Re: [PATCH 1/5] slab: make __slab_free() more clear

From: Vlastimil Babka

Date: Thu Nov 06 2025 - 03:43:26 EST


On 11/6/25 09:26, Harry Yoo wrote:
> On Wed, Nov 05, 2025 at 10:05:29AM +0100, Vlastimil Babka wrote:
>> The function is tricky and many of its tests are hard to understand. Try
>> to improve that by using more descriptively named variables and added
>> comments.
>>
>> - rename 'prior' to 'old_head' to match the head and tail parameters
>> - introduce a 'bool was_full' to make it more obvious what we are
>> testing instead of the !prior and prior tests
>
> Yeah I recall these were cryptic when I was analyzing slab few years
> ago :)
>
>> - add or improve comments in various places to explain what we're doing
>>
>> Also replace kmem_cache_has_cpu_partial() tests with
>> IS_ENABLED(CONFIG_SLUB_CPU_PARTIAL) which are compile-time constants.
>>
>> We can do that because the kmem_cache_debug(s) case is handled upfront
>> via free_to_partial_list().
>
> This makes sense. By the way, should we also check IS_ENABLED(CONFIG_SLUB_TINY)
> in kmem_cache_has_cpu_partial()?

If you really mean testing CONFIG_SLUB_TINY then it's not necessary because
CONFIG_SLUB_CPU_PARTIAL depends on !TINY.
If you mean using IS_ENABLED(CONFIG_SLUB_CPU_PARTIAL) instead of the #ifdef,
that could be possible, just out of scope here. And hopefully will be gone
fully, so no point in polishing at this point. Unlike __slab_free() which stays.

>> Signed-off-by: Vlastimil Babka <vbabka@xxxxxxx>
>> ---
>
> The code is much cleaner!
>
> Reviewed-by: Harry Yoo <harry.yoo@xxxxxxxxxx>
>