[v2,3/3] madvise:madvise_free_pte_range(): don't use mapcount() against large folio for sharing check
Message ID | 20230808020917.2230692-4-fengwei.yin@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2243172vqr; Tue, 8 Aug 2023 09:37:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGE3r38Fgc0rfYmRVg4DdUQgn4JjslF3Tm01Q+TopD6f1GcbyTJnK890HiV/U6LBO8tdRX9 X-Received: by 2002:a05:6a00:1799:b0:66f:578c:59fb with SMTP id s25-20020a056a00179900b0066f578c59fbmr23817pfg.10.1691512620157; Tue, 08 Aug 2023 09:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691512620; cv=none; d=google.com; s=arc-20160816; b=WAgZ76X1jBR3ZEseq2DtYmTIKuetbECFl8POyEFKvszfwiEKckhxVqlWyZmi8G4qGd fIxIFVGoHaheVrD4bCdxm4xuFOXFRFe9w5wZBbpRb/yJdDo+zmimDNWTD7z/4V8hbkZB CHuz6yKUvVexvCmXPsnIuW2ybVLdDAtMC8ZBysd2oGzR7RZVRCeWdTlFe5wfMCiq/4XT VEKrCLhEcZ9Ld13QxcsXUqMFuo+guGE0f47Eipc+nzVARX+sha733OzpRTCgbN5EFLzA EkAyLhyRxU3GHbahJxUw6jGJqirVAvSEJZB/7m9vEoD6EJlJq96T7YUTHTBtm/alhT1K U3Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SnBkVWTLCU6LpGHkVu+arSBfRN4pTVOEAmzdbz8UspQ=; fh=LgrQy7mqd4cTuAw7dlguzqzf4K4OZS27s5hhhI8E0EA=; b=UXcAdsN/hb+UIkRw8QUQiCRBs9PYIlB822Rp1GV4agRKBrr4QuJKaeHEK0ppstw1A4 l2lcsT2gPPY8sddLVD7ytgZqjam5/0O7nivE/u4bdQKq5hy3/zrgzBnazDc5X70KDA4I zsMtM8jyF1Tp5SaS9jGAQL8v6MLCy91q3ScPidarJAhpl87ENy3qV6wI2Dg86YKZHlFJ R1t9y8DnjznsRSUKLxYt6zg033OA4/nDAtLj4pMdypNNqQHH5CIKU0hIYEBXZ/Rjsn66 U6+F08yiBkNjpuu7e6RJYUts++4YJtqr02EIzSasMX10PSoeDdAA+QSqk3A3gYmFNCQU b+yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EuJd4qa0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dc13-20020a056a0035cd00b006871fa2ee53si7587347pfb.65.2023.08.08.09.36.46; Tue, 08 Aug 2023 09:37:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EuJd4qa0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230304AbjHHCLb (ORCPT <rfc822;aaronkmseo@gmail.com> + 99 others); Mon, 7 Aug 2023 22:11:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbjHHCL3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Aug 2023 22:11:29 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6ED19B6; Mon, 7 Aug 2023 19:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691460682; x=1722996682; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d3VIX2xY+fu1wWsahOfoN14pobtO1cM2MgEWqpBvgLY=; b=EuJd4qa0AAArhVMsFAlVuljUHzrNuN+NCuFOvd/FratfgL2JETvU6eCh qg6KhSCb58AqZmPXhmlnGTLUklrJP7iYSWSXQYEQRj7TcTSSk+e0wJc+m JURZuL/L5ni+vhYi93jQ0OaAWfp8hWPV15Xe0MPextHEwx2/gBdsKQHPx 12/mcxBQm0bm7Olx+egeufVxqoqMDaxF/ysXGR2cqJc/UB5n5PAPL8Hvp iQzc2W1QdyXnuBwG/qtj/XSzk3PlTQcOZVp0R3aZ0IrVRgu1tzPhbFvzG dsZRTrN9URLfshzRnuKIzObcL+fm3PdBJpkYAg1HUJIQWN7+NgtF1ONx1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="373453596" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="373453596" 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:11:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="977689411" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="977689411" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga006.fm.intel.com with ESMTP; 07 Aug 2023 19:11:18 -0700 From: Yin Fengwei <fengwei.yin@intel.com> 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 3/3] madvise:madvise_free_pte_range(): don't use mapcount() against large folio for sharing check Date: Tue, 8 Aug 2023 10:09:17 +0800 Message-Id: <20230808020917.2230692-4-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773679537357399034 X-GMAIL-MSGID: 1773679537357399034 |
Series |
don't use mapcount() to check large folio sharing
|
|
Commit Message
Yin Fengwei
Aug. 8, 2023, 2:09 a.m. UTC
Commit 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") replaced the page_mapcount() with folio_mapcount() to check whether the folio is shared by other mapping. It's not correct for large folios. 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: 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") Cc: stable@vger.kernel.org Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Reviewed-by: Yu Zhao <yuzhao@google.com> Reviewed-by: Ryan Roberts <ryan.roberts@arm.com> --- mm/madvise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 8/15/23 21:25, Daniel Gomez wrote: > Hi Yin, > On Tue, Aug 08, 2023 at 10:09:17AM +0800, Yin Fengwei wrote: >> Commit 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a >> folio") replaced the page_mapcount() with folio_mapcount() to check >> whether the folio is shared by other mapping. >> >> It's not correct for large folios. 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. > > I'm trying to understand why it should be ok for madvise this change, so > I hope it's okay to ask you few questions. > > folio_mapcount() calculates the total maps for all the subpages of a > folio. However, the folio_estimated_sharers does it only for the first > subpage making it not true for large folios. Then, wouldn't this change > drop support for large folios? I saw David explained this very well in another mail. > > Seems like folio_entire_mapcount() is not accurate either because of it > does not inclue PTE-mapped sub-pages which I think we need here. Hence, > the folio_mapcount(). Could this be something missing in the test side? > > I tried to replicate the setup with CONFIG_TRANSPARENT_HUGEPAGE but > seems like I'm not able to do it: > > ./cow > # [INFO] detected THP size: 2048 KiB > # [INFO] detected hugetlb size: 2048 KiB > # [INFO] detected hugetlb size: 1048576 KiB > # [INFO] huge zeropage is enabled > TAP version 13 > 1..166 > # [INFO] Anonymous memory tests in private mappings > # [RUN] Basic COW after fork() ... with base page > not ok 1 MADV_NOHUGEPAGE failed > # [RUN] Basic COW after fork() ... with swapped out base page > not ok 2 MADV_NOHUGEPAGE failed > # [RUN] Basic COW after fork() ... with THP > not ok 3 MADV_HUGEPAGE failed > # [RUN] Basic COW after fork() ... with swapped-out THP > not ok 4 MADV_HUGEPAGE failed > # [RUN] Basic COW after fork() ... with PTE-mapped THP > not ok 5 MADV_HUGEPAGE failed > # [RUN] Basic COW after fork() ... with swapped-out, PTE-mapped THP > not ok 6 MADV_HUGEPAGE failed > ... Can you post the MADV_PAGEOUT and PTE-mapped THP related testing result? And I suppose swap need be enabled also for the testing. Regards Yin, Fengwei > > > Daniel >> >> 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: 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") >> Cc: stable@vger.kernel.org >> Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> >> Reviewed-by: Yu Zhao <yuzhao@google.com> >> Reviewed-by: Ryan Roberts <ryan.roberts@arm.com> >> --- >> mm/madvise.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/mm/madvise.c b/mm/madvise.c >> index 49af35e2d99a..4dded5d27e7e 100644 >> --- a/mm/madvise.c >> +++ b/mm/madvise.c >> @@ -683,7 +683,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; >> -- >> 2.39.2 >>
diff --git a/mm/madvise.c b/mm/madvise.c index 49af35e2d99a..4dded5d27e7e 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -683,7 +683,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;