Re: [PATCH v3 12/13] mm/slab: stop allocating objcg pointers when unnecessary
From: Vlastimil Babka (SUSE)
Date: Tue Aug 04 2026 - 06:47:33 EST
On 8/4/26 11:45, Harry Yoo wrote:
> 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?
Indeed. Removed. Also moved the those debug warnings from 11/13 to here to
avoid bisectability issues, as you pointed out offlist.
>>
>> Reviewed-by: Hao Li <hao.li@xxxxxxxxx>
>> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
>> ---
>
> Otherwise LGTM so please feel free to add:
> Reviewed-by: Harry Yoo <harry@xxxxxxxxxx>
Thanks!