Re: [PATCH v2 13/13] mm/slab: stop allocating objcg pointers when unnecessary

Hao Li <[email protected]> Fri, 24 Jul 2026 17:57:15 +0800
Newsgroups org.kernel.vger.cgroups,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <amM2ybmTYfjlvDV7@fedora>
On Mon, Jul 20, 2026 at 04:16:27PM +0200, Vlastimil Babka (SUSE) wrote:
> Start using the slab_needs_objcg() helper to calculate slabobj_ext size.
> Caches that we know to never need objcg pointers (currently
> KMALLOC_NORMAL caches) will thus stop wasting memory on them when memory
> allocation profiling is enabled.
> 
> For things to work properly, we need to also add slab_needs_objcg()
> checks to mem_cgroup_from_obj_slab() and memcg_slab_free_hook(), because
> when obj_exts array exists for a slab only due to mem_alloc profiling,
> we would otherwise attempt to access a non-existing objcg pointer in
> that slab.
> 
> The function __memcg_slab_post_alloc_hook() should not be possible to
> call for a slab where slab_needs_objcg() is false, but add a DEBUG_VM
> check there to prevent breaking this assumption accidentally.
> 
> Signed-off-by: Vlastimil Babka (SUSE) <[email protected]>

Looks good to me.
Reviewed-by: Hao Li <[email protected]>

-- 
Thanks,
Hao