From nobody Thu Apr 16 00:47:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA40AC4332F for ; Wed, 23 Nov 2022 00:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235359AbiKWA72 (ORCPT ); Tue, 22 Nov 2022 19:59:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235150AbiKWA7O (ORCPT ); Tue, 22 Nov 2022 19:59:14 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46C80AFE65 for ; Tue, 22 Nov 2022 16:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669165099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FRXQzInu4Oq+Sfj0rM7dyXyjMHp78R6zBNAHLpf5AvU=; b=jUpgEAT4QRjW17MR7Z4fdTjnekXLW/CnSYdAYEk6ZMw7QpDPl2kxVLhGPiCxUedCnSEnmP zDrPseFUHgOmk5gIkR8YPJOII5W2cXoOVRRNdhb8qHmhd7/jD2HqHP2UKkdmbGam86pWOE 0mdxw2x1sz0hs0JuB5uWYM+UpZ/MncQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-184-XCEd7GhINXuqIGb4MCnXLQ-1; Tue, 22 Nov 2022 19:58:15 -0500 X-MC-Unique: XCEd7GhINXuqIGb4MCnXLQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6256C811E67; Wed, 23 Nov 2022 00:58:15 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-62.bne.redhat.com [10.64.54.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02F044A9254; Wed, 23 Nov 2022 00:58:11 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, william.kucharski@oracle.com, ziy@nvidia.com, kirill.shutemov@linux.intel.com, david@redhat.com, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH] mm: migrate: Fix THP's mapcount on isolation Date: Wed, 23 Nov 2022 08:57:52 +0800 Message-Id: <20221123005752.161003-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The issue is reported when removing memory through virtio_mem device. The transparent huge page, experienced copy-on-write fault, is wrongly regarded as pinned. The transparent huge page is escaped from being isolated in isolate_migratepages_block(). The transparent huge page can't be migrated and the corresponding memory block can't be put into offline state. Fix it by replacing page_mapcount() with total_mapcount(). With this, the transparent huge page can be isolated and migrated, and the memory block can be put into offline state. Fixes: 3917c80280c9 ("thp: change CoW semantics for anon-THP") Cc: stable@vger.kernel.org # v5.8+ Reported-by: Zhenyu Zhang Suggested-by: David Hildenbrand Signed-off-by: Gavin Shan --- mm/compaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index c51f7f545afe..c408b5e04c1d 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -990,7 +990,7 @@ isolate_migratepages_block(struct compact_control *cc, = unsigned long low_pfn, * admittedly racy check. */ mapping =3D page_mapping(page); - if (!mapping && page_count(page) > page_mapcount(page)) + if (!mapping && page_count(page) > total_mapcount(page)) goto isolate_fail; =20 /* --=20 2.23.0