From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F28AD11C83 for ; Mon, 28 Aug 2023 10:22:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A30AC433C7; Mon, 28 Aug 2023 10:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1693218145; bh=gh+yk4tl3bR9pRZsxT6xl7Yi7/L+YQtX8D0jmo2AZmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ovSr4KrozleENP7FWpuAd7rHpoUMg7BkChiQjiRmhYrDnb0kI+g/+ZPaAglXTtZbV 4miClppuE6aEHnDh3ANPeDbrEb/oLVkDIGyzCn0wehOh4u6ongVkZyEp+snJp5IhKg /9zE64hOlJMgwdEFzoTS5yBWQAkAf6oi1o+uD4mg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yin Fengwei , Yu Zhao , Ryan Roberts , David Hildenbrand , Kefeng Wang , Matthew Wilcox , Minchan Kim , "Vishal Moola (Oracle)" , Yang Shi , Andrew Morton Subject: [PATCH 6.4 112/129] madvise:madvise_free_pte_range(): dont use mapcount() against large folio for sharing check Date: Mon, 28 Aug 2023 12:13:11 +0200 Message-ID: <20230828101201.090409576@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230828101157.383363777@linuxfoundation.org> References: <20230828101157.383363777@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yin Fengwei commit 0e0e9bd5f7b9d40fd03b70092367247d52da1db0 upstream. 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. Link: https://lkml.kernel.org/r/20230808020917.2230692-4-fengwei.yin@intel.com Fixes: 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") Signed-off-by: Yin Fengwei Reviewed-by: Yu Zhao Reviewed-by: Ryan Roberts Cc: David Hildenbrand Cc: Kefeng Wang Cc: Matthew Wilcox Cc: Minchan Kim Cc: Vishal Moola (Oracle) Cc: Yang Shi Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/madvise.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/madvise.c +++ b/mm/madvise.c @@ -666,8 +666,8 @@ static int madvise_free_pte_range(pmd_t * deactivate all pages. */ if (folio_test_large(folio)) { - if (folio_mapcount(folio) != 1) - goto out; + if (folio_estimated_sharers(folio) != 1) + break; folio_get(folio); if (!folio_trylock(folio)) { folio_put(folio);