mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] mm/slab: update the sheaf documentation in kmem_cache_args
@ 2026-11-25 19:35 Andreas Hindborg
  2026-11-25 19:35 ` [PATCH 1/3] mm/slab: update the documentation of sheaf_capacity Andreas Hindborg
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andreas Hindborg @ 2026-11-25 19:35 UTC (permalink / raw)
  To: Vlastimil Babka, Harry Yoo, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, Liam R. Howlett,
	Suren Baghdasaryan
  Cc: linux-mm, linux-kernel, Andreas Hindborg, stable+noautosel

This series is a few documentation updates pertaining to how and when
sheaves are enabled. I discovered the inconsistency handled by patch 1
while discussing the Rust abstractions for sheaves [1]. While working on
patch 1 , my robot assistant found the other two inconsistencies updated by
this series:

- Patch 1 documents sheaf_capacity as a minimum capacity, where zero
  selects the calculated capacity, and lists the cases where no sheaves are
  created.
- Patch 2 drops the statement that refilling a sheaf requires gfp flags
  that allow blocking.
- Patch 3 corrects the description of allocations that request a specific
  NUMA node.

The statement fixed by patch 3 has been stale since v6.18, the ones fixed
by patches 1 and 2 since v7.0.

The series only changes documentation.

[1] https://lore.kernel.org/r/8a73da1c-0167-4aa5-a62c-4190327685cd@kernel.org

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
Andreas Hindborg (3):
      mm/slab: update the documentation of sheaf_capacity
      mm/slab: document that sheaf refill does not require blocking
      mm/slab: document that local node allocations can use sheaves

 include/linux/slab.h | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
---
base-commit: 0b0985aeb9979c5fa5c3b872cecdf97ed4ed2b3e
change-id: 20261117-sheaf-doc-update-b680c43d0ddf

Best regards,
--  
Andreas Hindborg <a.hindborg@kernel.org>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] mm/slab: update the documentation of sheaf_capacity
  2026-11-25 19:35 [PATCH 0/3] mm/slab: update the sheaf documentation in kmem_cache_args Andreas Hindborg
@ 2026-11-25 19:35 ` Andreas Hindborg
  2026-11-25 19:35 ` [PATCH 2/3] mm/slab: document that sheaf refill does not require blocking Andreas Hindborg
  2026-11-25 19:35 ` [PATCH 3/3] mm/slab: document that local node allocations can use sheaves Andreas Hindborg
  2 siblings, 0 replies; 4+ messages in thread
From: Andreas Hindborg @ 2026-11-25 19:35 UTC (permalink / raw)
  To: Vlastimil Babka, Harry Yoo, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, Liam R. Howlett,
	Suren Baghdasaryan
  Cc: linux-mm, linux-kernel, Andreas Hindborg, stable+noautosel

The documentation of the sheaf_capacity member of struct kmem_cache_args
describes sheaves as an opt-in feature: a non-zero value enables sheaves of
the given capacity, and zero means that no sheaves are created.

This has not been the case since sheaves were added to most caches.
calculate_sheaf_capacity() now calculates a capacity from the object size
for all caches and returns the larger of that and the requested capacity.
The requested capacity is thus a minimum, and zero selects the calculated
capacity, as pointed out in [1].

Update the documentation to match. While at it, mention that a non-zero
value makes the cache unmergeable, that the requested capacity is also not
used when slab_tiny is enabled, and refer to the debugging parameter by its
current name, slab_debug.

The updated text refers to the slab_tiny boot parameter, which older
kernels do not have, so exclude the patch from stable autoselection.

Fixes: e47c897a2949 ("slab: add sheaves to most caches")
Cc: <stable+noautosel@kernel.org> # slab_tiny is not in older kernels
Link: https://lore.kernel.org/r/8a73da1c-0167-4aa5-a62c-4190327685cd@kernel.org [1]
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 include/linux/slab.h | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index ad645967a3ee..64daeb239f78 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -351,13 +351,12 @@ struct kmem_cache_args {
 	 */
 	void (*ctor)(void *);
 	/**
-	 * @sheaf_capacity: Enable sheaves of given capacity for the cache.
+	 * @sheaf_capacity: Minimum capacity of the sheaves of the cache.
 	 *
-	 * With a non-zero value, allocations from the cache go through caching
-	 * arrays called sheaves. Each cpu has a main sheaf that's always
-	 * present, and a spare sheaf that may be not present. When both become
-	 * empty, there's an attempt to replace an empty sheaf with a full sheaf
-	 * from the per-node barn.
+	 * Allocations from the cache go through caching arrays called sheaves.
+	 * Each cpu has a main sheaf that's always present, and a spare sheaf
+	 * that may be not present. When both become empty, there's an attempt
+	 * to replace an empty sheaf with a full sheaf from the per-node barn.
 	 *
 	 * When no full sheaf is available, and gfp flags allow blocking, a
 	 * sheaf is allocated and filled from slab(s) using bulk allocation.
@@ -375,10 +374,19 @@ struct kmem_cache_args {
 	 * Bulk allocation and free operations also try to use the cpu sheaves
 	 * and barn, but fallback to using slab pages directly.
 	 *
-	 * When slub_debug is enabled for the cache, the sheaf_capacity argument
-	 * is ignored.
+	 * The allocator selects a default capacity for the sheaves based on the
+	 * size of the objects in the cache, with larger objects giving a lower
+	 * capacity. With a non-zero value, the capacity is at least the given
+	 * value. Use this to match the expected maximum size passed to
+	 * kmem_cache_prefill_sheaf(), to avoid low-performance oversize
+	 * sheaves. A cache created with a non-zero value is not merged with
+	 * other caches.
 	 *
-	 * %0 means no sheaves will be created.
+	 * When slab_tiny is enabled, or when slab_debug is enabled for the
+	 * cache, no percpu sheaves are created and the requested capacity is
+	 * not used. A non-zero value still prevents merging of the cache.
+	 *
+	 * %0 means the calculated capacity is used.
 	 */
 	unsigned int sheaf_capacity;
 };

-- 
2.54.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] mm/slab: document that sheaf refill does not require blocking
  2026-11-25 19:35 [PATCH 0/3] mm/slab: update the sheaf documentation in kmem_cache_args Andreas Hindborg
  2026-11-25 19:35 ` [PATCH 1/3] mm/slab: update the documentation of sheaf_capacity Andreas Hindborg
@ 2026-11-25 19:35 ` Andreas Hindborg
  2026-11-25 19:35 ` [PATCH 3/3] mm/slab: document that local node allocations can use sheaves Andreas Hindborg
  2 siblings, 0 replies; 4+ messages in thread
From: Andreas Hindborg @ 2026-11-25 19:35 UTC (permalink / raw)
  To: Vlastimil Babka, Harry Yoo, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, Liam R. Howlett,
	Suren Baghdasaryan
  Cc: linux-mm, linux-kernel, Andreas Hindborg

The documentation of the sheaf_capacity member of struct kmem_cache_args
states that when no full sheaf is available, a sheaf is only allocated and
filled if the gfp flags allow blocking, and that the allocation otherwise
falls back to allocating a single object from a slab.

This has not been the case since commit fb1091febd66 ("mm/slab: allow sheaf
refill if blocking is not allowed"). __pcs_replace_empty_main() now refills
a sheaf whenever spinning is allowed. Only kmalloc_nolock() disallows
spinning, and it allocates from the kmalloc caches, so for caches created
with kmem_cache_create() the refill is attempted regardless of the gfp
flags.

Drop the condition from the documentation, and describe the fallback as
what happens when the sheaf cannot be allocated or filled.

Fixes: fb1091febd66 ("mm/slab: allow sheaf refill if blocking is not allowed")
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 include/linux/slab.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 64daeb239f78..8f484e1edcd2 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -358,10 +358,10 @@ struct kmem_cache_args {
 	 * that may be not present. When both become empty, there's an attempt
 	 * to replace an empty sheaf with a full sheaf from the per-node barn.
 	 *
-	 * When no full sheaf is available, and gfp flags allow blocking, a
-	 * sheaf is allocated and filled from slab(s) using bulk allocation.
-	 * Otherwise the allocation falls back to the normal operation
-	 * allocating a single object from a slab.
+	 * When no full sheaf is available, a sheaf is allocated and filled
+	 * from slab(s) using bulk allocation. If that fails, the allocation
+	 * falls back to the normal operation allocating a single object from
+	 * a slab.
 	 *
 	 * Analogically when freeing and both percpu sheaves are full, the barn
 	 * may replace it with an empty sheaf, unless it's over capacity. In

-- 
2.54.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] mm/slab: document that local node allocations can use sheaves
  2026-11-25 19:35 [PATCH 0/3] mm/slab: update the sheaf documentation in kmem_cache_args Andreas Hindborg
  2026-11-25 19:35 ` [PATCH 1/3] mm/slab: update the documentation of sheaf_capacity Andreas Hindborg
  2026-11-25 19:35 ` [PATCH 2/3] mm/slab: document that sheaf refill does not require blocking Andreas Hindborg
@ 2026-11-25 19:35 ` Andreas Hindborg
  2 siblings, 0 replies; 4+ messages in thread
From: Andreas Hindborg @ 2026-11-25 19:35 UTC (permalink / raw)
  To: Vlastimil Babka, Harry Yoo, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, Liam R. Howlett,
	Suren Baghdasaryan
  Cc: linux-mm, linux-kernel, Andreas Hindborg

The documentation of the sheaf_capacity member of struct kmem_cache_args
states that allocations via kmem_cache_alloc_node() with a node specified
other than NUMA_NO_NODE bypass the sheaves.

This has not been the case since commit 4ec1a08d2031 ("slab: allow NUMA
restricted allocations to use percpu sheaves"). alloc_from_pcs() only
bypasses the sheaves when the requested node is not the local node. A
request for the local node is served from the sheaves if the object found
there is from that node.

Update the documentation to match.

Fixes: 4ec1a08d2031 ("slab: allow NUMA restricted allocations to use percpu sheaves")
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 include/linux/slab.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 8f484e1edcd2..ae9f305db9ea 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -369,7 +369,9 @@ struct kmem_cache_args {
 	 *
 	 * The sheaves do not enforce NUMA placement of objects, so allocations
 	 * via kmem_cache_alloc_node() with a node specified other than
-	 * NUMA_NO_NODE will bypass them.
+	 * NUMA_NO_NODE or the local node will bypass them. When the local node
+	 * is specified, an object from the sheaves is used only if it is from
+	 * that node.
 	 *
 	 * Bulk allocation and free operations also try to use the cpu sheaves
 	 * and barn, but fallback to using slab pages directly.

-- 
2.54.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 19:35 [PATCH 0/3] mm/slab: update the sheaf documentation in kmem_cache_args Andreas Hindborg
2026-11-25 19:35 ` [PATCH 1/3] mm/slab: update the documentation of sheaf_capacity Andreas Hindborg
2026-11-25 19:35 ` [PATCH 2/3] mm/slab: document that sheaf refill does not require blocking Andreas Hindborg
2026-11-25 19:35 ` [PATCH 3/3] mm/slab: document that local node allocations can use sheaves Andreas Hindborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®