From: Hao Li <hao.li@linux.dev>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Harry Yoo <harry@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
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 v2 12/13] mm/slab: add cache_ and slab_needs_objcg() helpers
Date: Thu, 23 Jul 2026 18:01:07 +0800 [thread overview]
Message-ID: <amHldYIo_-Bgm7Ek@fedora> (raw)
In-Reply-To: <e8b503fe-c97f-4747-aa95-97be42cdd832@kernel.org>
On Thu, Jul 23, 2026 at 11:30:49AM +0200, Vlastimil Babka (SUSE) wrote:
> On 7/23/26 11:25, Hao Li wrote:
> > On Mon, Jul 20, 2026 at 04:16:26PM +0200, Vlastimil Babka (SUSE) wrote:
> >> @@ -359,6 +359,13 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
> >> goto out_unlock;
> >> }
> >>
> >> + /*
> >> + * For now we assume any cache can be used with __GFP_ACCOUNT and thus
> >> + * may need to store objcg pointers for objects
> >> + */
> >> + if (!mem_cgroup_kmem_disabled())
> >> + flags |= SLAB_MAY_ACCOUNT;
> >
> > if memcg itself is disabled via `cgroup_disable`, mem_cgroup_kmem_disabled()
> > still return false, so maybe we can use:
>
> Aha, but then shouldn't rather mem_cgroup_kmem_disabled() take that into
> account on its own?
Yeah, it's better to handle two cases in mem_cgroup_kmem_disabled!
This could also be a standalone patch, but including it to this patchset it totally
fine.
>
> > if (!mem_cgroup_disabled() && !mem_cgroup_kmem_disabled())
> > flags |= SLAB_MAY_ACCOUNT;
> >
> >> +
> >> /* Fail closed on bad usersize of useroffset values. */
> >> if (!IS_ENABLED(CONFIG_HARDENED_USERCOPY) ||
> >> WARN_ON(!args->usersize && args->useroffset) ||
> >> @@ -984,11 +991,19 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)
> >> #endif
> >>
> >> /*
> >> - * If CONFIG_MEMCG is enabled, disable cache merging for
> >> - * KMALLOC_NORMAL caches.
> >> + * If memcg_kmem is enabled and this is a KMALLOC_NORMAL cache and not
> >> + * aliased with any other type, make sure it's never merged with any other
> >> + * cache.
> >> + *
> >> + * In other cases the kmalloc cache may end up being used for a
> >> + * __GFP_ACCOUNT allocation so mark it as such
> >> */
> >> - if (IS_ENABLED(CONFIG_MEMCG) && (type == KMALLOC_NORMAL))
> >> - flags |= SLAB_NO_MERGE;
> >> + if (!mem_cgroup_kmem_disabled()) {
> >
> > the same as above
> >
> > Others look good to me.
> >
> > Reviewed-by: Hao Li <hao.li@linux.dev>
>
> Thanks!
>
> >
> >> + if (type == KMALLOC_NORMAL && KMALLOC_RECLAIM != KMALLOC_NORMAL)
> >> + flags |= SLAB_NO_MERGE;
> >> + else
> >> + flags |= SLAB_MAY_ACCOUNT;
> >> + }
> >>
> >> if (minalign > ARCH_KMALLOC_MINALIGN) {
> >> aligned_size = ALIGN(aligned_size, minalign);
> >> diff --git a/mm/slub.c b/mm/slub.c
> >> index d78d3e50c877..30435e2509ea 100644
> >> --- a/mm/slub.c
> >> +++ b/mm/slub.c
> >> @@ -2557,7 +2557,7 @@ bool memcg_slab_post_charge(void *p, gfp_t flags)
> >> * of slab_obj_exts being allocated from the same slab and thus the slab
> >> * becoming effectively unfreeable.
> >> */
> >> - if (is_kmalloc_normal(s))
> >> + if (!cache_needs_objcg(s))
> >> return true;
> >>
> >> /* Ignore already charged objects. */
> >> @@ -3435,6 +3435,10 @@ static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags,
> >>
> >> slab->objects = oo_objects(oo);
> >>
> >> +#ifdef CONFIG_64BIT
> >> + if (cache_needs_objcg(s))
> >> + slab->obj_exts_needs_objcg = 1;
> >> +#endif
> >> slab->slab_cache = s;
> >>
> >> kasan_poison_slab(slab);
> >>
> >> --
> >> 2.55.0
> >>
> >
>
--
Thanks,
Hao
next prev parent reply other threads:[~2026-07-23 10:01 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 14:16 [PATCH v2 00/13] mm/slab, alloc_tag: reduce obj_ext memory waste Vlastimil Babka (SUSE)
2026-07-20 14:16 ` [PATCH v2 01/13] mm/slab: skip kfence objects in allocation profiling Vlastimil Babka (SUSE)
2026-07-21 5:43 ` Harry Yoo
2026-07-21 9:20 ` Vlastimil Babka (SUSE)
2026-07-21 15:41 ` Harry Yoo
2026-07-22 12:47 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 02/13] mm/slub: skip handle_failed_objexts_alloc() with profiling disabled Vlastimil Babka (SUSE)
2026-07-21 5:51 ` Harry Yoo
2026-07-21 9:23 ` Vlastimil Babka (SUSE)
2026-07-20 14:16 ` [PATCH v2 03/13] mm/slab: remove objs_per_slab() Vlastimil Babka (SUSE)
2026-07-21 5:53 ` Harry Yoo
2026-07-23 11:29 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 04/13] mm: move struct slabobj_ext to mm/slab.h Vlastimil Babka (SUSE)
2026-07-21 5:55 ` Harry Yoo
2026-07-23 11:29 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 05/13] mm/slab: make slab_obj_ext() determine object index Vlastimil Babka (SUSE)
2026-07-21 6:02 ` Harry Yoo
2026-07-23 11:30 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 06/13] mm/slab: abstract slabobj_ext.objcg access Vlastimil Babka (SUSE)
2026-07-23 11:32 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 07/13] mm/slab: abstract slabobj_ext.ref access Vlastimil Babka (SUSE)
2026-07-23 11:32 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 08/13] mm/slab: replace slab.stride with obj_exts_in_object Vlastimil Babka (SUSE)
2026-07-23 11:32 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 09/13] mm/slab: change struct slabobj_ext to a union Vlastimil Babka (SUSE)
2026-07-23 3:05 ` Hao Li
2026-07-23 6:27 ` Harry Yoo
2026-07-23 9:56 ` Hao Li
2026-07-20 14:16 ` [PATCH v2 10/13] mm/slab: introduce slab_obj_ext_has_codetag() Vlastimil Babka (SUSE)
2026-07-20 14:16 ` [PATCH v2 11/13] mm/slab: reduce slabobj_ext memory with allocation profiling disabled Vlastimil Babka (SUSE)
2026-07-20 14:16 ` [PATCH v2 12/13] mm/slab: add cache_ and slab_needs_objcg() helpers Vlastimil Babka (SUSE)
2026-07-23 9:25 ` Hao Li
2026-07-23 9:30 ` Vlastimil Babka (SUSE)
2026-07-23 10:01 ` Hao Li [this message]
2026-07-20 14:16 ` [PATCH v2 13/13] mm/slab: stop allocating objcg pointers when unnecessary Vlastimil Babka (SUSE)
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=amHldYIo_-Bgm7Ek@fedora \
--to=hao.li@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=cl@gentwo.org \
--cc=elver@google.com \
--cc=glider@google.com \
--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 \
--cc=vbabka@kernel.org \
/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