From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 608D11F0089A; Thu, 3 Dec 2026 15:08:34 +0000 (UTC) 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== Date: Thu, 3 Dec 2026 15:08:33 +0000 From: Harry Yoo To: Vlastimil Babka , Andrew Morton , Suren Baghdasaryan , Johannes Weiner , Michal Hocko , Shakeel Butt , Roman Gushchin Cc: Hao Li , Christoph Lameter , David Rientjes , Muchun Song , Hao Ge , Pedro Falcato , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, "Liam R. Howlett" , Alice Ryhl , Andrew Ballance , Matthew Wilcox , linux-fsdevel@vger.kernel.org, Alexander Viro , Christian Brauner , Jan Kara , "David S. Miller" , Jakub Kicinski , Sebastian Andrzej Siewior , Jiayuan Chen , netdev@vger.kernel.org, Kees Cook , David Hildenbrand , Lorenzo Stoakes , Catalin Marinas , Will Deacon , Mark Rutland , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Robin Murphy , "Joerg Roedel (AMD)" , Amir Goldstein , Casey Schaufler , Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , Eric Dumazet , maple-tree@lists.infradead.org, Paolo Abeni , Simon Horman , Jason Xing , Willem de Bruijn , Mina Almasry , =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , Mike Rapoport , Michal Hocko , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Anshuman Khandual , linux-arm-kernel@lists.infradead.org, "Christophe Leroy (CS GROUP)" , linuxppc-dev@lists.ozlabs.org, Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , iommu@lists.linux.dev, linux-s390@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-um@lists.infradead.org, cgroups@vger.kernel.org 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 Message-ID: References: <20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-0-7c680f02a734@kernel.org> X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-0-7c680f02a734@kernel.org> 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) > --- > 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