Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4445956rwb; Tue, 8 Aug 2023 08:37:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiwmHlp0PcsC4ygETCT+epqgKBw4A1748Sm0F3LrPJ6CNX1wPD5ZXPztzNaCT6Sp6wUlW+ X-Received: by 2002:a17:902:b597:b0:1b8:b3f9:58e5 with SMTP id a23-20020a170902b59700b001b8b3f958e5mr32661pls.38.1691509053478; Tue, 08 Aug 2023 08:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691509053; cv=none; d=google.com; s=arc-20160816; b=cueOh6Qs0WdvfOPw3ekrCXKni9uMmby23Msa7wO/P4fukKvMZDD0cWUOvPehAbZn5X tpcISaaArS2FGi++AYWyostW51jTsEFMODRZ5q/l+G79MEZsoIiyHwKzLoRkV6+OniVw ZgQMQ0dFxnseYZwm6HEpNzrNe5zWTy5cEdYOCzpdyyu1B/6Q4zDA7nf5ubRyc8wfjhx6 UqFIhtWaaNb59L51mkQawOkkfzOcccZABZ29tp9CBJWotqb1xBZQx7X+X7mVrAAPW0Rr E8Mqcp6QxmGL3vqPuEh96E5fue26WSVzieHeox5ry6E3hc02R/f0nW4wVJ1uDLo3QP9j RHbg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b69-20020a633448000000b00564be9cb7b3si6651551pga.268.2023.08.08.08.37.03; Tue, 08 Aug 2023 08:37:33 -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 S230264AbjHHCLa (ORCPT + 99 others); Mon, 7 Aug 2023 22:11:30 -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 ); 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 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Yu Zhao Reviewed-by: Ryan Roberts --- 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