🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26453

Re: [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for s...

#26453
From: Harry Yoo
Date: Thu, 03 Dec 2026 15:08
108 lines
15415 bytes
Thank you for the all ACKs and reviews, folks!

I feel this is almost ready for mainline but given that we're already
reaching -rc6 soon I guess it should target v7.6. I will give it a
couple of weeks and post v3.

-- 
Cheers,
Harry / Hyeonggon

On Wed, Nov 25, 2026 at 09:37:01PM +0000, Harry Yoo (Meta) wrote:
> TL;DR
> -----
> 
> The purpose of this series is to convert existing slab users that
> specify __GFP_ACCOUNT on allocations to specify SLAB_MAY_ACCOUNT on
> cache creation, to reduce memory waste for slab metadata with
> CONFIG_MEMCG=y && CONFIG_MEM_ALLOC_PROFILING=y.
> 
> Longer version of the cover letter
> ----------------------------------
> 
> Currently, there are two ways to charge slab objects to memory
> cgroups: 1) specify SLAB_ACCOUNT during cache creation, or 2) specify
> __GFP_ACCOUNT on allocation. The latter method made it impossible to
> assume that certain slab caches are never charged to memory cgroups.
> 
> Since commit d4404b0f5b8b ("mm/slab: stop allocating objcg pointers when
> unnecessary"), slabobj_ext allocates the space for the objcg pointer
> only for caches with SLAB_MAY_ACCOUNT. However, kmem_cache_create() sets
> the flag on every cache, because any cache may be used with
> __GFP_ACCOUNT.
> 
> As a result, sizeof(struct obj_cgroup *) bytes are wasted for each
> unaccounted slab object when both memalloc profiling and memcg are
> enabled. This is suboptimal when memalloc profiling is used to
> profile memory allocations on production.
> 
> So, let's make memcg charging opt-in and stop wasting memory!
> 
> New rule for slab users: a cache must specify SLAB_MAY_ACCOUNT
> (explicitly or implied by SLAB_ACCOUNT) for its objects to be charged
> to a memcg. Otherwise __GFP_ACCOUNT is ignored and triggers a warning on
> debug kernels (CONFIG_DEBUG_VM=y).
> 
> The approach is quite straightforward, but converting all caches that
> may pass __GFP_ACCOUNT without SLAB_ACCOUNT at once is not.
> As a best-effort approach, I swept the whole tree (with help of an
> LLM) for paths that pass __GFP_ACCOUNT into slab allocations either
> directly or indirectly.
> 
> While I tried to make sure the sweep is exhaustive, there can be a
> missing conversion. However that is not a correctness problem:
> the objects are just no longer charged to memcgs. Patch 13 adds
> VM_WARN_ON_ONCE in __memcg_slab_post_alloc_hook() to catch such a
> missing conversion.
> 
> Patch 1 allows passing SLAB_MAY_ACCOUNT to kmem_cache_create(),
> patches 2-12 specify SLAB_MAY_ACCOUNT for the caches found by
> the sweep, and patch 14 stops setting SLAB_MAY_ACCOUNT on all caches.
> 
> Memory savings and testing
> --------------------------
> 
> On an idle x86 VM with both memalloc profiling and memcg enabled,
> slabobj_ext memory (the alloc_slab_obj_exts entry in /proc/allocinfo)
> drops from 1,280KB to 910KB (-29%) after boot. The savings are expected
> to be larger on real workloads, which allocate far more unaccounted slab
> objects (8 bytes per unaccounted slab object).
> 
> Each tested cache was verified with the warning in patch 13:
> I confirmed that 1) the warning is triggered without the conversion,
> and 2) specifying SLAB_MAY_ACCOUNT resolves it. However I could not test
> io-pgtable_armv7s_l2 and sun50i's pt_pool caches due to lack of the
> hardware and emulation support. So they are compile-tested only.
> 
>   cache                  tested  environment
>   ---------------------  ------  -----------------------
>   radix_tree_node        yes     x86
>   maple_node             yes     x86
>   buffer_head            yes     x86
>   skbuff_head_cache      yes     x86
>   fanotify_*_event       yes     x86
>   smack_rule             yes     x86
>   io-pgtable_armv7s_l2   no      compile-tested only
>   thread_stack           yes     ppc64le (64K pages)
>   pgd_cache (arm64)      yes     arm64 (64K pages)
>   PGT_CACHE (powerpc)    yes     ppc64le
>   PCI_DMA_*_tables       yes     s390x (zPCI + vfio)
>   hostfs_inode_cache     yes     UML
>   sun50i pt_pool         no      compile-tested only
> 
> Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
> ---
> Changes in v2:
> - Rebased onto the latest slab/for-next.
> - Collected Acked-by from Jakub and Reviewed-by from Casey. Thanks!
> - Patch 1
>   - Resolve "sysfs: cannot create duplicate filename" warning by
>     encoding SLAB_MAY_ACCOUNT in create_unique_id() (kernel test robot,
>     Sashiko).
>   - Define SLAB_MAY_ACCOUNT in tools/include/linux/slab.h to fix
>     the build of tools/testing/{radix-tree,vma} (Mike, Sashiko).
> - Swept the tree again on the new base. No new cache needs
>   SLAB_MAY_ACCOUNT.
> - Re-tested all the conversions on the new base.
> - Link to v1: https://patch.msgid.link/20261021-memalloc-prof-dont-waste-slabobj-ext-metadata-v1-0-096800aa3330@kernel.org
Technical Details
Message-ID: <axGErSYXcGHW7dTh@thinkstation>
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376697-linux-kernel-netdev=dewy.ru
References: <20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-0-7c680f02a734@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376697-linux-kernel-netdev=dewy.ru
From: harry@kernel.org (Harry Yoo)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT
 for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata
Date: Thu, 3 Dec 2026 15:08:33 +0000
Organization: Usenet Network
Message-ID: <axGErSYXcGHW7dTh@thinkstation>
References: <20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-0-7c680f02a734@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="2523529"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:AzT+Go4jdV1OtHvr7aaldj/3VQY= sha256:xnEi+ZvixYSRBDpstMcl7iF5A82zHDz7L+VQFsQQOgg=
	sha1:FJQN74F319rJktUD9DXPJsb3J5k= sha256:trP4Qi8KLJYuMeONU/y7JBoPq99lPBkpaK7p55k5MA4=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 2A58A11799C; Thu,  3 Dec 2026 18:08:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.74
X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Sg2YYk8DWk_T;
	Thu,  3 Dec 2026 18:08:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-376697-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 504EC11794E; Thu,  3 Dec 2026 18:08:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id E14F9603451; Thu,  3 Dec 2026 15:08:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796310516;
	b=xR0zzwsEqIhMmY9o0XI+8PBmpanOn3vIbw3bd/m34eMaI0tT1ERVO4lV9fAXtaAEMVEc
	 3E9aRkKtS1q/7yVTMvdutgHXqlPxHyjP4NkEgBJMJS/AevOWe4U5lSep3VOLi/osHsBnu
	 9p8fGvvMon7fhEKX8UHiRNx+4lR7OyuxnCDiT3lozd1MYr9FKghj1SzvsAUauhWKVYhuB
	 9y0BbXQAYq0y1g+2hIBuXuOfpkrhHctXhbArFs/zC8mIdS2N7KU6zuj2srAX0U7u0Einf
	 t/c1VZC6RzPYAUkxVvkx9yEv5iq2oBBCDecnF++nRLiOayhjh3zqyID66xS58nGndQw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796310516;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=nBCZZut6NEJtyIAHdK8MnPE19tpv1rASBocwU2Y+ZVM=;
	b=3M5oYmmVBcxKMANCBiK6Uh6Xji7BQEbmmypS71Bg8cUlXJ0Lfke2rReprjghxlJLeA7t
	 kvsPwbyn81OozXbZH/+OBA2OqqwLR9763mR1JudEElYEC//9xfCtNIuKENbcIUDQ58APq
	 m6D7/kUXZ/EVsYnuF/uPIPRHdZ5baUgikBtKxummPF6J43G1d1HFfhcTDAT1XWreIf5lE
	 22PAWJHvGqX5LFD1EUd5SThaej9C4vzD6vJUrbuxoISPgGxO5syk5p2/otxf9Zae2amTZ
	 GonlbNDgVkc4M2uGtHUjdpkS05G5tNSY4NSOnfrHwbOWi5xDSSTBkQ7/MV3Sp3EyC5Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IbpR1a+2;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B7972606A681;
	Thu,  3 Dec 2026 15:08:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IbpR1a+2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796310515;
	b=hiCZd+SiBFqIrgsRmp5A/TLmSEWDPdmYPOh1xjAjrc98bZJtYxrujwIQVj0A2YgJgr0v
	 jNav/ODIQyzsKphYK6yVVpLq64aZXCk90FFG28N+QhzZei40h5MA2yj5z2i0Czz5XJK7O
	 2e91a6PI3aw2EFarcEpnIZFjxQ+eGq+X/oc9O/n3yqhWjvinNGk4EviNbhLjSS2ES6C30
	 MHxCAz0mh6j2O0mBJJkpBMhKMSkMcHzKvSYqfHGaH4Y9H2f6gYHkKWDKtm7pRYSmD0Bca
	 at3DliHqZ53JLzrkCWC1SxF7xRs/6BayQsmQ6sXMPBVtG15UeAD7oyeK1bhSVy2EEZg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796310515;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=nBCZZut6NEJtyIAHdK8MnPE19tpv1rASBocwU2Y+ZVM=;
	b=uoyGecYBG0mhmjpnF7jw5ncMY8KC1WkR4MXFKEF8QhOVRMeHXZiIhkq/oZANcKK7kvhI
	 xXjt9xtIDM1jjidg/K2axMX7TvAwBVe7HDTC/V6BFRWZsTlnc9sJaGud1LyVXWMQaJ/u1
	 mEAmkkyBsAM662nlXmtLdE/hB9i6ue5AxUC0KgmjFCmcZWAq/JIH2rJ3VxDNEAGcb5zM1
	 itt8iM7dQIps475Ze279vaxeF4i3h5XR4qNV0els8CuvMDhGxS3R4WhDcXzxg8Ta+TjDN
	 Go0YE207EbcksR/5FWdMqJn/sexLu5dN6DjB10gZ4UHjwr4H5jCsLlTsK0Eb1OoODWA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IbpR1a+2;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0139606A32D;
	Thu,  3 Dec 2026 15:08:35 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 608D11F0089A;
	Thu,  3 Dec 2026 15:08:34 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796310515;
	bh=nBCZZut6NEJtyIAHdK8MnPE19tpv1rASBocwU2Y+ZVM=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=IbpR1a+2jAAUy1PhGCGsWEzIvHUTd8PGp9nSywm20ogxLmTkuKJcz9t5A0FG+N4Td
	 uPloTjPpEwKu8aoOvq6xKuP/UCfQaQsyN1D4VY4/m6DCrn96fP5I7TgENlh/xSZsX9
	 nXsl+lbsvNJYaydp3FNyAO7fg4g0vSxBuOCqYcAYcycL2Cafqq/CB5YTeUvk/VtWLD
	 b7rU9fkYVG0jinRIhMNyC+VhGvtsA16sBqDiES5zVtcNJp4dwAPrAcarFu+d/zqzod
	 uj387fH+ApsoS27eWRj/W7qbE2LCIdHkefovO1EgXdl/KPwSBt0hjWNPhf76/toDmQ
	 gEBx8Y/zncZzg==
X-Cc: Hao Li <hao.li@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>, maple-tree@lists.infradead.org, Paolo Abeni <pabeni@redhat.com>, 
	Simon Horman <horms@kernel.org>, Jason Xing <kerneljasonxing@gmail.com>, 
	Willem de Bruijn <willemb@google.com>, Mina Almasry <almasrymina@google.com>, 
	Björn Töpel <bjorn@kernel.org>, Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>, 
	Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>, 
	Juri Lelli <juri.lelli@redhat.com>, Vincent Guittot <vincent.guittot@linaro.org>, 
	Dietmar Eggemann <dietmar.eggemann@arm.com>, Steven Rostedt <rostedt@goodmis.org>, 
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>, 
	Valentin Schneider <vschneid@redhat.com>, K Prateek Nayak <kprateek.nayak@amd.com>, 
	Anshuman Khandual <anshuman.khandual@arm.com>, linux-arm-kernel@lists.infradead.org, 
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>, linuxppc-dev@lists.ozlabs.org, 
	Niklas Schnelle <schnelle@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, 
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>, Chen-Yu Tsai <wens@kernel.org>, 
	Jernej Skrabec <jernej.skrabec@gmail.com>, Samuel Holland <samuel@sholland.org>, iommu@lists.linux.dev, 
	linux-s390@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-um@lists.infradead.org, 
	cgroups@vger.kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-0-7c680f02a734@kernel.org>