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/kwrCpocYyiwIIEuXIWpieU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LgI+CuWIaaNm3ZY5s1N6LIJF8lHAda8Mg764LdxiU6pBieoG2SO/uzuzUKDHzaB6HgTiFiJ7r6WaSvtQAkozNKzQUMpSqZklMlOi5Zu+jS0o2g6shG1I5GLCOc5KN+Qa5IKTLDqpmYb57dHZgKV9jarBMNhIqi/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;