Re: [PATCH RFC v2] mm, slab: add an optimistic __slab_try_return_freelist()

From: Vlastimil Babka (SUSE)

Date: Thu May 14 2026 - 08:55:02 EST


On 5/12/26 07:49, Harry Yoo (Oracle) wrote:
> On Mon, Apr 27, 2026 at 11:42:57AM +0200, Vlastimil Babka (SUSE) wrote:
>> When we end up returning extraneous objects during refill to a slab
>> where we just did a get_freelist_nofreeze(), it is likely no other CPU
>> has freed objects to it meanwhile. We can then reattach the remainder of
>> the freelist without having to walk the (potentially cache cold)
>> freelist for finding its tail to connect slab->freelist to it.
>>
>> Add a __slab_try_return_freelist() function that does that. As suggested
>> by Hao Li, it doesn't need to also return the slab to the partial list,
>> because there's code in __refill_objects_node() that already does that
>> for any slabs where we don't detach the freelist in the first place.
>>
>> Reviewed-by: Hao Li <hao.li@xxxxxxxxx>
>> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
>> ---
>> Optimizes the current refill leftover handling in a way that should have
>> no downsides, so we have a better baseline for any further changes (e.g.
>> spilling or caching the leftover) that involve some tradeoffs.
>>
>> Git version here:
>>
>> https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/linux.git/log/?h=b4/refill-optimistic-return
>>
>> It's based on slab/for-7.2/perf with "mm/slub: defer freelist
>> construction until after bulk allocation from a new slab".
>> ---
>> Changes in v2:
>> - rebase to slab/for-7.2/perf, drop RFC
>> - simplify to reuse the existing reattaching to partial list (Hao Li)
>> - Add R-b from Hao Li, thanks!
>> - drop the stat items - they serverd to verify the optimistic path was
>> succeeding, but are too detailed for mainline
>> - Link to v1: https://patch.msgid.link/20260421-b4-refill-optimistic-return-v1-1-24f0bfc1acff@xxxxxxxxxx
>> ---
>
> Looks good to me,
> Reviewed-by: Harry Yoo (Oracle) <harry@xxxxxxxxxx>

Thanks!

> with a few typo fixes below.

Fixed up.