From patchwork Fri Jul 21 09:40:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13321707 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 52BA7C001DE for ; Fri, 21 Jul 2023 09:41:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0A772801AB; Fri, 21 Jul 2023 05:41:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB8AB2801A0; Fri, 21 Jul 2023 05:41:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0AE32801AB; Fri, 21 Jul 2023 05:41:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9EB5D2801A0 for ; Fri, 21 Jul 2023 05:41:38 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6F0A012015B for ; Fri, 21 Jul 2023 09:41:38 +0000 (UTC) X-FDA: 81035126676.20.CE84B4F Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf05.hostedemail.com (Postfix) with ESMTP id 5310F100014 for ; Fri, 21 Jul 2023 09:41:35 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=kdwB5dTN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.88 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=1689932496; 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=e2sNh8vTkR820lnb3yYf7b8aM21w60Mfy7WKVZcrew4=; b=4R8P7UJCAoEu5ZmwuDBZJBduhTWTdYgZPM1o27emQlCEd+/d0df7FnY5KAFvRwWBfEo/se RuQlGgreVx7LINU2vn8aOVH18ULp8Mv08vUWEqRrmRxgrOF7z0DP7r66CtT74XuRyizDWI XasxDq9MB7vH4lutsPF6PkS9M52HiNA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=kdwB5dTN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689932496; a=rsa-sha256; cv=none; b=K/Pv1qUKLNSuaJ5bSbUgHeg2Zx7USS3EvcxSiChUMeVr9GUbu3b7FxPOWf+lHaa1a5z7I5 bpWckpDxmGina0n8zsPmM5Bl7hUxB7wU7tEj4NCFMzYREy5KMcdFQDIl7jHak0PL1YCDCV YuQK6xkfeDtnrEpswlbL8ReuIjok9SA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689932496; x=1721468496; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AU+Bax7o8AGRnodMI5F/Lc+z+q2VSKWl4dvqmzGnJLE=; b=kdwB5dTNHWaWbMK3AuaWmHZ5CG2phibK/ZDDd2vS0FkDkkwAvK70Q8Ci reaPIdAQsXTNuV0mXqxx/2QEK6N66w7K9ml5X521DmbZJU+CEDTwdbQvN nWk1A5byJsVxdkpmm7b40XDPTsgpeA1Fr9pNJ0zU1Ha1g54wtiUOooOrv eg0BOmfFcYRom/cFfLUvkzPvK96REA5bHetwoo0MlHKNy4i0zjkswZTza xwcwtb65irsE6GeJrJgNEVS3elmnIg7d89WSTx9jOHx2bz1S43ooxi9D1 AURjv3t8MIAPG0toQimJH/w5VwX3QH4F1GrxtGNpmoDeEM/i5G78UgPFw w==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="397874317" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="397874317" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 02:40:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="898661109" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="898661109" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga005.jf.intel.com with ESMTP; 21 Jul 2023 02:40:46 -0700 From: Yin Fengwei To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, minchan@kernel.org, yuzhao@google.com, willy@infradead.org, david@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com Cc: fengwei.yin@intel.com Subject: [RFC PATCH v2 1/4] madvise: not use mapcount() against large folio for sharing check Date: Fri, 21 Jul 2023 17:40:40 +0800 Message-Id: <20230721094043.2506691-2-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230721094043.2506691-1-fengwei.yin@intel.com> References: <20230721094043.2506691-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5310F100014 X-Stat-Signature: kbh4h7f4jzmmsw64omwfwpcckoqhcbno X-HE-Tag: 1689932495-451696 X-HE-Meta: U2FsdGVkX19LlUIypKzALV3194CxeXvx77CLTQ4vUs1Nb6DMdAMGzsZjyF/vlyMblrFzozRQVzkyKgKybIUF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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. Signed-off-by: Yin Fengwei Reviewed-by: Yu Zhao --- mm/madvise.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 38382a5d1e39..f12933ebcc24 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; @@ -682,7 +682,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;