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

Harry Yoo <[email protected]> Tue, 4 Aug 2026 09:45:23 +0000
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm,gmane.linux.kernel.cgroups
Message-ID <anGzWSrjIWZ2jZmf@dev>
On Mon, Jul 27, 2026 at 02:54:06PM +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.

Perhaps this part is not necessary as slab_obj_ext_set_objcg() now has
a debug warning?

> 
> Reviewed-by: Hao Li <[email protected]>
> Signed-off-by: Vlastimil Babka (SUSE) <[email protected]>
> ---

Otherwise LGTM so please feel free to add:
Reviewed-by: Harry Yoo <[email protected]>

-- 
Cheers,
Harry / Hyeonggon