[v2,2/3] madvise:madvise_free_huge_pmd(): don't use mapcount() against large folio for sharing check
Message ID | 20230808020917.2230692-3-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 w14csp2205585vqr; Tue, 8 Aug 2023 08:37:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFScB+DbZFip2JNdyW1kXdz8Y5C+EL61vRbEV96W3xCKuwuhDz9dSTnRAtZT8pn2EMZ7AM6 X-Received: by 2002:a17:903:228d:b0:1b2:fa8:d9c9 with SMTP id b13-20020a170903228d00b001b20fa8d9c9mr36288plh.49.1691509077638; Tue, 08 Aug 2023 08:37:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691509077; cv=none; d=google.com; s=arc-20160816; b=iMHmK8KDQuWiRERGu1mRclIyT5RfvrlsFdb4hyAxVPu1aKPviNHHZNh9FnPoeLCEeu 34NcZipXTPz2gm9g0ebRT5PN1wXFhvQPwwfkAElbtSOQyigNjfJtXrdxx+LTA8TFI39Z ijTwEFhYa0SvyWsqhTnZcvDhJVS1PvLjVn5T4MzFthg+32rVQGApLid+WELZpe7Xff1o MoAu8TxeYSCy8XbjN3Z59b2/Dnjzb23GpCYrDJz9EBnd0E40EBwNREVz7BoPBZUFwDx7 fHBvi8io+Lj9WJoF7MR1ASwYpY19ycSoLcM4WhkaILxYB1QbbSVDq9UsVpH0Vc00DIjE XiUg== 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=o6jkD1q2jWi2X8kGNkhNdNjBTl2DhE6CD0Wi6fdQEcw=; fh=LgrQy7mqd4cTuAw7dlguzqzf4K4OZS27s5hhhI8E0EA=; b=WqJHM+sa/NabJ/buA47au2xTRUeO7gEo7cGhN8Z2k3wGOF5PI75yc1GiFdI9rh8a/N 4k1x0oUo+WVYeWIuWltZb8DVm5fjqPr2A8Pk+OCY90qKwR2RKUyp92E3F6kOwuDyAatF iNG/NVPM4B4nAMWI7qX+8bArrbAADcmZZuX9zdheSnVv/JLUxUCey5U9hzDvl2asrMxy ODtNcxYN3VJNcfbjXW8eihjb4+NEPBlgwPonfyvpN6o7BymgYsPKDm3zLviSV+JsCieL rvYinCbffhYvQw4rJz1Pz966iyZyHrtwO8RgpChee35jY6iWT8DfirYipmpeXtHBA63e nuzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mIQNCeW2; 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 q6-20020a17090311c600b001bbad1883d5si7617087plh.293.2023.08.08.08.37.44; Tue, 08 Aug 2023 08:37:57 -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=mIQNCeW2; 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 S230238AbjHHCLK (ORCPT <rfc822;aaronkmseo@gmail.com> + 99 others); Mon, 7 Aug 2023 22:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbjHHCLI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Aug 2023 22:11:08 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E5CD170B; Mon, 7 Aug 2023 19:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691460668; x=1722996668; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F3oORw0alZIlqdHjL/85Fxei/Bpe8d1CgQMNfWf9J+M=; b=mIQNCeW2k5AHYKQUqOV4Wy4/T4s1ba03EWASwQQQIXl8J/DAcH0v76tD ZhVWN40u77qMXYG6cJMpZRf1TMz7+SsY+QcXTNI8632jjM7xMz7SHpb39 vXgQ9Ba3jKt0/xEnHoyFBxIwrA7XNONSVZA2uQnBXFUG3k+C9+HG1GG7J Jwwqx6tTAZfZ/xw1mtyKLScDN/3mS7VGXZL7O0lhd8I9PImB/H0xqG7A7 rcsvqB32Z1uSkEYW8mkGvRn7xJikVHRw3hk4v6JLeMh4W1b3A4LZ1p/r2 bpjfIsA/QO0hufw23pU/UwuRqQadG5bOsFOLSqdFkhPRYIrTkW7tOi+gF Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="374371058" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="374371058" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2023 19:11:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="681051006" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="681051006" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga003.jf.intel.com with ESMTP; 07 Aug 2023 19:11:03 -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 2/3] madvise:madvise_free_huge_pmd(): don't use mapcount() against large folio for sharing check Date: Tue, 8 Aug 2023 10:09:16 +0800 Message-Id: <20230808020917.2230692-3-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, 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: 1773675822643928039 X-GMAIL-MSGID: 1773675822643928039 |
Series |
don't use mapcount() to check large folio sharing
|
|
Commit Message
Yin Fengwei
Aug. 8, 2023, 2:09 a.m. UTC
Commit 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. 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: fc986a38b670 ("mm: huge_memory: convert madvise_free_huge_pmd 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/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mon, Aug 7, 2023 at 8:11 PM Yin Fengwei <fengwei.yin@intel.com> wrote: > > Commit 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. > > 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: fc986a38b670 ("mm: huge_memory: convert madvise_free_huge_pmd to use a folio") > Cc: stable@vger.kernel.org Andrew, this one isn't really a bug fix but an optimization, so please feel free to drop the Fixes and Cc tags above. (It seems to me it doesn't hurt for stable to take it though.) Thank you. > 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/huge_memory.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 154c210892a1..0b709d2c46c6 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1612,7 +1612,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)) > -- > 2.39.2 >
diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 154c210892a1..0b709d2c46c6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1612,7 +1612,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))