Linux filesystem development
 help / color / mirror / Atom feed
From: Hao Li <hao.li@linux.dev>
To: Harry Yoo <harry@kernel.org>
Cc: Vlastimil Babka <vbabka@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Suren Baghdasaryan <surenb@google.com>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	 Shakeel Butt <shakeel.butt@linux.dev>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	 Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	 Muchun Song <muchun.song@linux.dev>, Hao Ge <hao.ge@linux.dev>,
	Pedro Falcato <pfalcato@suse.de>,
	 linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com,  "Liam R. Howlett" <liam@infradead.org>,
	Alice Ryhl <aliceryhl@google.com>,
	 Andrew Ballance <andrewjballance@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	 linux-fsdevel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	 Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	"David S. Miller" <davem@davemloft.net>,
	 Jakub Kicinski <kuba@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	 Jiayuan Chen <jiayuan.chen@linux.dev>,
	netdev@vger.kernel.org, Kees Cook <kees@kernel.org>,
	 David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	 Mark Rutland <mark.rutland@arm.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	 Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	 Robin Murphy <robin.murphy@arm.com>,
	"Joerg Roedel (AMD)" <joro@8bytes.org>,
	 Amir Goldstein <amir73il@gmail.com>,
	Casey Schaufler <casey@schaufler-ca.com>,
	 Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	 "Serge E. Hallyn" <serge@hallyn.com>,
	linux-security-module@vger.kernel.org,
	 Richard Weinberger <richard@nod.at>,
	Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	 Johannes Berg <johannes@sipsolutions.net>,
	Eric Dumazet <edumazet@kernel.org>
Subject: Re: [PATCH slab/for-next v2 14/14] mm/slab: do not set SLAB_MAY_ACCOUNT for all caches
Date: Thu, 3 Dec 2026 15:47:25 +0000	[thread overview]
Message-ID: <axGEqynYEexukm46@fedora> (raw)
In-Reply-To: <axF_9PFvl-Ypa9dD@thinkstation>

On Thu, Dec 03, 2026 at 02:46:49PM +0000, Harry Yoo wrote:
> On Thu, Dec 03, 2026 at 02:36:57PM +0000, Hao Li wrote:
> > On Thu, Dec 03, 2026 at 02:27:25PM +0000, Harry Yoo wrote:
> > > On Thu, Dec 03, 2026 at 02:17:21PM +0000, Hao Li wrote:
> > > > On Wed, Nov 25, 2026 at 09:37:15PM +0000, Harry Yoo (Meta) wrote:
> > > > > Now that all caches whose objects may be allocated with __GFP_ACCOUNT
> > > > > specify SLAB_MAY_ACCOUNT (or SLAB_ACCOUNT, which implies it), stop
> > > > > assuming any cache may be used with __GFP_ACCOUNT. This avoids wasting
> > > > > the objcg slot in slabobj_ext for caches that are never charged to a
> > > > > memcg.
> > > > > 
> > > > > Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
> > > > > ---
> > > > > diff --git a/mm/slab_common.c b/mm/slab_common.c
> > > > > index 193b5a03bc47..464695504248 100644
> > > > > --- a/mm/slab_common.c
> > > > > +++ b/mm/slab_common.c
> > > > > @@ -367,12 +367,10 @@ 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())
> > > > > +	if (flags & SLAB_ACCOUNT)
> > > > >  		flags |= SLAB_MAY_ACCOUNT;
> > > > > +	if (mem_cgroup_kmem_disabled())
> > > > > +		flags &= ~SLAB_MAY_ACCOUNT;
> > > > 
> > > > Btw, say maple_node/sk_buff/... could be merged with cacheX before. After this
> > > > patch, cacheX loses SLAB_MAY_ACCOUNT while we still set SLAB_MAY_ACCOUNT for
> > > > maple_node explicitly, so they can't be merged anymore. Not sure if it matters,
> > > > though.
> > > 
> > > Hmm you mean SLAB_ACCOUNT and SLAB_MAY_ACCOUNT should be cleared at
> > > run-time during merging decision with cgroup.memory=nokmem? 
> > 
> > Ah, not really. I mean, assuming kmem is enabled, before this patchset
> > all caches have SLAB_MAY_ACCOUNT. After applying it, some have the flag and
> > some don't, so `if ((flags & SLAB_MERGE_SAME) != (s->flags & SLAB_MERGE_SAME))`
> > in find_mergeable() might not hold anymore.
> 
> Ah, I see.
> This is intentional and benign I think :-)
> 
> We don't want to merge cache X and Y when only one of them has
> SLAB_MAY_ACCOUNT as that'll bloat metadata size.

Yeah, you're right. I just happened to think of commit 08c78a6d33af ("mm, slab:
rework KMALLOC_RECLAIM handling of SLUB_TINY"), which drops
SLAB_RECLAIM_ACCOUNT under slab_tiny so that caches can still be merged. Still,
memory savings from this patchset should far outweigh the slab merging we lose!

Looks good to me!
Reviewed-by: Hao Li <hao.li@linux.dev>

-- 
Thanks,
Hao

  reply	other threads:[~2026-12-03 15:47 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 21:37 [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Harry Yoo (Meta)
2026-11-25 21:37 ` [PATCH slab/for-next v2 01/14] mm/slab: allow passing SLAB_MAY_ACCOUNT to kmem_cache_create() Harry Yoo (Meta)
2026-12-03 14:23   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 02/14] lib/maple_tree: specify SLAB_MAY_ACCOUNT for maple_node cache Harry Yoo (Meta)
2026-11-26 19:34   ` Liam R. Howlett
2026-12-03 14:25   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 03/14] lib/xarray: specify SLAB_MAY_ACCOUNT for radix_tree_node cache Harry Yoo (Meta)
2026-12-03 14:41   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 04/14] fs/buffer: specify SLAB_MAY_ACCOUNT for buffer_head cache Harry Yoo (Meta)
2026-11-26  9:05   ` Jan Kara
2026-11-26 14:23     ` Harry Yoo
2026-12-03 14:46   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 05/14] net: skbuff: specify SLAB_MAY_ACCOUNT for skbuff_head_cache Harry Yoo (Meta)
2026-12-03 14:49   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 06/14] kernel/fork: specify SLAB_MAY_ACCOUNT for thread_stack cache Harry Yoo (Meta)
2026-12-03 14:52   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 07/14] arm64/mm: specify SLAB_MAY_ACCOUNT for pgd_cache Harry Yoo (Meta)
2026-12-03 14:53   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 08/14] powerpc/mm: specify SLAB_MAY_ACCOUNT for pgtable caches Harry Yoo (Meta)
2026-12-03 14:55   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches Harry Yoo (Meta)
2026-11-27 13:35   ` Niklas Schnelle
2026-12-03 14:59   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 10/14] fanotify: specify SLAB_MAY_ACCOUNT for event caches Harry Yoo (Meta)
2026-11-26  9:06   ` Jan Kara
2026-12-03 15:00   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 11/14] smack: specify SLAB_MAY_ACCOUNT for smack_rule cache Harry Yoo (Meta)
2026-12-03 15:01   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 12/14] hostfs: specify SLAB_MAY_ACCOUNT for inode cache Harry Yoo (Meta)
2026-12-03 15:02   ` Hao Li
2026-11-25 21:37 ` [PATCH slab/for-next v2 13/14] mm/memcontrol: do not allow charging objects without SLAB_MAY_ACCOUNT Harry Yoo (Meta)
2026-12-03 14:21   ` Hao Li
2026-12-03 15:15     ` Harry Yoo
2026-11-25 21:37 ` [PATCH slab/for-next v2 14/14] mm/slab: do not set SLAB_MAY_ACCOUNT for all caches Harry Yoo (Meta)
2026-12-03 14:17   ` Hao Li
2026-12-03 14:27     ` Harry Yoo
2026-12-03 14:36       ` Hao Li
2026-12-03 14:46         ` Harry Yoo
2026-12-03 15:47           ` Hao Li [this message]
2026-11-26 15:24 ` [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Shakeel Butt
2026-11-29  5:16 ` Chris Down
2026-12-03 14:22   ` Harry Yoo
2026-12-03 15:08 ` Harry Yoo

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=axGEqynYEexukm46@fedora \
    --to=hao.li@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=amir73il@gmail.com \
    --cc=andrewjballance@gmail.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=bigeasy@linutronix.de \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@gentwo.org \
    --cc=davem@davemloft.net \
    --cc=david@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hao.ge@linux.dev \
    --cc=harry@kernel.org \
    --cc=jack@suse.cz \
    --cc=jiayuan.chen@linux.dev \
    --cc=jmorris@namei.org \
    --cc=johannes@sipsolutions.net \
    --cc=joro@8bytes.org \
    --cc=kees@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mhocko@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=muchun.song@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=npiggin@gmail.com \
    --cc=paul@paul-moore.com \
    --cc=pfalcato@suse.de \
    --cc=richard@nod.at \
    --cc=rientjes@google.com \
    --cc=robin.murphy@arm.com \
    --cc=roman.gushchin@linux.dev \
    --cc=serge@hallyn.com \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=will@kernel.org \
    --cc=willy@infradead.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