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 C1EC22DAFBA for ; Tue, 25 Nov 2025 08:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764060949; cv=none; b=sEvaEKhfJNFUBtCyXCR8y0cKlLa6ATxFGA4xFCDPhvyVCa1+PTuBhb5yrjZ0yKDY0BAkGFDLejWLA59uuKaK7RemUwUzpd7gokNB0FloTHervuF0Hgh2Ykb+SmieQcN/xRB+wtcAYLFEk+zXDEUheYH9x/BwLfmWuV+6fFbAqkE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764060949; c=relaxed/simple; bh=Mwl10SHsprDsG24tXHNm9Hq0qPyZ3bvWdNtKi5Ctd6g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ahsyg27pG8BJO0Q1qBsJ4jQ+F2j9hD4RijZbFTFKCOvRYCt9zI5WpV1ZvoaDeBmxp7Z3LKWhgafJducPHN3FfUo7uwyIAwx/BK8vApXj12Mx4YRu2ZrIovpclHyu+vHQT0qy8qYSWTAd3lT1+pv9P0PfctpTdpaXYg696RYSp/E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oK3tj+fx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oK3tj+fx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0C5AC4CEF1; Tue, 25 Nov 2025 08:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764060949; bh=Mwl10SHsprDsG24tXHNm9Hq0qPyZ3bvWdNtKi5Ctd6g=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=oK3tj+fxjuLk8QMh1pYn5HXUAGHzlk5JEnmkZ/em4volvbiWyhwmlhysPibjDXtIo fE1EGevXYpHqp4hqUckvIilznbi0MkUKnwqGgXI9rN20fgMgiuoDo5CIhKd8McVyJp m5gaBrbqeQ6GHHcD8NpZhQsFkcBNZtN6YwJTZZ93kKUbrCnvN4DdLztq0Q5Fs3xH8w W3LPlhMF9hvdNUtxcO+ckaXe6FQR2p9uGln4d1yKyb5ZY+OMaEmoRNIcHzy2+g4c0h OByjfXHvzobO8ihAY5pbRDE37ETUypDseCtH3uCa1ESQC9CbI4e1td+CHzZwdsI1AD u7Oecrb12ejzA== Message-ID: <5421c8d0-1151-48dc-8774-fd2e983735a5@kernel.org> Date: Tue, 25 Nov 2025 09:55:40 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/4] mm/huge_memory: replace can_split_folio() with direct refcount calculation To: Balbir Singh , Zi Yan , Lorenzo Stoakes Cc: Andrew Morton , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Miaohe Lin , Naoya Horiguchi , Wei Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20251122025529.1562592-1-ziy@nvidia.com> <20251122025529.1562592-3-ziy@nvidia.com> <51675d77-9453-43cc-bfda-f21a2edfeace@nvidia.com> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: <51675d77-9453-43cc-bfda-f21a2edfeace@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/24/25 23:14, Balbir Singh wrote: > On 11/22/25 13:55, Zi Yan wrote: >> can_split_folio() is just a refcount comparison, making sure only the >> split caller holds an extra pin. Open code it with >> folio_expected_ref_count() != folio_ref_count() - 1. For the extra_pins >> used by folio_ref_freeze(), add folio_cache_references() to calculate it. >> >> Suggested-by: David Hildenbrand (Red Hat) >> Signed-off-by: Zi Yan >> --- >> include/linux/huge_mm.h | 1 - >> mm/huge_memory.c | 43 ++++++++++++++++------------------------- >> mm/vmscan.c | 3 ++- >> 3 files changed, 19 insertions(+), 28 deletions(-) >> >> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >> index 97686fb46e30..1ecaeccf39c9 100644 >> --- a/include/linux/huge_mm.h >> +++ b/include/linux/huge_mm.h >> @@ -369,7 +369,6 @@ enum split_type { >> SPLIT_TYPE_NON_UNIFORM, >> }; >> >> -bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins); >> int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list, >> unsigned int new_order); >> int folio_split_unmapped(struct folio *folio, unsigned int new_order); >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index c1f1055165dd..6c821c1c0ac3 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -3455,23 +3455,6 @@ static void lru_add_split_folio(struct folio *folio, struct folio *new_folio, >> } >> } >> >> -/* Racy check whether the huge page can be split */ >> -bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) >> -{ >> - int extra_pins; >> - >> - /* Additional pins from page cache */ >> - if (folio_test_anon(folio)) >> - extra_pins = folio_test_swapcache(folio) ? >> - folio_nr_pages(folio) : 0; >> - else >> - extra_pins = folio_nr_pages(folio); >> - if (pextra_pins) >> - *pextra_pins = extra_pins; >> - return folio_mapcount(folio) == folio_ref_count(folio) - extra_pins - >> - caller_pins; >> -} >> - >> static bool page_range_has_hwpoisoned(struct page *page, long nr_pages) >> { >> for (; nr_pages; page++, nr_pages--) >> @@ -3776,17 +3759,26 @@ int folio_check_splittable(struct folio *folio, unsigned int new_order, >> return 0; >> } >> >> +/* Number of folio references from the pagecache or the swapcache. */ >> +static unsigned int folio_cache_references(const struct folio *folio) > > folio_cache_ref_count? Yes, makes sense. > >> +{ >> + if (folio_test_anon(folio) && !folio_test_swapcache(folio)) >> + return 0; >> + return folio_nr_pages(folio); >> +} >> +> > Does this belong to include/linux/mm.h with the other helpers? Not for now I think, in particular, as we require earlier !folio->mapping checks to give a correct answer. Most people should be using folio_expected_ref_count(). -- Cheers David