From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 453D83FD94E for ; Fri, 15 May 2026 16:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862284; cv=none; b=GDbUXd//5PV4FBwaguidl/+oYMhzYASmoHqkYUJL2pHFylszJ9r/7/b81QcCOhiItVAz7TZ1PW7lG9Nkydlxxk3H0FihO51NEh6F3hRAKqpyaLqlOiR0KgBa3/BQbIy+6ssWeVdZs7IVg0ek+xXcjtUhqkJzZ/UCnSlfON6PvkM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862284; c=relaxed/simple; bh=mY8sogTT47E6WZnzv6R2mVXWjFcYPBLJkIVpwMtmkQE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GloqoAF2NLzYDUkZh8rslLxXFNmla3SusU8HoxohgvmCIJ3TBypSMaU4aAjndq5kvhCXpabaa4yX+llR41nP8LLaYqFfEs5R+RtiSgXAPYvRvst8wzUknhZjVwtf9jleTD6eGFHGnQ9CehMiYVnEKRXXzVt2fJ5W6jBece2SKy0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wx/YP4Wt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wx/YP4Wt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 218F8C2BCB0; Fri, 15 May 2026 16:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778862284; bh=mY8sogTT47E6WZnzv6R2mVXWjFcYPBLJkIVpwMtmkQE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Wx/YP4WtDdwRnvDlY399gmxLFZiDLoRGb/plBPW4wK5meiZ3U2FmWXf/1l302m3yl 41NDa29HVdmjV0DrZqnijBjdtLPkddwjXNeQeVcHYOc6HmNrWJYohoBELzDNfijtN6 zi8d/I27IaLcPG8sDhGZK4AvsKb1MtzPErOn67V8LKUQYkebeMWfISSkeaQ6/0SMMe wKIXJTA0vs6EqslcxBh0grtD3olCa1sMm5dDNcP1u3tRDiIJoVanqLWBZWwGS1DZEa dkzwTyupqSuiZ859K4uG90/zJ61fEVjO0ZGrSwwSklJa+cuW5ckXarf7pYApvO8baP W+MzbE81x+YIA== From: "Harry Yoo (Oracle)" Date: Sat, 16 May 2026 01:24:26 +0900 Subject: [PATCH RFC 2/8] mm/slab: change sheaf_capacity type to unsigned short 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: 7bit Message-Id: <20260516-sheaves-tuning-v1-2-221aa3e1d829@kernel.org> References: <20260516-sheaves-tuning-v1-0-221aa3e1d829@kernel.org> In-Reply-To: <20260516-sheaves-tuning-v1-0-221aa3e1d829@kernel.org> To: Vlastimil Babka , Andrew Morton , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan , "Liam R. Howlett" X-Mailer: b4 0.16-dev Change struct kmem_cache.sheaf_capacity and the matching kmem_cache_args field from unsigned int to unsigned short, so that we can add a new field later without growing the struct size. unsigned short is a reasonable size for any realistic configurations. Signed-off-by: Harry Yoo (Oracle) --- include/linux/slab.h | 8 ++++---- mm/slab.h | 2 +- mm/slub.c | 34 +++++++++++++++++----------------- tools/include/linux/slab.h | 14 +++++++------- tools/testing/shared/linux.c | 4 ++-- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 2b5ab488e96b..6f023f04763a 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -371,7 +371,7 @@ struct kmem_cache_args { * * %0 means no sheaves will be created. */ - unsigned int sheaf_capacity; + unsigned short sheaf_capacity; }; struct kmem_cache *__kmem_cache_create_args(const char *name, @@ -828,10 +828,10 @@ void *kmem_cache_alloc_node_noprof(struct kmem_cache *s, gfp_t flags, #define kmem_cache_alloc_node(...) alloc_hooks(kmem_cache_alloc_node_noprof(__VA_ARGS__)) struct slab_sheaf * -kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size); +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned short size); int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, - struct slab_sheaf **sheafp, unsigned int size); + struct slab_sheaf **sheafp, unsigned short size); void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, struct slab_sheaf *sheaf); @@ -841,7 +841,7 @@ void *kmem_cache_alloc_from_sheaf_noprof(struct kmem_cache *cachep, gfp_t gfp, #define kmem_cache_alloc_from_sheaf(...) \ alloc_hooks(kmem_cache_alloc_from_sheaf_noprof(__VA_ARGS__)) -unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf); +unsigned short kmem_cache_sheaf_size(struct slab_sheaf *sheaf); /* * These macros allow declaring a kmem_buckets * parameter alongside size, which diff --git a/mm/slab.h b/mm/slab.h index bf2f87acf5e3..dfbe73011cb8 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -204,7 +204,7 @@ struct kmem_cache { unsigned int object_size; /* Object size without metadata */ struct reciprocal_value reciprocal_size; unsigned int offset; /* Free pointer offset */ - unsigned int sheaf_capacity; + unsigned short sheaf_capacity; struct kmem_cache_order_objects oo; /* Allocation and freeing of slabs */ diff --git a/mm/slub.c b/mm/slub.c index 75281eb802de..a1974523bba9 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -418,11 +418,11 @@ struct slab_sheaf { struct list_head barn_list; /* only used for prefilled sheafs */ struct { - unsigned int capacity; + unsigned short capacity; bool pfmemalloc; }; }; - unsigned int size; + unsigned short size; int node; /* only used for rcu_sheaf */ void *objects[]; }; @@ -2756,7 +2756,7 @@ static inline void *setup_object(struct kmem_cache *s, void *object) } static struct slab_sheaf *__alloc_empty_sheaf(struct kmem_cache *s, gfp_t gfp, - unsigned int capacity) + unsigned short capacity) { struct slab_sheaf *sheaf; size_t sheaf_size; @@ -2854,10 +2854,10 @@ static void __kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p); * * Returns how many objects are remaining to be flushed */ -static unsigned int __sheaf_flush_main_batch(struct kmem_cache *s) +static unsigned short __sheaf_flush_main_batch(struct kmem_cache *s) { struct slub_percpu_sheaves *pcs; - unsigned int batch, remaining; + unsigned short batch, remaining; void *objects[PCS_BATCH_MAX]; struct slab_sheaf *sheaf; @@ -2884,7 +2884,7 @@ static unsigned int __sheaf_flush_main_batch(struct kmem_cache *s) static void sheaf_flush_main(struct kmem_cache *s) { - unsigned int remaining; + unsigned short remaining; do { local_lock(&s->cpu_sheaves->lock); @@ -2899,7 +2899,7 @@ static void sheaf_flush_main(struct kmem_cache *s) */ static bool sheaf_try_flush_main(struct kmem_cache *s) { - unsigned int remaining; + unsigned short remaining; bool ret = false; do { @@ -4849,7 +4849,7 @@ unsigned int alloc_from_pcs_bulk(struct kmem_cache *s, gfp_t gfp, size_t size, do_alloc: main = pcs->main; - batch = min(size, main->size); + batch = min_t(size_t, size, main->size); main->size -= batch; memcpy(p, main->objects + main->size, batch * sizeof(void *)); @@ -5004,7 +5004,7 @@ static int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, * return NULL if sheaf allocation or prefilling failed */ struct slab_sheaf * -kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size) +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned short size) { struct slub_percpu_sheaves *pcs; struct slab_sheaf *sheaf = NULL; @@ -5146,7 +5146,7 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, * In practice we always refill to full sheaf's capacity. */ int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, - struct slab_sheaf **sheafp, unsigned int size) + struct slab_sheaf **sheafp, unsigned short size) { struct slab_sheaf *sheaf; @@ -5225,7 +5225,7 @@ kmem_cache_alloc_from_sheaf_noprof(struct kmem_cache *s, gfp_t gfp, return ret; } -unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf) +unsigned short kmem_cache_sheaf_size(struct slab_sheaf *sheaf) { return sheaf->size; } @@ -6172,7 +6172,7 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p) do_free: main = pcs->main; - batch = min(size, s->sheaf_capacity - main->size); + batch = min_t(size_t, size, s->sheaf_capacity - main->size); memcpy(main->objects + main->size, p, batch * sizeof(void *)); main->size += batch; @@ -7759,11 +7759,11 @@ static int init_kmem_cache_nodes(struct kmem_cache *s) return 1; } -static unsigned int calculate_sheaf_capacity(struct kmem_cache *s, - struct kmem_cache_args *args) +static unsigned short calculate_sheaf_capacity(struct kmem_cache *s, + struct kmem_cache_args *args) { - unsigned int capacity; + unsigned short capacity; size_t size; @@ -8466,7 +8466,7 @@ static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache) static void __init bootstrap_cache_sheaves(struct kmem_cache *s) { struct kmem_cache_args empty_args = {}; - unsigned int capacity; + unsigned short capacity; bool failed = false; int node, cpu; @@ -9091,7 +9091,7 @@ SLAB_ATTR_RO(order); static ssize_t sheaf_capacity_show(struct kmem_cache *s, char *buf) { - return sysfs_emit(buf, "%u\n", s->sheaf_capacity); + return sysfs_emit(buf, "%hu\n", s->sheaf_capacity); } SLAB_ATTR_RO(sheaf_capacity); diff --git a/tools/include/linux/slab.h b/tools/include/linux/slab.h index 6d8e9413d5a4..76d0b9da6cfe 100644 --- a/tools/include/linux/slab.h +++ b/tools/include/linux/slab.h @@ -47,7 +47,7 @@ struct kmem_cache { pthread_mutex_t lock; unsigned int size; unsigned int align; - unsigned int sheaf_capacity; + unsigned short sheaf_capacity; int nr_objs; void *objs; void (*ctor)(void *); @@ -70,7 +70,7 @@ struct kmem_cache_args { /** * @sheaf_capacity: The maximum size of the sheaf. */ - unsigned int sheaf_capacity; + unsigned short sheaf_capacity; /** * @useroffset: Usercopy region offset. * @@ -127,10 +127,10 @@ struct slab_sheaf { union { struct list_head barn_list; /* only used for prefilled sheafs */ - unsigned int capacity; + unsigned short capacity; }; struct kmem_cache *cache; - unsigned int size; + unsigned short size; int node; /* only used for rcu_sheaf */ void *objects[]; }; @@ -186,7 +186,7 @@ void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t size, void **list); int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, void **list); struct slab_sheaf * -kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size); +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned short size); void * kmem_cache_alloc_from_sheaf(struct kmem_cache *s, gfp_t gfp, @@ -195,9 +195,9 @@ kmem_cache_alloc_from_sheaf(struct kmem_cache *s, gfp_t gfp, void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, struct slab_sheaf *sheaf); int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, - struct slab_sheaf **sheafp, unsigned int size); + struct slab_sheaf **sheafp, unsigned short size); -static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf) +static inline unsigned short kmem_cache_sheaf_size(struct slab_sheaf *sheaf) { return sheaf->size; } diff --git a/tools/testing/shared/linux.c b/tools/testing/shared/linux.c index 8c7257155958..2da3a6617d87 100644 --- a/tools/testing/shared/linux.c +++ b/tools/testing/shared/linux.c @@ -252,7 +252,7 @@ __kmem_cache_create_args(const char *name, unsigned int size, } struct slab_sheaf * -kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size) +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned short size) { struct slab_sheaf *sheaf; unsigned int capacity; @@ -281,7 +281,7 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size) } int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, - struct slab_sheaf **sheafp, unsigned int size) + struct slab_sheaf **sheafp, unsigned short size) { struct slab_sheaf *sheaf = *sheafp; int refill; -- 2.43.0