From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.159 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796307492; b=FBi1iJl5hggxAX5yU9mWEMyhD9vvbvDnhrryPWgoPI7F3gZI5ulFsgFbSVgRTBSUZ9AV UKj8YnFqpJf+2J7P4i8hnyTYyQ6VZGpYj3pZktw7U+jY7v79pmzQ98bgmdZVUZhzNuzAf OmSc56YCfaSkgbfqcsrmZuP8POYivH5N/ZAodfQZ04cbSTO2nv5S00QsaAMrESemTmvGV xQ1fe7lBNsSoKZcTOl34rHMEGI4aLEgSZg5Re57Z3HfQr+67NtDoBC/XZRZplRgFHNK4K h31e0k+tB1JrH87u8/BmrprxY9BbRDVUR8CI9QNjbhoja0oZ/Ntbikz3Zhz8X57oLEw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796307492; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=QRsF9puGeyosF/QZRGchJAFRwy4XAM350SjW7HgBK5Y=; b=q45G+6CHJJ5/oqx7ie0TY6SqXWhfu5RixfiOWwdPmcCOT8gcvSkyx3rH9JbNfFuAD4aL 2+vyPZOBA2lCA9uX4/dwCg7JnwH3V3WKeLPJTKz+14Mdut4kE1PbvQ64OPWzIOgJTJN5P meYO6crc4nk68rOu/AeOY28v+lJDBvaUKvWS5WP65ARn0XVIu44X4Ucizwcemu8NNZfiY vt2fxLVMzhwnSCuY3iIy4tYy8K4KQKZqXq0jsbaCridFqr1A/vw77pt6bT8yGAgT7aZmQ lcWDr517O2HW7l2+BmTT863V6dy5AGyDxYBaAw0naxcbwZW2Hw616SCs2d+h4yxikRA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=donxnuqA; arc=none smtp.remote-ip=95.215.58.159 Received: from mta1.migadu.com (out-159.mta1.migadu.com [95.215.58.159]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 915DE606A685 for ; Thu, 3 Dec 2026 14:18:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 915DE606A685 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=donxnuqA X-Envelope-To: linux-fsdevel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Rg6K4h6/kySwYmiPvtPSiqCrai3k8yXeiiQqi+kiCGs=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796307488; v=1; x=1796912288; b=donxnuqAnZtAIXMqySyDeKBTzvMkBrkpCDb6a25egWrew4kTIkj+Qg394e3MfHbTecUx/vZx WW5fdM82YdeD4xDgbgHWgHo2SHZhHXpj1bX9ICsvWnWpdHn7hMqpSNVr87/BIJRos70Hh82h8VS IXqe2/dFwC2OPPAAFga9V3bU= X-Envelope-To: linux-fsdevel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id c5f57345048f755d; Thu, 03 Dec 2026 14:18:06 +0000 X-Mizu-Trace-ID: c5f57345048f755d X-Migadu-Flow: FLOW_OUT Date: Thu, 3 Dec 2026 14:17:21 +0000 From: Hao Li To: "Harry Yoo (Meta)" Cc: Vlastimil Babka , Andrew Morton , Suren Baghdasaryan , Johannes Weiner , Michal Hocko , Shakeel Butt , Roman Gushchin , 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 Subject: Re: [PATCH slab/for-next v2 14/14] mm/slab: do not set SLAB_MAY_ACCOUNT for all caches Message-ID: References: <20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-0-7c680f02a734@kernel.org> <20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-14-7c680f02a734@kernel.org> X-Mailing-List: linux-fsdevel@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-14-7c680f02a734@kernel.org> 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) > --- > include/linux/slab.h | 16 +++++++++++++--- > mm/slab_common.c | 8 +++----- > 2 files changed, 16 insertions(+), 8 deletions(-) > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index ad645967a3ee..8525e70eaa76 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -201,14 +201,24 @@ enum _slab_flag_bits { > /** > * define SLAB_ACCOUNT - Account allocations to memcg. > * > - * All object allocations from this cache will be memcg accounted, regardless of > - * __GFP_ACCOUNT being or not being passed to individual allocations. > + * All object allocations from this cache will be memcg accounted. > + * SLAB_ACCOUNT implies SLAB_MAY_ACCOUNT. > */ > #ifdef CONFIG_MEMCG > # define SLAB_ACCOUNT __SLAB_FLAG_BIT(_SLAB_ACCOUNT) > -# define SLAB_MAY_ACCOUNT __SLAB_FLAG_BIT(_SLAB_MAY_ACCOUNT) > #else > # define SLAB_ACCOUNT __SLAB_FLAG_UNUSED > +#endif > + > +/** > + * define SLAB_MAY_ACCOUNT > + * > + * Objects will be memcg accounted when __GFP_ACCOUNT flag is specified. > + * Requesting __GFP_ACCOUNT allocations without SLAB_MAY_ACCOUNT is not allowed. > + */ > +#ifdef CONFIG_MEMCG > +# define SLAB_MAY_ACCOUNT __SLAB_FLAG_BIT(_SLAB_MAY_ACCOUNT) > +#else > # define SLAB_MAY_ACCOUNT __SLAB_FLAG_UNUSED > #endif > > 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. > > /* Fail closed on bad usersize of useroffset values. */ > if (!IS_ENABLED(CONFIG_HARDENED_USERCOPY) || > > -- > 2.54.0 > -- Thanks, Hao