From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: Harry Yoo <harry@kernel.org>, Hao Li <hao.li@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Alexander Potapenko <glider@google.com>,
Marco Elver <elver@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org
Subject: Re: [PATCH RFC 12/12] mm/slab: stop allocating objcg pointers when unnecessary
Date: Thu, 16 Jul 2026 17:08:00 +0200 [thread overview]
Message-ID: <e126d6b1-bed7-46bb-a8a3-cc555707b516@kernel.org> (raw)
In-Reply-To: <CAJuCfpHuXu3BDf93zeBQWSW_k5wApegp44rHoZwk5Ym6xxbqEA@mail.gmail.com>
On 7/16/26 06:46, Suren Baghdasaryan wrote:
> Maybe now we should rename static_obj_ext_size() to
> static_obj_ext_max_size() as it reflects the max possible size of
> slabobj_ext?
Hm with _max_size() it doesn't have to be called static_ anymore?
But maybe we can get rid of it completely.
The only caller is calculate_sizes():
#if defined(CONFIG_SLAB_OBJ_EXT) && defined(CONFIG_64BIT)
if (slab_args_unmergeable(args, s->flags) &&
(aligned_size - size >= static_obj_ext_size()))
s->flags |= SLAB_OBJ_EXT_IN_OBJ;
#endif
We don't have slab pointer to pass to static_obj_ext_max_size().
But we should be able to figure it out from the cache via
cache_needs_objcg().
So we'd need cache_obj_ext_size()?
The static max size here works, but may prevent SLAB_OBJ_EXT_IN_OBJ
needlessly if padding can only fit codetag_ref and not objcg, but
we don't need objcg.
Which is probably only theoretical at this point as kmalloc_normal
caches (that have no objcg) have no padding, at least without
slab_debug. But still.
>> + size_t sz = 0;
>> +
>> + if (slab_needs_objcg(slab))
>> + sz += 1;
>> +
>> + if (slab_obj_ext_has_codetag())
>> + sz += 1;
>> +
>> + return sizeof(struct slabobj_ext) * sz;
>> }
>>
>> #ifdef CONFIG_SLAB_OBJ_EXT
>> @@ -741,7 +749,7 @@ static inline struct obj_cgroup **slab_obj_ext_objcgp(struct slabobj_ext *obj_ex
>> static inline union codetag_ref *
>> slab_obj_ext_codetag_ref(struct slab *slab, struct slabobj_ext *obj_ext)
>> {
>> - if (IS_ENABLED(CONFIG_MEMCG))
>> + if (slab_needs_objcg(slab))
>> obj_ext += 1;
>>
>> return &obj_ext->_ctref;
>> diff --git a/mm/slub.c b/mm/slub.c
>> index 771d73abacb6..09c4931e5435 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -2503,6 +2503,9 @@ void memcg_slab_free_hook(struct kmem_cache *s, struct slab *slab, void **p,
>> if (likely(!obj_exts))
>> return;
>>
>> + if (!slab_needs_objcg(slab))
>> + return;
>> +
>> get_slab_obj_exts(obj_exts);
>> __memcg_slab_free_hook(s, slab, p, objects, obj_exts);
>> put_slab_obj_exts(obj_exts);
>>
>> --
>> 2.55.0
>>
next prev parent reply other threads:[~2026-07-16 15:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260715-b4-objext_split-v1-0-9a49c4ccf4c3@kernel.org>
2026-07-15 15:32 ` [PATCH RFC 00/12] mm/slab, alloc_tag: reduce obj_ext memory waste Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-1-9a49c4ccf4c3@kernel.org>
2026-07-15 16:02 ` [PATCH RFC 01/12] mm/slab: skip kfence objects in allocation profiling Suren Baghdasaryan
[not found] ` <ab9782bf-d3dd-4cb5-ae66-127b3a16330b@kernel.org>
2026-07-16 15:24 ` Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-2-9a49c4ccf4c3@kernel.org>
2026-07-15 16:13 ` [PATCH RFC 02/12] mm/slab: remove objs_per_slab() Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-3-9a49c4ccf4c3@kernel.org>
2026-07-16 0:56 ` [PATCH RFC 03/12] mm: move struct slabobj_ext to mm/slab.h Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-4-9a49c4ccf4c3@kernel.org>
2026-07-16 1:02 ` [PATCH RFC 04/12] mm/slab: make slab_obj_ext() determine object index Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-5-9a49c4ccf4c3@kernel.org>
2026-07-16 1:27 ` [PATCH RFC 05/12] mm/slab: abstract slabobj_ext.objcg access Suren Baghdasaryan
2026-07-16 13:58 ` Vlastimil Babka (SUSE)
2026-07-16 15:27 ` Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-6-9a49c4ccf4c3@kernel.org>
2026-07-16 1:28 ` [PATCH RFC 06/12] mm/slab: abstract slabobj_ext.ref access Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-7-9a49c4ccf4c3@kernel.org>
2026-07-16 1:44 ` [PATCH RFC 07/12] mm/slab: replace slab.stride with obj_exts_in_object Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-8-9a49c4ccf4c3@kernel.org>
[not found] ` <CAJuCfpGq3Yv8Dq=2mPgR5LGC=40VSNTA6mg4BjTRE0ADXMZkbg@mail.gmail.com>
2026-07-16 14:43 ` [PATCH RFC 08/12] mm/slab: change struct slabobj_ext to a union Vlastimil Babka (SUSE)
2026-07-16 15:28 ` Suren Baghdasaryan
[not found] ` <20260715-b4-objext_split-v1-9-9a49c4ccf4c3@kernel.org>
[not found] ` <CAJuCfpGkpe=5O_vW9VKqKFxrBO+QquCD+mXth_qeUSqcWcW6hA@mail.gmail.com>
2026-07-16 14:47 ` [PATCH RFC 09/12] mm/slab: introduce slab_obj_ext_has_codetag() Vlastimil Babka (SUSE)
[not found] ` <20260715-b4-objext_split-v1-12-9a49c4ccf4c3@kernel.org>
[not found] ` <CAJuCfpHuXu3BDf93zeBQWSW_k5wApegp44rHoZwk5Ym6xxbqEA@mail.gmail.com>
2026-07-16 15:08 ` Vlastimil Babka (SUSE) [this message]
2026-07-16 15:32 ` [PATCH RFC 12/12] mm/slab: stop allocating objcg pointers when unnecessary Suren Baghdasaryan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e126d6b1-bed7-46bb-a8a3-cc555707b516@kernel.org \
--to=vbabka@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=cl@gentwo.org \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox