Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3733619rwb; Mon, 7 Aug 2023 20:02:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHv64Zuo1N+/IBOoYBkQJswolfWTyr+OeJN7asrp1aiZpVf/1s/qwfNpfBHuOQ2WPWwRzK5 X-Received: by 2002:a05:620a:40c5:b0:76c:c450:b987 with SMTP id g5-20020a05620a40c500b0076cc450b987mr12858933qko.62.1691463723492; Mon, 07 Aug 2023 20:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691463723; cv=none; d=google.com; s=arc-20160816; b=XJ3gyzERaiJsCewadrt/nm7w4jyxVgmY1CqrL9Tn3a9X7TrtDTaRZcmJqS319Gt+VU ZzIu2xHQAsRWohTvuOTJnC7hPSScRH6Kve2+4q+wiCpj1UPU9byHQY3IczsZ6N6Fk71e bxZMnXjjC/IxWn0pibcfIp+cm6H84ri0oSG50f09+dsO16XuNOkryIW7xyKRL8solVFq pl1fR1s0KG0x8O1gD7+gkFPn0IhM5d+/8xSU+DPWLp1+nrsucSonwLTUCgwlUs2UR9vS xzl3iOqQhQtV6vWO2Fy1vVIEHXkjRmHENDbxNrs9XucgudYsrIMZNpaJjERyfk06/NjX DV4Q== 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=Ljmm8K/QkDciIB4DKIAS5aVl8fxci5EsuS9jbdr0jIg=; fh=LgrQy7mqd4cTuAw7dlguzqzf4K4OZS27s5hhhI8E0EA=; b=wGxK+qR2S0x7GeCu82WAFmZ8TSy3VVcA83MpAFcSqVAR6bEYHvmj2Dj3LnWfN3Wxzj dJ4sISGrbsFwKq8Uh2pHf3ELwDZ+OgYUjjjKbByGTo+0/E0CZivZgHSvbDDMteWqkJkw bCqa/E0GkWAbpXDoHZAfm7UxWP/iHryNMorS0PNtoAXQCfCcYsyipjn+hed3nvYGg8N0 wi0KwOMB1RiPXIVHrIA17BiES1hUscMVtMvk6bOS8MueL8R/fUEAeq4EtvzWHAYMjour DBIdHPYARGGbvFGXjnoThSLMUynOaA95fZgh1tqmzJZD4vQcQQaJxforAIgZzc0MNYOH QB5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=joHMlYxP; 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 y19-20020a63e253000000b0055793097dbesi6529503pgj.469.2023.08.07.20.01.51; Mon, 07 Aug 2023 20:02:03 -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=joHMlYxP; 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 S230214AbjHHCK7 (ORCPT + 99 others); Mon, 7 Aug 2023 22:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbjHHCK6 (ORCPT ); Mon, 7 Aug 2023 22:10:58 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25A81711; Mon, 7 Aug 2023 19:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691460653; x=1722996653; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I0sX9zQ55/pnapaBgwBXw+8hFPy7SpHzYq+j/u0jVVw=; b=joHMlYxPWu5ShZUS3ILS82ZCwlpnmi4lVi9vegrtgdysZxfHyxdrnQ/D BgazzmrzTSeruioIdqjDbJ2m+SurGkS8iPoZpMBmyTePexgZhwskY8B11 Bxlp/KKRbOgkunLaSF338P+TrHTdOD7+AZZ24CkASRQF7dx/gxMbMbQaW lh/TR72cOLj2VtPBe6gKCDuhvLP+CUuDM9qfZQewLtP9+Dqu6XPwdZEFm waVmeP0UbDZ7ekGPUU4LU4CqPQuMvAhd6afKPDBwDH/gUgCPHoiu4Cq1i IzZCjUIH3facI05fgHwNFaPgUMSbD7KQ16NKzkoVtir5m45n8/rgufyY/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="373453505" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="373453505" 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:10:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="977689341" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="977689341" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga006.fm.intel.com with ESMTP; 07 Aug 2023 19:10:49 -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 1/3] madvise:madvise_cold_or_pageout_pte_range(): don't use mapcount() against large folio for sharing check Date: Tue, 8 Aug 2023 10:09:15 +0800 Message-Id: <20230808020917.2230692-2-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 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. 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. 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: 07e8c82b5eff ("madvise: convert madvise_cold_or_pageout_pte_range() to use folios") Cc: stable@vger.kernel.org Signed-off-by: Yin Fengwei Reviewed-by: Yu Zhao Reviewed-by: Ryan Roberts --- mm/madvise.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 1d7933933e31..49af35e2d99a 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; -- 2.39.2