🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26414

Re: [PATCH slab/for-next v2 14/14] mm/slab: do not set SLAB_MAY_ACCOUNT for all caches

#26414
From: Hao Li
Date: Thu, 03 Dec 2026 14:17
80 lines
12846 bytes
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>
> ---
>  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
Technical Details
Message-ID: <axF1jxUBKq0Y00tw@fedora>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!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-376650-linux-kernel-netdev=dewy.ru
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>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!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-376650-linux-kernel-netdev=dewy.ru
From: hao.li@linux.dev (Hao Li)
Newsgroups: linux.kernel.netdev
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 14:17:21 +0000
Organization: Usenet Network
Message-ID: <axF1jxUBKq0Y00tw@fedora>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="2511489"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:4pvn5Q1A3C4gnjt3fL5pHDSY1Hg= sha256:9E83qD3N/ADAjHBhsHBjoQI4FlllPT7UIK70HakfLdc=
	sha1:rvVMoPsn4CBZxTJ9h3acWYUnTkM= sha256:rDPUj4o56o/WLpYX6CH3Hq1KUybQG8NeY3cL1HHawio=
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 1347A117975; Thu,  3 Dec 2026 17:19:02 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.299
X-Spam-Status: No, score=-3.299 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001,
	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 (1024-bit key)
	header.d=linux.dev
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 J-4oDHogvJDC;
	Thu,  3 Dec 2026 17:18:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376650-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 5986E11790E; Thu,  3 Dec 2026 17:18:46 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id DDC233005B; Thu,  3 Dec 2026 14:18:15 +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=1796307492;
	b=zjGyo1scEDOi2/JSFh84GpVlqi8KqJ2Oiix6LNyTkPi+LI2VjnNx4MsDwQJS9OvskpzG
	 z4d5yw247DrTrKfAarqlKYmyjJNF2usyZNeHWpS8hcEv1y86O/7p/Ng0gbWz5AGQnr2+L
	 Vieg19VQul4ytjCC09ZDdCYdLdh/Qrg078P0tOvN0PrH0Eh+PwgLJuwp98oqQazqGZQFS
	 mQwUURaXK6GgfX6XQF61GnT9g6jQ4IXIXtvBafCvGawzkA3mASsGLR6i0M3FqsQDScZ2H
	 Vtsqu0ovEkkfh6/JO4Zyv3dJMchu2XwBHTkZWEUiSgtqZ/c6XDsFCCv6799nja3e1YA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796307492;
	h=X-Original-To:Received: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: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=QRsF9puGeyosF/QZRGchJAFRwy4XAM350SjW7HgBK5Y=;
	b=x48qdnI4Rs3XrBvDCkHLo2ssM+X2hShQHudXfM88/MwjHPEAMRiz92eSZttNPO0X3jK3
	 tfAALHy6SC6YVBFYZFvG8lxsbIsbZqKc7NShhMrgEsUBIeJJpkjYqI49tYvaN6KvT1hv2
	 U2Fdlnsat2lBHV9bxwUQFPB/RL7oIasuiv5tWfou6OxmZ5xDoqFFBZ2HFtKszh3DZwGYu
	 18q416z+ldNLXUYDpJM+gvnbYUefhoO6VSr6zBxV7slb6mpQ+X+gEGwrSW7uyrtcLgyA6
	 WyCXqduHmXLEbUMI0+uMlcdud0Z8tCWQAYJJBvRhrJMTcblZ5xyvanZU3Rjxh6ehoFw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=QDJvcQZc;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 32B0D606A693;
	Thu,  3 Dec 2026 14:18:12 +0000 (UTC)
X-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=QDJvcQZc
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.121
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796307491;
	b=dsmV706aGvBBqmWBIbL0I5zpWVxXmLhOCl+lBwVmeVgsvtQrMqHQbbGYr5DWo0pbPJ1Y
	 8INfiSGVCIs5CxGFweMnY/9HPg0Y7fTJy02DB2ZMWyg1B+Bnt74S+6qBf+EXZp5ndAsHn
	 a587OSQjS5cOI065sl0eqMg8H7n758yKnIJjUEg/tyEmQXJkM7CWaCyL332hJHVrdskfW
	 BjRhIQy57RfOg+6Z+YV9XgUn2Oir4onPvpOzhoeasqiSCtm5UGjPvsAdz2m33pooMnW1a
	 ZhFVvkdtttkNoB7lpP4vxA+kbih/KHdidU9YDFQRCNV99EMGUdMQtNF44fnH/RCblcQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796307491;
	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=Ftqt1+7fqT+MBwRaQDXjyl2WW89kZRjIKw+xeYQdpdvchDYjKqBXGF6jwpw2X9emWpLx
	 JAa2ffISECI3wiKd3bYl8OqxDq/86tDxoLaD3g5TTamx/EoTMSiRSDTsx5aRvYrSFUO4z
	 ueymSF4rEmEF8EhVLmbCTOcq+jVXx6tpiKnAk/CPOnqtNhsfNqbj0SvMuu4qOciQ1yEO2
	 yKhIY02gHVslK2qR0jlPVXbP1yUWAh0uVFZqWuuGEuyXajSIo07mOd2HM+c1X/O3SxUxb
	 LYPaOqhq8zFIv0BDnSqVjc8WwoRCCeO+uO/LFmei1FFx8itx6IEljC1ifZCUQy1Ibqw==
X-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=QDJvcQZc;
	arc=none smtp.remote-ip=91.218.175.121
X-Received: from mta0.migadu.com (out-121.mta0.migadu.com [91.218.175.121])
	(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 B7417606A32F
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 14:18:10 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7417606A32F
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-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=1796307487; v=1; x=1796912287;
 b=QDJvcQZcIdvqjEWx4C/hHA5YsxeFcSn5gUHZd8qlrDhpi9mRWVxxaDqlfIMLKp0xdgWs0GaO
 W9hE/emwY/lAJccjy1YrXZlEPnRH3e+ecgF7E0dCIcSMyQRN/OVjHQkCgZGYgpmPvLRGJJ9ZxxP
 EgCHuANxxSeNgrSXyNbO0n8M=
X-Envelope-To: netdev@vger.kernel.org
X-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
X-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>
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-14-7c680f02a734@kernel.org>