All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hao Li <hao.li@linux.dev>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: harry@kernel.org, akpm@linux-foundation.org, cl@gentwo.org,
	 rientjes@google.com, roman.gushchin@linux.dev,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
Date: Thu, 12 Nov 2026 15:54:34 +0800	[thread overview]
Message-ID: <avVnuWCQW56qznll@fedora> (raw)
In-Reply-To: <e2d1dc9f-59ff-4dfb-8ca4-35c584d14b35@kernel.org>

On Wed, Nov 11, 2026 at 02:08:40PM +0100, Vlastimil Babka (SUSE) wrote:
> On 11/11/26 13:49, Hao Li wrote:
> > An allocation with __GFP_ACCOUNT set (without __GFP_DMA or
> > __GFP_RECLAIMABLE) is redirected to KMALLOC_CGROUP and will never hit
> > KMALLOC_NORMAL or KMALLOC_PARTITION_CACHES. Consequently, neither of
> > these caches requires objcg slots in obj_exts.
> > 
> > While KMALLOC_NORMAL already skips setting SLAB_MAY_ACCOUNT,
> > KMALLOC_PARTITION_CACHES still carries it unnecessarily.
> > 
> > Extend the check to skip KMALLOC_PARTITION_CACHES as well, saving
> > unnecessary objcg slots in obj_exts.
> > 
> > Signed-off-by: Hao Li <hao.li@linux.dev>
> 
> Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

Thanks!

> 
> > ---
> > This doesn't seem like a real bug to me, just a small waste of memory, so I
> > didn't add a Fixes tag.
> 
> Hmm I'd add
> Fixes: 7def2e8549e5 ("mm/slab: add cache_ and slab_needs_objcg() helpers")

Ah right, I mixed up Fixes with cc stable. Thanks for pointing it out!

> 
> The question is whether cc stable as well. 7.3 LTS will be used for Android
> and IIRC they have memory allocation profiling enabled. Not sure about
> kmalloc partitions. Cc'ing Suren.

Makes sense. If Android uses partitioned caches, then it looks like we should
cc stable.

> 
> > ---
> >  mm/slab_common.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/mm/slab_common.c b/mm/slab_common.c
> > index 2befd24b4d09..f0ea1fa178e7 100644
> > --- a/mm/slab_common.c
> > +++ b/mm/slab_common.c
> > @@ -1000,16 +1000,18 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)
> >  #endif
> >  
> >  	/*
> > -	 * 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.
> > +	 * If memcg_kmem is enabled and this is a KMALLOC_NORMAL or
> > +	 * KMALLOC_PARTITION_CACHES 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. The exception is a
> >  	 * KMALLOC_NO_OBJ_EXT cache.
> >  	 */
> >  	if (!mem_cgroup_kmem_disabled()) {
> > -		if (type == KMALLOC_NORMAL && KMALLOC_RECLAIM != KMALLOC_NORMAL)
> > +		if (type >= KMALLOC_PARTITION_START &&
> > +		    type <= KMALLOC_PARTITION_END &&
> > +		    KMALLOC_RECLAIM != KMALLOC_NORMAL)
> >  			flags |= SLAB_NO_MERGE;
> >  		else if (!(flags & SLAB_NO_OBJ_EXT))
> >  			flags |= SLAB_MAY_ACCOUNT;
> 

      reply	other threads:[~2026-11-12  7:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 12:49 [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES Hao Li
2026-11-11 13:08 ` Vlastimil Babka (SUSE)
2026-11-12  7:54   ` Hao Li [this message]

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=avVnuWCQW56qznll@fedora \
    --to=hao.li@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.