Re: [PATCH] mm/slab: extract __free_to_pcs_batch() from free_to_pcs_bulk()
From: Vlastimil Babka (SUSE)
Date: Wed Jul 08 2026 - 12:48:13 EST
On 7/7/26 17:34, hu.shengming@xxxxxxxxxx wrote:
> Vlastimil wrote:
>> It has been noted that free_to_pcs_bulk() is difficult to follow, with a
>> number of goto labels, and this has contributed to two memory leak bugs
>> in there.
>>
>> Extract part of the code to __free_to_pcs_batch(), which focuses only on
>> freeing free-hook-processed local objects to a percpu sheaf, and
>> returning how many were freed. Zero means a trylock failure or no empty
>> sheaf available, and thus the caller should fallback to
>> __kmem_cache_free_bulk().
>>
>> Make free_to_pcs_bulk() call this in a while loop, removing all goto
>> labels from the function. __free_to_pcs_batch() retains two rather
>> straightforward ones.
>
> Hi Vlastimil,
>
> This looks like a very nice refactoring to me. Splitting out the actual
> per-CPU sheaf batching into __free_to_pcs_batch() makes the control flow
> in free_to_pcs_bulk() much easier to follow, and also keeps the fallback
> handling clearer.
>
> Please feel free to add:
> Reviewed-by: Shengming Hu <hu.shengming@xxxxxxxxxx>
Thanks!
Added to slab/for-next