From nobody Tue Feb 10 07:22:37 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25F0132D44F for ; Fri, 23 Jan 2026 06:53:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769151201; cv=none; b=WAv/FbrvsnOtyScCf9ODZUX4Hi/w7bIE44TbRxftLf+nNHMORFkyn12DjmJKAWT6LRArbO5fj6gztTneK0r5lQaFXTFCeJUFWKKYXfx7jUXSbUKSCuac45RWyH31l1YR9pwsAB1S1OwFnaIp4L4ZdOosfBTelqiwlFpdHexXAFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769151201; c=relaxed/simple; bh=IaePGwqWshxhTjZYl31tqWcQQw14RXWgkHaU/TSelIk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iMZjGbSXo9tihBNC5SbzaUPnc5ZnP/+0rB/EOW/o+k5oNIoXM8wvWrhA5FAdzqov76hGMNpFhsL2zm6S03T3BUDxzJLvK3neGmAfkpewXWJihIIQrH7DVXFNjItjiQuKBf5PO1L38FHnZfp4+9ed8LeZ8AtxYes0Rzzn+uehovI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=Gi3T+Xls; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=Q9pnIhD8; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=Gi3T+Xls; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=Q9pnIhD8; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="Gi3T+Xls"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="Q9pnIhD8"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="Gi3T+Xls"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="Q9pnIhD8" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9EAF33376A; Fri, 23 Jan 2026 06:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1769151190; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eEKVD7jaQE+LDv05PIHRGwJ26LSVOziITzWTXSPhpJk=; b=Gi3T+XlsDlqP0QQ71QXovXJrIlfjBGQeRqSBfbyQFpBKtEpHW5IgZGdCchVZs6aKCnB0TX JSei/5QvWeNHR1Rmv6rtBGVw6+Gk4QjAHZBNJHDaao9btn6eVFPC686TxQWfTeWou9isfh Ow8hOUG5opux48LL58BvidGqcCy+cDg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1769151190; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eEKVD7jaQE+LDv05PIHRGwJ26LSVOziITzWTXSPhpJk=; b=Q9pnIhD8MFvOie+v6Hqk7CLnQQHVeGsOmf7qdQlSNz504NBYXUHG1V0G9PhcDnxT9qPr2x YMLYiDqFZWzBygDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1769151190; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eEKVD7jaQE+LDv05PIHRGwJ26LSVOziITzWTXSPhpJk=; b=Gi3T+XlsDlqP0QQ71QXovXJrIlfjBGQeRqSBfbyQFpBKtEpHW5IgZGdCchVZs6aKCnB0TX JSei/5QvWeNHR1Rmv6rtBGVw6+Gk4QjAHZBNJHDaao9btn6eVFPC686TxQWfTeWou9isfh Ow8hOUG5opux48LL58BvidGqcCy+cDg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1769151190; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eEKVD7jaQE+LDv05PIHRGwJ26LSVOziITzWTXSPhpJk=; b=Q9pnIhD8MFvOie+v6Hqk7CLnQQHVeGsOmf7qdQlSNz504NBYXUHG1V0G9PhcDnxT9qPr2x YMLYiDqFZWzBygDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B1514139ED; Fri, 23 Jan 2026 06:53:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0DYFK9Uac2k4YgAAD6G6ig (envelope-from ); Fri, 23 Jan 2026 06:53:09 +0000 From: Vlastimil Babka Date: Fri, 23 Jan 2026 07:52:44 +0100 Subject: [PATCH v4 06/22] slab: add sheaves to most caches Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260123-sheaves-for-all-v4-6-041323d506f7@suse.cz> References: <20260123-sheaves-for-all-v4-0-041323d506f7@suse.cz> In-Reply-To: <20260123-sheaves-for-all-v4-0-041323d506f7@suse.cz> To: Harry Yoo , Petr Tesarik , Christoph Lameter , David Rientjes , Roman Gushchin Cc: Hao Li , Andrew Morton , Uladzislau Rezki , "Liam R. Howlett" , Suren Baghdasaryan , Sebastian Andrzej Siewior , Alexei Starovoitov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, bpf@vger.kernel.org, kasan-dev@googlegroups.com, Vlastimil Babka X-Mailer: b4 0.14.3 X-Spam-Score: -8.30 X-Spamd-Result: default: False [-8.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCPT_COUNT_TWELVE(0.00)[18]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_RATELIMIT(0.00)[to_ip_from(RLwn5r54y1cp81no5tmbbew5oc)]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[linux.dev,linux-foundation.org,gmail.com,oracle.com,google.com,linutronix.de,kernel.org,kvack.org,vger.kernel.org,lists.linux.dev,googlegroups.com,suse.cz]; MID_RHS_MATCH_FROM(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:mid,suse.cz:email,imap1.dmz-prg2.suse.org:helo,oracle.com:email] X-Spam-Level: X-Spam-Flag: NO In the first step to replace cpu (partial) slabs with sheaves, enable sheaves for almost all caches. Treat args->sheaf_capacity as a minimum, and calculate sheaf capacity with a formula that roughly follows the formula for number of objects in cpu partial slabs in set_cpu_partial(). This should achieve roughly similar contention on the barn spin lock as there's currently for node list_lock without sheaves, to make benchmarking results comparable. It can be further tuned later. Don't enable sheaves for bootstrap caches as that wouldn't work. In order to recognize them by SLAB_NO_OBJ_EXT, make sure the flag exists even for !CONFIG_SLAB_OBJ_EXT. This limitation will be lifted for kmalloc caches after the necessary bootstrapping changes. Also do not enable sheaves for SLAB_NOLEAKTRACE caches to avoid recursion with kmemleak tracking (thanks to Breno Leitao). Reviewed-by: Suren Baghdasaryan Reviewed-by: Harry Yoo Signed-off-by: Vlastimil Babka Reviewed-by: Hao Li Reviewed-by: Liam R. Howlett Tested-by: Breno Leitao Tested-by: Zhao Liu --- include/linux/slab.h | 6 ------ mm/slub.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++= ---- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 2482992248dc..2682ee57ec90 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -57,9 +57,7 @@ enum _slab_flag_bits { #endif _SLAB_OBJECT_POISON, _SLAB_CMPXCHG_DOUBLE, -#ifdef CONFIG_SLAB_OBJ_EXT _SLAB_NO_OBJ_EXT, -#endif _SLAB_FLAGS_LAST_BIT }; =20 @@ -238,11 +236,7 @@ enum _slab_flag_bits { #define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */ =20 /* Slab created using create_boot_cache */ -#ifdef CONFIG_SLAB_OBJ_EXT #define SLAB_NO_OBJ_EXT __SLAB_FLAG_BIT(_SLAB_NO_OBJ_EXT) -#else -#define SLAB_NO_OBJ_EXT __SLAB_FLAG_UNUSED -#endif =20 /* * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. diff --git a/mm/slub.c b/mm/slub.c index 9d86c0505dcd..594f5fac39b3 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -7880,6 +7880,53 @@ static void set_cpu_partial(struct kmem_cache *s) #endif } =20 +static unsigned int calculate_sheaf_capacity(struct kmem_cache *s, + struct kmem_cache_args *args) + +{ + unsigned int capacity; + size_t size; + + + if (IS_ENABLED(CONFIG_SLUB_TINY) || s->flags & SLAB_DEBUG_FLAGS) + return 0; + + /* + * Bootstrap caches can't have sheaves for now (SLAB_NO_OBJ_EXT). + * SLAB_NOLEAKTRACE caches (e.g., kmemleak's object_cache) must not + * have sheaves to avoid recursion when sheaf allocation triggers + * kmemleak tracking. + */ + if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE)) + return 0; + + /* + * For now we use roughly similar formula (divided by two as there are + * two percpu sheaves) as what was used for percpu partial slabs, which + * should result in similar lock contention (barn or list_lock) + */ + if (s->size >=3D PAGE_SIZE) + capacity =3D 4; + else if (s->size >=3D 1024) + capacity =3D 12; + else if (s->size >=3D 256) + capacity =3D 26; + else + capacity =3D 60; + + /* Increment capacity to make sheaf exactly a kmalloc size bucket */ + size =3D struct_size_t(struct slab_sheaf, objects, capacity); + size =3D kmalloc_size_roundup(size); + capacity =3D (size - struct_size_t(struct slab_sheaf, objects, 0)) / size= of(void *); + + /* + * Respect an explicit request for capacity that's typically motivated by + * expected maximum size of kmem_cache_prefill_sheaf() to not end up + * using low-performance oversize sheaves + */ + return max(capacity, args->sheaf_capacity); +} + /* * calculate_sizes() determines the order and the distribution of data wit= hin * a slab object. @@ -8014,6 +8061,10 @@ static int calculate_sizes(struct kmem_cache_args *a= rgs, struct kmem_cache *s) if (s->flags & SLAB_RECLAIM_ACCOUNT) s->allocflags |=3D __GFP_RECLAIMABLE; =20 + /* kmalloc caches need extra care to support sheaves */ + if (!is_kmalloc_cache(s)) + s->sheaf_capacity =3D calculate_sheaf_capacity(s, args); + /* * Determine the number of objects per slab */ @@ -8618,15 +8669,12 @@ int do_kmem_cache_create(struct kmem_cache *s, cons= t char *name, =20 set_cpu_partial(s); =20 - if (args->sheaf_capacity && !IS_ENABLED(CONFIG_SLUB_TINY) - && !(s->flags & SLAB_DEBUG_FLAGS)) { + if (s->sheaf_capacity) { s->cpu_sheaves =3D alloc_percpu(struct slub_percpu_sheaves); if (!s->cpu_sheaves) { err =3D -ENOMEM; goto out; } - // TODO: increase capacity to grow slab_sheaf up to next kmalloc size? - s->sheaf_capacity =3D args->sheaf_capacity; } =20 #ifdef CONFIG_NUMA --=20 2.52.0