From patchwork Fri Jul 28 16:13:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13332107 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 58DC8C0015E for ; Fri, 28 Jul 2023 16:17:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC96C8D0002; Fri, 28 Jul 2023 12:17:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E96FC8D0001; Fri, 28 Jul 2023 12:17:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5F828D0002; Fri, 28 Jul 2023 12:17:00 -0400 (EDT) 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 C87BC8D0001 for ; Fri, 28 Jul 2023 12:17:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 89ECC1CA30A for ; Fri, 28 Jul 2023 16:17:00 +0000 (UTC) X-FDA: 81061524600.03.E654B69 Received: from mgamail.intel.com (unknown [134.134.136.31]) by imf27.hostedemail.com (Postfix) with ESMTP id 102C140011 for ; Fri, 28 Jul 2023 16:16:57 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GZMJYeXH; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690561018; a=rsa-sha256; cv=none; b=ZH1rEfGbd3FMWG7TB3mUTXND+QOq0D3V16+/JWsv+ErNE7mULSO6tFUjqe2rZP7ZEgFrOL A6ZK6QMOY5Co4C7C0EFyZKPB03wnqbmu09JGHBfgZuJHxpVN0l2PAoPRmPfZG6DxZVHe5f DxwKifbpY1asyMU2o1QcrBXA34qxmXo= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GZMJYeXH; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690561018; 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=GTpvf3n3+opX17rj6U4yeGiU6XtoBl1c1lw64WwWEM0=; b=PjHqbac8/9OtkLxxYm1Fog1klPz/gGLSRpzf96Jqic8hp/sfD4sLi/LCFYFjd7n9YSZjx7 EXAgVQCxDb6WJKr/KlysipJcuLFHc1imKpUpIathByVrJ0UuUilapi/If6OXEVqrOKhYxx jzWiE6ZDWv4G2HYWC/sNYBHTrfioqZM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690561018; x=1722097018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yoKWUZ9b4nmnub08HwQjvgeLWWLSNJ2JgO+gF3lpB1A=; b=GZMJYeXHQwgFi5nG2KFB+gusehE14PrZsFIopMvbdnsLRhAIDk1m58m8 kZT5AqurwkzzRJsNohY43Roz4ino3B8pmhzEuF6SGe1trr8h2Fh7P9jq7 vljHkhNYOoAbC8AGXFGNR8S04+rvRo5X/kgYXaY2VC7weduiFlcDXN9d4 5uINekgqGZ0wkGt4N+dNd57mnuZmVtY3PicumyUftRCtZqoaDYQxsNzn3 Apl8WpNDfxTbofBn6YTeLDU5r30Q11C2Xwbo+pOVQ1bknId+tNOflb5ua zZnc5J7e/lhHw/KUZtQMbyKmKPjtOa9h9aunUAKXQXl4WkuITpj81vGYx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="432442960" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="432442960" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 09:15:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="851267434" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="851267434" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga004.jf.intel.com with ESMTP; 28 Jul 2023 09:15:35 -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 1/2] madvise: don't use mapcount() against large folio for sharing check Date: Sat, 29 Jul 2023 00:13:55 +0800 Message-Id: <20230728161356.1784568-2-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230728161356.1784568-1-fengwei.yin@intel.com> References: <20230728161356.1784568-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 102C140011 X-Stat-Signature: dm8y1ygqrkume4qheriqy6x8nqwuhud1 X-HE-Tag: 1690561017-54020 X-HE-Meta: U2FsdGVkX1+cvddflSLrcVpSqNUWp8WonSN8Qdy0Nyy7udXGoO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zwWNYD3n5l0CCGPVc2Ql+6gs6jtOzwwDbhDl2Ma8CZLdA7+NyIpGSJT26L1MBidS6VIOLwt9Vf1MW4eD+dzgSSrm64rRrBaCXdtMQYUjbDAmrxU+oqKBcYgBSMdEapjzcHuQ4vqjkzU2SseKF4= 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 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. But 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. But it should be OK for madvise case here. Fixes: 07e8c82b5eff ("madvise: convert madvise_cold_or_pageout_pte_range() to use folios") Signed-off-by: Yin Fengwei Reviewed-by: Yu Zhao --- mm/madvise.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 886f06066622..148b46beb039 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)) @@ -457,7 +457,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; From patchwork Fri Jul 28 16:13:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13332106 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 A1F7BC0015E for ; Fri, 28 Jul 2023 16:15:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39B2E8D0003; Fri, 28 Jul 2023 12:15:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34B808D0001; Fri, 28 Jul 2023 12:15:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23B918D0003; Fri, 28 Jul 2023 12:15:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 155A88D0001 for ; Fri, 28 Jul 2023 12:15:59 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D5C851CA2C5 for ; Fri, 28 Jul 2023 16:15:58 +0000 (UTC) X-FDA: 81061521996.30.2FA879C Received: from mgamail.intel.com (unknown [192.55.52.88]) by imf07.hostedemail.com (Postfix) with ESMTP id BBD4240005 for ; Fri, 28 Jul 2023 16:15:55 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=S2ObP0vg; spf=pass (imf07.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.88 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=1690560957; 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=xUoEr5I95lUh9hjBzY7s8yEoirfYNyR/ZKYQRhAtaJQ=; b=gZIeG3NIHNzuggfee6Ba2mvIZ3KF8F2HHUVU9Ki90+TNvmBO37cZ/jG339o3GOaxN61RU7 T1YaMS7Oso4d3Um3wiEKGy22wnC++HOdVeeGWPYOJLV4yn5bLIPWmQ1zT4M6mUqvUKAPLo vuCGzA5R2owYENflZ809j9zqktg2MC0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690560957; a=rsa-sha256; cv=none; b=Lj3/MOZZ4rPC5vKhCZy46oGrQUXv9O4ANp2vF+wvN93mTANaRxAmS3Ip/1GS5lLIXm+iRH XWq8gl2NkSwk0WzGOfx8h9Arto95w1EYQwMJ4m+Yeboxx2C7dRvbtTz0lBRKf4OfptyfrH 0a+Oe0EhFidHJNpb3o4eisovjFtPCYU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=S2ObP0vg; spf=pass (imf07.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690560956; x=1722096956; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BrOxNMR67qVjTh31EvN6swY79AWjbm/yuEvrka6JwLk=; b=S2ObP0vg34W+5I/9vMkTA5KYEy+R/FWJr+ik8Ny/5ww58kKJKJQbgbKM 90xTjmC1CT6fCQaVkrvAI0kvFt+ZrzNmkUy5hetVqVh5wb7iAn4CJtWTc 097w74qRW2wRMObz0YY0thTCEz9XOTTvOYMBneEHyvFggnX58vmPmOYgi ICM6xG4cRp7N2j2EWVX6Qw8oF+LFiLOE5VnY6IsE6Me4vQSXzf1qY3vNt eWh2p80jezbxKDOuHHLibPEmmDSQx1Gt+ymezAWKc5tw7wnFDSgigroH6 Vjc5HTMGPsQmdDeKEcEEU74rR1VLh1Yy2KLTz76rw4RbJHxNEHfn+kiYs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="399566018" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="399566018" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 09:15:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="974142248" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="974142248" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga006.fm.intel.com with ESMTP; 28 Jul 2023 09:15:51 -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 2/2] madvise: don't use mapcount() against large folio for sharing check Date: Sat, 29 Jul 2023 00:13:56 +0800 Message-Id: <20230728161356.1784568-3-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230728161356.1784568-1-fengwei.yin@intel.com> References: <20230728161356.1784568-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BBD4240005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: r1t8ubac6867cpz9rzt9xdkorgswz9nr X-HE-Tag: 1690560955-965463 X-HE-Meta: U2FsdGVkX18oOO/kwrCpocYyiwIIEuXIWpieUjvcm1IOpjj9PYTm+AsrrUzABkC0xcCWKOprtzHwvimumyCAszmfv8a52EtWS5llvPvkW2ikgLWyxNLfPVtDjlDLowjd6EcOppQZKOm0yqv5MbXf/h+qAqHhyjRHoiEyHeTolwqN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a5IKTLDqpmYb57dHZgKV9jarBMNhIqi/FEo= 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 commits 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") fc986a38b670 ("mm: huge_memory: convert madvise_free_huge_pmd to use a folio") replaced the page_mapcount() with folio_mapcount() to check whether the folio is shared by other mapping. But 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. But it should be OK for madvise case here. Fixes: 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") Fixes: fc986a38b670 ("mm: huge_memory: convert madvise_free_huge_pmd to use a folio") Signed-off-by: Yin Fengwei Reviewed-by: Yu Zhao --- mm/huge_memory.c | 2 +- mm/madvise.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index eb3678360b97..68c890875257 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1613,7 +1613,7 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, * If other processes are mapping this folio, we couldn't discard * the folio unless they all do MADV_FREE so let's skip the folio. */ - if (folio_mapcount(folio) != 1) + if (folio_estimated_sharers(folio) != 1) goto out; if (!folio_trylock(folio)) diff --git a/mm/madvise.c b/mm/madvise.c index 148b46beb039..55bdf641abfa 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -678,7 +678,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, if (folio_test_large(folio)) { int err; - if (folio_mapcount(folio) != 1) + if (folio_estimated_sharers(folio) != 1) break; if (!folio_trylock(folio)) break;