[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <874intpmz1.fsf@t14s.mail-host-address-is-not-set>
Date: Fri, 06 Feb 2026 22:43:14 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Matthew Wilcox (Oracle)" <willy@...radead.org>, Tamir Duberstein
<tamird@...il.com>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor
<alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo
<gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, Benno
Lossin <lossin@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>, Trevor
Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, Lorenzo
Stoakes <lorenzo.stoakes@...cle.com>, "Liam R. Howlett"
<Liam.Howlett@...cle.com>, Vlastimil Babka <vbabka@...e.cz>, Andrew Morton
<akpm@...ux-foundation.org>, Christoph Lameter <cl@...two.org>, David
Rientjes <rientjes@...gle.com>, Roman Gushchin <roman.gushchin@...ux.dev>,
Harry Yoo <harry.yoo@...cle.com>
Cc: Daniel Gomez <da.gomez@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v2 11/11] rust: xarray: add preload API
Andreas Hindborg <a.hindborg@...nel.org> writes:
> Add a preload API that allows preallocating memory for XArray
> insertions. This enables insertions to proceed without allocation
> failures in contexts where memory allocation is not desirable, such as
> in atomic contexts or where reliability is critical.
>
> The API includes:
>
> - `XArrayPreloadBuffer` for managing a pool of preallocated nodes.
> - `XArrayPreloadNode` representing a single preallocated node.
> - Integration with the entry API, allowing `VacantEntry::insert` and
> `VacantEntry::insert_entry` to accept an optional preload buffer.
> - A new `Guard::insert_entry` method for inserting with preload support.
>
> The implementation uses a circular buffer to efficiently manage
> preallocated nodes. When an insertion would fail due to ENOMEM, the
> XArray state API automatically consumes a preallocated node from the
> buffer if available.
>
> Export `radix_tree_node_ctor` from C to enable Rust code to work with the
> radix tree node cache.
>
> Cc: "Liam R. Howlett" <Liam.Howlett@...cle.com>
> Cc: "Matthew Wilcox (Oracle)" <willy@...radead.org>
> Signed-off-by: Andreas Hindborg <a.hindborg@...nel.org>
I somehow managed to not include this last bit of detail:
commit 09bdfa18f6f879eb42df2e032ad5224eed29eb25
Author: Andreas Hindborg <a.hindborg@...nel.org>
Date: Fri Feb 6 22:38:09 2026 +0100
radix-tree: enable sheaf suppport for kmem_cache
The rust null block driver plans to rely on preloading xarray nodes from the
radix_tree_node_cachep kmem_cache.
Signed-off-by: Andreas Hindborg <a.hindborg@...nel.org>
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index b642f2775e89c..ddd67ce672f5c 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1599,10 +1599,16 @@ void __init radix_tree_init(void)
BUILD_BUG_ON(RADIX_TREE_MAX_TAGS + __GFP_BITS_SHIFT > 32);
BUILD_BUG_ON(ROOT_IS_IDR & ~GFP_ZONEMASK);
BUILD_BUG_ON(XA_CHUNK_SIZE > 255);
- radix_tree_node_cachep = kmem_cache_create("radix_tree_node",
- sizeof(struct radix_tree_node), 0,
- SLAB_PANIC | SLAB_RECLAIM_ACCOUNT,
- radix_tree_node_ctor);
+
+ struct kmem_cache_args args = {
+ .ctor = radix_tree_node_ctor,
+ .sheaf_capacity = 64,
+ };
+
+ radix_tree_node_cachep = kmem_cache_create(
+ "radix_tree_node", sizeof(struct radix_tree_node), &args,
+ SLAB_PANIC | SLAB_RECLAIM_ACCOUNT);
+
ret = cpuhp_setup_state_nocalls(CPUHP_RADIX_DEAD, "lib/radix:dead",
NULL, radix_tree_cpu_dead);
WARN_ON(ret < 0);
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists