Re: [PATCH RFC 11/13] mm/huge_memory: clean up after-split folio freeing in __folio_split

"Zi Yan" <[email protected]>
Newsgroups org.kvack.linux-mm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Fri Aug 7, 2026 at 5:17 PM EDT, Kairui Song via B4 Relay wrote:
> From: Kairui Song <[email protected]>
>
> Replace free_folio_and_swap_cache() with an explicit folio_free_swap()
> and folio_put() in the after-split loop.  free_folio_and_swap_cache()
> unlocks the folio, then free_swap_cache() must trylock it again and
> re-check folio_mapped() before freeing the swap cache entries; if the
> trylock loses a race, the entries are left behind even though the folio
> reference is dropped.  The sub folios are still locked and unmapped
> here, so just directly call folio_free_swap() directly under the lock,
> unlock and drop the reference.  This makes the swap cache freeing
> deterministic and the reference drop explicit.
>
> Signed-off-by: Kairui Song <[email protected]>
> ---
>  mm/huge_memory.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index b80d0db63225..39c91c8e5bc8 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -4304,14 +4304,16 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
>  		if (new_folio == page_folio(lock_at))
>  			continue;
>  
> -		folio_unlock(new_folio);
>  		/*
>  		 * Subpages whose mapping has been zapped may be freed
>  		 * earlier, but freeing them requires taking the
>  		 * lru_lock, so we defer put_page() on tail pages until
>  		 * after the split completes.

this comment needs some love.

>  		 */
> -		free_folio_and_swap_cache(new_folio);
> +		if (is_swapcache)
> +			folio_free_swap(new_folio);
> +		folio_unlock(new_folio);
> +		folio_put(new_folio);
>  	}
>  
>  out:

folio_split_unmaped()'s comment still refers to
free_folio_and_swap_cache().

Otherwise, LGTM.

Reviewed-by: Zi Yan <[email protected]>



-- 
Best Regards,
Yan, Zi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.