Re: [PATCH v3 11/13] mm/slab: add cache_ and slab_needs_objcg() helpers
From: Harry Yoo
Date: Tue Aug 04 2026 - 04:50:28 EST
On Mon, Jul 27, 2026 at 02:54:05PM +0200, Vlastimil Babka (SUSE) wrote:
> Slabs of some caches never need the objcg part of struct slabobj_ext.
> Introduce helpers to query this for a cache or a slab.
>
> Introduce SLAB_MAY_ACCOUNT flag that is currently only internal and all
> caches have it set except:
>
> - KMALLOC_NORMAL caches, as long as KMALLOC_RECLAIM caches are separate
> - KMALLOC_NO_OBJ_EXT caches, if they exist
>
> For named caches we currently can't derive SLAB_MAY_ACCOUNT from
> SLAB_ACCOUNT because some caches might be created without SLAB_ACCOUNT
> and then used both with and without __GFP_ACCOUNT concurrently,
> allocating obj_ext arrays on demand. So just add the SLAB_MAY_ACCOUNT
> to all kmem caches, unless kmem accounting is disabled.
>
> This can be improved later by finding out all caches used with
> __GFP_ACCOUNT, creating them with the SLAB_MAY_ACCOUNT flag explicitly,
> and then ignoring __GFP_ACCOUNT for all other caches (possibly with a
> warning).
>
> To make the evaluation of slab_needs_objcg() faster in the allocation
> and free fast paths, add a obj_exts_needs_objcg flag into slab itself.
> This optimization is only available on 64bit architectures where free
> bits are available for the flag.
>
> Reviewed-by: Hao Li <hao.li@xxxxxxxxx>
> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
> ---
Reviewed-by: Harry Yoo <harry@xxxxxxxxxx>
--
Cheers,
Harry / Hyeonggon