Re: [PATCH v3 1/2] mm, slab: add an optimistic __slab_try_return_freelist()
From: Harry Yoo
Date: Thu May 28 2026 - 04:21:08 EST
On 5/22/26 11:23 PM, 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. So
we just put the slab back to the pc.slabs list. It's no longer likely
that the list will be empty now, so remove the unlikely() annotation.
However, also change that code to add to the tail of the partial list
instead of head to match what __slab_free() did and avoid a regression,
that was reported for the earlier version by the kernel test robot [1].
This change will also affect slabs which were grabbed from the partial
list and not refilled from even partially, but those should be much more
rare than a partial refill.
[1]https://lore.kernel.org/all/202605112204.9382cecf-lkp@xxxxxxxxx/
Reviewed-by: Hao Li<hao.li@xxxxxxxxx>
Signed-off-by: Vlastimil Babka (SUSE)<vbabka@xxxxxxxxxx>
---
Reviewed-by: Harry Yoo (Oracle) <harry@xxxxxxxxxx>
--
Cheers,
Harry / Hyeonggon