Re: [PATCH v2 09/16] mm/slab: pass alloc_flags through slab_post_alloc_hook() chain

From: Vlastimil Babka (SUSE)

Date: Mon Jun 15 2026 - 07:33:18 EST


On 6/15/26 06:35, Suren Baghdasaryan wrote:
> On Wed, Jun 10, 2026 at 8:41 AM Vlastimil Babka (SUSE)
> <vbabka@xxxxxxxxxx> wrote:
>> @@ -4568,9 +4577,8 @@ struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags)
>> }
>>
>> static __fastpath_inline
>> -bool slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru,
>> - gfp_t flags, size_t size, void **p,
>> - unsigned int orig_size)
>> +bool slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags, size_t size,
>> + void **p, struct slab_alloc_context *ac)
>
> Would if be possible to make this last parameter a ""const struct
> slab_alloc_context*" (here and in other functions accepting it)? I
> think these functions accept it as an input parameter only and are not
> supposed to change it, right? Makes it easy to veriy that
> slab_alloc_context is not changed between consequitive calls reusing
> it, for example inside slab_alloc_node().

Uh, ok, did that. Also changed orig_size to size_t.

>> {
>> bool init = slab_want_init_on_alloc(flags, s);
>> unsigned int zero_size = s->object_size;
>> @@ -4590,7 +4598,7 @@ bool slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru,
>> * orig_size if we track it.
>> */
>> if (slub_debug_orig_size(s))
>> - zero_size = orig_size;
>> + zero_size = ac->orig_size;
>>
>> /*
>> * When slab_debug is enabled, avoid memory initialization integrated
>> @@ -4616,14 +4624,14 @@ bool slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru,
>> !kasan_has_integrated_init())
>> && !is_kfence_address(p[i]))
>> memset(p[i], 0, zero_size);
>> - if (gfpflags_allow_spinning(flags))
>> + if (alloc_flags_allow_spinning(ac->alloc_flags))
>> kmemleak_alloc_recursive(p[i], s->object_size, 1,
>> s->flags, init_flags);
>> kmsan_slab_alloc(s, p[i], init_flags);
>> - alloc_tagging_slab_alloc_hook(s, p[i], flags);
>> + alloc_tagging_slab_alloc_hook(s, p[i], flags, ac->alloc_flags);
>> }
>>
>> - return memcg_slab_post_alloc_hook(s, lru, flags, size, p);
>> + return memcg_slab_post_alloc_hook(s, flags, size, p, ac);
>> }
>>
>> /*
>> @@ -4918,6 +4926,12 @@ static __fastpath_inline void *slab_alloc_node(struct kmem_cache *s, struct list
>> {
>> const unsigned int alloc_flags = SLAB_ALLOC_DEFAULT;
>> void *object;
>> + struct slab_alloc_context ac = {
>> + .caller_addr = addr,
>> + .orig_size = orig_size,
>> + .alloc_flags = alloc_flags,
>> + .lru = lru,
>> + };
>>
>> s = slab_pre_alloc_hook(s, gfpflags);
>> if (unlikely(!s))
>> @@ -4929,14 +4943,8 @@ static __fastpath_inline void *slab_alloc_node(struct kmem_cache *s, struct list
>>
>> object = alloc_from_pcs(s, gfpflags, alloc_flags, node);
>>
>> - if (unlikely(!object)) {
>> - struct slab_alloc_context ac = {
>> - .caller_addr = addr,
>> - .orig_size = orig_size,
>> - .alloc_flags = alloc_flags,
>> - };
>> + if (!object)
>
> Any reason "unlikely" is removed?

No, fixed, thanks!

>> object = __slab_alloc_node(s, gfpflags, node, &ac);
>> - }
>>
>> maybe_wipe_obj_freeptr(s, object);
>>