Re: [PATCH v3 05/21] slab: add sheaves to most caches

Vlastimil Babka
2026-01-21T08:12:37Z

On 1/20/26 19:47, Breno Leitao wrote:
> Hello Vlastimil,
>
> On Fri, Jan 16, 2026 at 03:40:25PM +0100, Vlastimil Babka wrote:
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -7863,6 +7863,48 @@ static void set_cpu_partial(struct kmem_cache *s)
>> #endif
>> }
>>
>> +static unsigned int calculate_sheaf_capacity(struct kmem_cache *s,
>> + struct kmem_cache_args *args)
>> +
>> +{
>> + unsigned int capacity;
>> + size_t size;
>> +
>> +
>> + if (IS_ENABLED(CONFIG_SLUB_TINY) || s->flags & SLAB_DEBUG_FLAGS)
>> + return 0;
>> +
>> + /* bootstrap caches can't have sheaves for now */
>> + if (s->flags & SLAB_NO_OBJ_EXT)
>> + return 0;
>
> I've been testing this on my arm64 environment with some debug patches,
> and the machine became unbootable.
>
> I am wondering if you should avoid SLAB_NOLEAKTRACE as well. I got the
> impression it is hitting this infinite loop:
>
> -> slab allocation
> -> kmemleak_alloc()
> -> kmem_cache_alloc(object_cache)
> -> alloc_from_pcs() / __pcs_replace_empty_main()
> -> alloc_full_sheaf() -> kzalloc()
> -> kmemleak_alloc()
> -> ... (infinite recursion)
>

Oops.

> What about something as:
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 26804859821a..0a6481aaa744 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -7445,8 +7445,13 @@ static unsigned int calculate_sheaf_capacity(struct kmem_cache *s,
> if (IS_ENABLED(CONFIG_SLUB_TINY) || s->flags & SLAB_DEBUG_FLAGS)
> return 0;
>
> - /* bootstrap caches can't have sheaves for now */
> - if (s->flags & SLAB_NO_OBJ_EXT)
> + /*
> + * bootstrap caches can't have sheaves for now (SLAB_NO_OBJ_EXT).
> + * SLAB_NOLEAKTRACE caches (e.g., kmemleak's object_cache) must not
> + * have sheaves to avoid recursion when sheaf allocation triggers
> + * kmemleak tracking.
> + */
> + if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
> return 0;

Yeah that should work, will do. Thanks a lot!