From patchwork Tue Aug 8 02:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13345580 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 449D8EB64DD for ; Tue, 8 Aug 2023 02:10:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C73706B0074; Mon, 7 Aug 2023 22:10:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BFBFE6B0075; Mon, 7 Aug 2023 22:10:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9D148D0001; Mon, 7 Aug 2023 22:10:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 962FD6B0074 for ; Mon, 7 Aug 2023 22:10:56 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6AF3C140691 for ; Tue, 8 Aug 2023 02:10:56 +0000 (UTC) X-FDA: 81099309312.26.C9FEE98 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by imf02.hostedemail.com (Postfix) with ESMTP id 63D858000D for ; Tue, 8 Aug 2023 02:10:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=j7D3fIfL; spf=pass (imf02.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691460654; a=rsa-sha256; cv=none; b=AOcZdRzV9Iwp97UPCA7tNuN9+xGuwR6HoX1axUvCMHGh2Zc+1THioJO33Av1DdkVxiFWZH GaSKo5sX3VSCha2PEjb668m9Q7ariT36SukG8G0BgKaaHGIi7lHNBHTY7YhWOTtJt+temk DNjpFcXmEokrrSCGtKaRWrApfF2cW4A= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=j7D3fIfL; spf=pass (imf02.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691460654; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ljmm8K/QkDciIB4DKIAS5aVl8fxci5EsuS9jbdr0jIg=; b=m8W6+W6uqryxd1pDsTdQgWnPnoxX5qjiEMJR+llyL6P9hgDBk5Mc97nrUyRfbaHMExuSsb QI/ClchmWNruw31FuqUch5jEY2x2r6DBcIpKprENSNCPGRjC5noQdeFah9fh4bmCp4jUgK 4rgTwg5nABVXvozcMaaSFuDta8Yr9XM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691460654; x=1722996654; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I0sX9zQ55/pnapaBgwBXw+8hFPy7SpHzYq+j/u0jVVw=; b=j7D3fIfLJOitaaySFBMRWnEzOC2jFt197MFAMWhT8ofPEvQmwN71wzr+ HyWL92ZR0jpWx0ZbtrS9KHA0dWSXGAZva+BrStpDU7BRlWmQPgYUIfrHc 2NNtDACFoUsm1gUsZAZpmd7OIFobk9RNG01L/eHfvuoe0u6O6pfRs5mOl Ved95wsoXkB0Woum02O9OD1R1Kzb+iPcf4rufpt/ZJF0LQ1+PTgBmr8dL sIFbxUi9goIbW2/i+QYQLWW3SeCoX2DHlkGa4wceEFimn9sEHw9jp0q00 R7GE6SK1UjHAgtARqomhoKLeqinT80uZdaRWjZLctp4urqly7egymujr1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="373453503" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="373453503" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2023 19:10:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="977689341" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="977689341" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga006.fm.intel.com with ESMTP; 07 Aug 2023 19:10:49 -0700 From: Yin Fengwei To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, akpm@linux-foundation.org, willy@infradead.org, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, minchan@kernel.org, yuzhao@google.com, david@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com Cc: fengwei.yin@intel.com Subject: [PATCH v2 1/3] madvise:madvise_cold_or_pageout_pte_range(): don't use mapcount() against large folio for sharing check Date: Tue, 8 Aug 2023 10:09:15 +0800 Message-Id: <20230808020917.2230692-2-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808020917.2230692-1-fengwei.yin@intel.com> References: <20230808020917.2230692-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 63D858000D X-Stat-Signature: hnog7aaxaz8np3kuxf8wxkckzco8ahha X-Rspam-User: X-HE-Tag: 1691460654-430024 X-HE-Meta: U2FsdGVkX18RTvDrd1pVhf4Z/cA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zDsAtwJ/rKGBLZJ2BFMd3el7YjpqjtWfggwhS/hOz/ugTVvlbQA5fzpJ1VNL1cHmW6SalCfHLAVlsqMeRyRuO1Xfp5u1zGSiYjjc/hjt0wDyjz4JD0H72Dw9PF+BXw4k+dG0MnxTdznKAKHbB+1Mx70sp1B68fMSHrUe3E/C7GHg0mOIgJ5+1Ff781/VKSfSJhYpDRylOZhCf4evj2gMIYjQ9OaUjVJ9FnRKoh2BbUzQDrPfcdidrBReRGmTCUINOJUeQlnkn+l1MfdyBp2m2UZfZRI2nwxUnYaObRW2bKgBfGTIYVT7v 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: Commit 07e8c82b5eff ("madvise: convert madvise_cold_or_pageout_pte_range() to use folios") replaced the page_mapcount() with folio_mapcount() to check whether the folio is shared by other mapping. It's not correct for large folio. folio_mapcount() returns the total mapcount of large folio which is not suitable to detect whether the folio is shared. Use folio_estimated_sharers() which returns a estimated number of shares. That means it's not 100% correct. It should be OK for madvise case here. User-visible effects is that the THP is skipped when user call madvise. But the correct behavior is THP should be split and processed then. NOTE: this change is a temporary fix to reduce the user-visible effects before the long term fix from David is ready. Fixes: 07e8c82b5eff ("madvise: convert madvise_cold_or_pageout_pte_range() to use folios") Cc: stable@vger.kernel.org Signed-off-by: Yin Fengwei Reviewed-by: Yu Zhao Reviewed-by: Ryan Roberts --- mm/madvise.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 1d7933933e31..49af35e2d99a 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -383,7 +383,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, folio = pfn_folio(pmd_pfn(orig_pmd)); /* Do not interfere with other mappings of this folio */ - if (folio_mapcount(folio) != 1) + if (folio_estimated_sharers(folio) != 1) goto huge_unlock; if (pageout_anon_only_filter && !folio_test_anon(folio)) @@ -459,7 +459,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (folio_test_large(folio)) { int err; - if (folio_mapcount(folio) != 1) + if (folio_estimated_sharers(folio) != 1) break; if (pageout_anon_only_filter && !folio_test_anon(folio)) break;