From patchwork Wed Nov 23 00:57:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 24634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2523887wrr; Tue, 22 Nov 2022 17:04:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6RSZa9GRnF9cthnTDLCvUEMm+dc2X6Jgoq1sse6uteiihuUspi4IpCmMkWK+5mM+S1pahm X-Received: by 2002:a63:1054:0:b0:42b:9219:d14e with SMTP id 20-20020a631054000000b0042b9219d14emr6306070pgq.176.1669165446302; Tue, 22 Nov 2022 17:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669165446; cv=none; d=google.com; s=arc-20160816; b=waGucUyfHzS8kTjOr3dX8OAhg4EzRgJP9Um/i6pbmT1Mwd+WSHjfqJQcUZ6YIc7SAr 1GYmXTh59hYkjoFsMxk8OsL1GxOAUD/sfnBrKqGFqx2uZ0x31GmiRZAuw/aepLlKMxGo TmMg7seyb46AlWlFhUq8F7j88gAr3GFc7PoICqDfkYPreWFLWoyqDMPlDVwES0Y98Hr+ gvyF1TYMLDP1vNwmPkMXYaw8H8bIHLC6ft6L7/JStW2HBwQo0hJxOOzYTviuTcNsA12M QEx9E7aO8/J0WeRBM6cMlPz+zp0xBuy276OESIWj4eun9Wx4guSxFXtF8/r0hrzIqJtE dw5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=FRXQzInu4Oq+Sfj0rM7dyXyjMHp78R6zBNAHLpf5AvU=; b=UphAQ/pyd02NyrHMQKAcAshbtB1LGRDFVaZzt6lIW4JHqRcJv/fTZKF1MIoRaA2Hsf qnL2ITTP+MLW+NmE/o1u7jr53gjQHQi3yYfxaPgdOsImFZhc3D2GxKBYl4dNoDsHJQjc xxPp2gspxB/pcYKQpl2l71CF7ZTrTuBbA4h+4tZKcBNU+FE6PaDUcpKNgo3W/42pgyjf BRh3xiEMyBdp1xb+UbTPPup5xzGAzixuf+ZDk1p1Ub5NYCQXoCBdFST3TCDjer3N3lSt A6nRB/dm0zFobV5yRr68QtwqFzUcQNOS/3luXnKJkkAA0eXCtJ9FT3cF+VLPNa+MuoaY Bn7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jUpgEAT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a656944000000b004772cf9ae7esi1822072pgq.284.2022.11.22.17.03.53; Tue, 22 Nov 2022 17:04:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jUpgEAT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235357AbiKWA71 (ORCPT + 99 others); Tue, 22 Nov 2022 19:59:27 -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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750246827300294072?= X-GMAIL-MSGID: =?utf-8?q?1750246827300294072?= 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 = page_mapping(page); - if (!mapping && page_count(page) > page_mapcount(page)) + if (!mapping && page_count(page) > total_mapcount(page)) goto isolate_fail; /*