Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4505090rwb; Tue, 8 Aug 2023 09:23:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5ugMQDo6UyaEZKWKiDU+Z+iyEian5AoZHXwlvqw37zQXHiR3xM6/YiAIoStdisx4xbOK1 X-Received: by 2002:a17:902:b589:b0:1b9:be2e:2b40 with SMTP id a9-20020a170902b58900b001b9be2e2b40mr154908pls.50.1691511801059; Tue, 08 Aug 2023 09:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691511801; cv=none; d=google.com; s=arc-20160816; b=cwTdnbqNB8VZMkdKq6B0lhmkQsCmou5wUivpbxml3XORP88wyfm5GuDju2L8v8to8a ysEsAy+DfTPleFAorWyC7sjmhOZ/5ihohTHnAAwL+08KcpmEPFne81S2+OJTzNCVTlJc KeBoaWj6VqhN87pGpBDBEMXrXUK6jpYK92dfEurUN4+BRQ/i1Ak3kLtKbs5Cl1l+M9Ph 5KGAPi4tm8vHSF9BDDZIT8j8AWqcvqdCVqmldESGeDS2fpXw3kYv37rV2EIfH4nUfdRX 9PO0L+lLrVmq+G2JemgEWER6/E5t6vbGEkjOSap2xEWeYAw9ccb8r8DhiCHl5oKUh2Fc ixWQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o11-20020a1709026b0b00b001bbb8324bd5si5595028plk.479.2023.08.08.09.23.07; Tue, 08 Aug 2023 09:23:21 -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 S230200AbjHHCLK (ORCPT + 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 ); 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 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Yu Zhao Reviewed-by: Ryan Roberts --- 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