From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.106 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796312874; b=LUn3iigsA0aVEPjCuDJ/gQtotbIzLJ+FmDam4IS1TNfUEZPTybldG0zWVliAwHW8Y7eo Z0n7AGtt+AIDGTxyXpIUxzTHRubw7TpRWV75un5iq9cGD5/6BkOrFO23pUZV9vw2rXnYS i35pCIPU96c8K9JD4RoceQis9bKrhnBCnUH/tg74UfMgfNxyd5cgh9d3CDyNaKEmciV+a Ps64D3fjHi2lU8UKwDA57HZ1cAdvY9Ww3bjtmVUQ92ULwQm6Wr2Dz4YnasC/X0572vKne dzRurwOAxkFk0CScoo0l82qtoZzyJ6ntKQGbYQSnTXPNcrwgSQt4U1rALOr2dd/cWRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796312874; 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=iVqFyx4eEKm5axwDGZ5BFHB9motCDI788uXhTdfQvRM=; b=LvCpiLSOh9YgHvRFBaCzXcgOLfkzjvgRA1ui2zIWC82JLFgjHZomhmYL6vA0MiFT786b B6zWgfkh8pOMAqIQR2AU89DqWXWoN0wgNGSdkn7n4RooUzr0SDrPnZ93KvnCRekv3r0Cm qHYO6pqSMSFyjovrSc/mOHdj77KxwIVUvNgS1Om/eRhV1ycdEL7OHmSE5uJKg+gXy5ees N7FGss671yUnkDoixVAW/pdHgnC6tPI/YwoFiKJNQBGJRUkFQZMjmzmUdJ2/++4n/MdgD qqkFO5eUCQVgn7ri//iyrH4QVVguRk/FD/FEMfGr/VgS8HmG4ON2BSD19VRBeqN7N8A== 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="pDDcZBE/"; arc=none smtp.remote-ip=95.215.58.106 Received: from mta1.migadu.com (out-106.mta1.migadu.com [95.215.58.106]) (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 E7490606A330 for ; Thu, 3 Dec 2026 15:47:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E7490606A330 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=pDDcZBE/ X-Envelope-To: linux-security-module@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=QqlQlGmxu2LmbSPTp+tsr/hojjHy1g55TMpi9cmZi68=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796312871; v=1; x=1796917671; b=pDDcZBE/glkqrdCAdO+BFIrrTWE/U9mpDPOAsoOfnUG98WVr71Juuo2r3AkQHQrbdZj+kDBZ 22e4pOx/47fQIruHawyGZtn+BnD2D00ATEdxhGhRLUurdP+3F2L4GcNR1S0mQHItq7skvYY54Qx tu/iOhDNLtQGcyQh8hSonGqE= X-Envelope-To: linux-security-module@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 339cfd8b1d3524c3; Thu, 03 Dec 2026 15:47:50 +0000 X-Mizu-Trace-ID: 339cfd8b1d3524c3 X-Migadu-Flow: FLOW_OUT Date: Thu, 3 Dec 2026 15:47:25 +0000 From: Hao Li To: Harry Yoo 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-security-module@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: 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) > > > > > --- > > > > > 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 -- Thanks, Hao