mm/slab: reduce slabobj_ext memory with allocation profiling disabled

When memory allocation profiling is compiled in but permanently disabled
on boot with (implicit or explicit) "never" parameter, stop allocating
(thus wasting) memory for the codetag_ref parts of slabobj_ext metadata.

Do this by using the new slab_obj_ext_has_codetag() helper in
cache_obj_ext_size().

Additionally add a slab_obj_ext_has_codetag() check in
handle_failed_objexts_alloc(). The function might get called with memory
allocation profiling disabled, when the obj_ext array is allocated for
objcg pointers only. Setting codetag refs as empty is unnecessary in
that case, and with them not allocated anymore would now result in
memory corruption.

Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Link: https://patch.msgid.link/20260727-b4-objext_split-v3-10-c29ef0f1f257@kernel.org
Reviewed-by: Hao Li <hao.li@linux.dev>
Reviewed-by: Harry Yoo <harry@kernel.org>
Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
This commit is contained in:
Vlastimil Babka (SUSE) 2026-07-27 14:54:04 +02:00
parent 580258a192
commit c4ec6cb557
2 changed files with 7 additions and 1 deletions

View File

@ -591,7 +591,7 @@ static inline size_t cache_obj_ext_size(struct kmem_cache *s)
if (IS_ENABLED(CONFIG_MEMCG))
sz += 1;
if (IS_ENABLED(CONFIG_MEM_ALLOC_PROFILING))
if (slab_obj_ext_has_codetag())
sz += 1;
return sizeof(struct slabobj_ext) * sz;

View File

@ -2064,6 +2064,9 @@ static inline void mark_obj_codetag_empty(const void *obj)
struct slab *obj_slab;
unsigned long slab_exts;
if (!slab_obj_ext_has_codetag())
return;
if (is_kfence_address(obj))
return;
@ -2099,6 +2102,9 @@ static inline void handle_failed_objexts_alloc(struct slab *slab,
{
unsigned int stride;
if (!slab_obj_ext_has_codetag())
return;
/*
* If vector previously failed to allocate then we have live
* objects with no tag reference. Mark all references in this