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: 13052898 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A9E3C433FE for ; Wed, 23 Nov 2022 00:58:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4CF16B0072; Tue, 22 Nov 2022 19:58:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AFB6E6B0073; Tue, 22 Nov 2022 19:58:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C2908E0001; Tue, 22 Nov 2022 19:58:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8A3566B0072 for ; Tue, 22 Nov 2022 19:58:22 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 630C91A0AC5 for ; Wed, 23 Nov 2022 00:58:22 +0000 (UTC) X-FDA: 80162896044.20.0913A69 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 0C5DE1C000E for ; Wed, 23 Nov 2022 00:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669165101; 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=X/6/ol5WSEByC8Q1TXAoSfUApk128ux6Bg5e6MhtKMIraHBEn3xjloJTwmtVisSYedlovC /jamPBOWcDb5FP1kqzDkrgvlGMqO9oI3eo0pfU8eY5Q5RlwmNCQSZjGqaayI4YZtvO5VzE G3G6Mb+xIm1slZ+6vGKw2VSFZiMcElA= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669165102; a=rsa-sha256; cv=none; b=znepcyM4d66kch2B88PQyeJwhbgVr0AvbHj0+mzLoq7ANivfV2IRxT6g+CnYpK8QoyLKuN uT6Q8R9jvPq/0COYIHeyqdlzwJR4UDDRjqmOakNVzkbH7eRb4ISy8kd1cd9XRdzfh88LA/ 4ayG0b62IiGKHEEVAi8IzAQ/M7LJ+80= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="X/6/ol5W"; spf=pass (imf21.hostedemail.com: domain of gshan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669165102; h=from:from:sender: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:in-reply-to: references:dkim-signature; bh=FRXQzInu4Oq+Sfj0rM7dyXyjMHp78R6zBNAHLpf5AvU=; b=xdxjyZR1Ocz0g48i6ZFvsewi83O1SsKPaZFZ/jOC8udPaMxxUi70DEuEo0m9CRF7DId0ls Hx2PlRtaSO/2X9hQHxZI7FBUXbwYvm6oE3IuhdXOnlcmGvEslRY0dYyWbi6MH+wSbldkge LLy9rlP+CdRYr9/Zl7ztLwz5adWWgyI= X-Rspam-User: X-Rspamd-Queue-Id: 0C5DE1C000E Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="X/6/ol5W"; spf=pass (imf21.hostedemail.com: domain of gshan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: uicgnynceqheqqr1z7idy7ikaoeihuit X-Rspamd-Server: rspam10 X-HE-Tag: 1669165101-367703 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; /*