[PATCH v5 00/12] rust: xarray: add entry API with preloading
From: Andreas Hindborg
Date: Wed Sep 02 2026 - 11:15:29 EST
This patch series is a mashup of cleanups, bugfixes and feature additions for
the Rust XArray abstractions.
- Patch 1 starts by fixing minor formatting issues and bringing use
statements up to date with the new coding guidelines.
- Patch 2 add some minor convenience functionality.
- Patch 3 moves two static C helper functions to the xarray header so
that they can be called from Rust helpers.
- Patch 4 adds an abstraction for the C `xa_state` structure and uses
it in `xarray::Guard::load`, removing an unnecessary rcu lock. This
is a prerequisite for all the subsequent patches.
- Patch 5 is a simplifying refactor of `xarray::Guard::load`.
- Patch 6 adds two new methods for finding items with keys that are larger
than a given integer.
- Patch 7 adds an entry API.
- Patch 8-9 adds support for object caches based on sheafs.
- Patch 10 enables sheafs for the xarray kmem_cache.
- Patch 11 adds preloading to the new entry API.
- Patch 12 documents that `Guard::store` may temporarily drop the
xarray lock.
The feature additions in this series are dependencies for the rust null
block driver, most of which is still downstream.
Best regards,
Andreas
Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
Changes in v5:
- Rebase on v7.2.
- Update the cover letter.
- Adapt the entry API to the new lifetime bounds on `ForeignOwnable::Borrowed` and `ForeignOwnable::BorrowedMut`.
- Squash the `xas_load` conversion into the `XArrayState` patch (Tamir).
- Replace the `GuardRef` trait with a `Deref` bound on `XArrayState` (Tamir).
- Filter internal `XA_ZERO_ENTRY` entries in `XArrayState::load` and `load_next` (Sashiko).
- Add a new patch moving `xas_result()` and `xa_zero_to_null()` to the xarray header instead of duplicating them in the Rust helpers (Tamir).
- Require an exclusive guard reference for `XArrayState::insert`.
- Add `XArrayState::replace` and `XArrayState::restart_at` helpers and use them in the entry code (Daniel).
- Clear `XA_FREE_MARK` when inserting through the entry API (Sashiko).
- Reset the `xa_state` cursor before retrying a failed store in `XArrayState::insert` (Sashiko).
- Check for NULL before running the object initializer in `Sheaf::alloc` (Sashiko).
- Set cache object alignment to the alignment of `T` in `KMemCacheHandle::new` (Sashiko).
- Restrict the `SBox` raw pointer round trip to static caches (Sashiko).
- Implement `Send` and `Sync` for the sheaf types and `Send` for `XArrayNode` where sound (Sashiko).
- Add `#[repr(transparent)]` to `XArrayNode` (Sashiko).
- Document that dropping the last `KMemCacheHandle` reference may sleep (Sashiko).
- Add a new patch documenting that `Guard::store` may temporarily drop the lock (Sashiko).
- Import `kernel::fmt` in the `StoreError` `Debug` implementation (Tamir).
- Add the `__rust_helper` attribute to the new C helpers (Sashiko).
- Add `#[inline]` to small forwarding functions in the xarray and sheaf abstractions (Sashiko).
- Fix the SAFETY comment in `OccupiedEntry::insert` (Sashiko).
- Fix the `KMemCacheInit::init` documentation (Sashiko).
- Update the `Guard::load` simplification commit message to note it establishes the untyped pointer style for the rest of the series (Tamir).
- Remove a stray blank line in `Guard::get_mut` (Tamir).
- Expand the entry API commit message to describe and motivate the added API surface (Tamir).
- Collect Daniel's Reviewed-by tags. The tag for the `XArrayState` patch is dropped due to substantial rework of the patch.
- Link to v4: https://msgid.link/20260604-xarray-entry-send-v4-0-965f6028790e@xxxxxxxxxx
Changes in v4:
- Rebase on v7.1-rc2.
- Drop `contains_index` patch (Tamir).
- Use `kernel::fmt::*` rather than `core::fmt::*` (Tamir).
- Add `into_guard` to `VacantEntry` and `OccupiedEntry` for releasing the entry borrow while keeping the lock guard (Alice).
- Refactor `XArrayState` over a new `GuardRef` trait to support both `&Guard` and `&mut Guard` borrows.
- Improve the `XArrayState` type invariant and update SAFETY comments.
- Document the `(size_t)XAS_RESTART` cast in `bindings_helper.h` (Tamir).
- Use GFP_ATOMIC when allocating under spinlock in the examples.
- Link to v3: https://msgid.link/20260209-xarray-entry-send-v3-0-f777c65b8ae2@xxxxxxxxxx
Changes in v3:
- Fix a misconception about sheaf availablility under `CONFIG_SLUB_TINY` and `CONFIG_SLUB_DEBUG`.
- Add missing patch to enable sheaf support in xarray kmem_cache.
- Update commit messages for last 3 patches.
- Link to v2: https://msgid.link/20260206-xarray-entry-send-v2-0-91c41673fd30@xxxxxxxxxx
Changes in v2:
- Rebase on v6.19-rc8.
- Update the cover letter.
- Implement preloading with sheafs.
- Investigate generating RUST_CONST_HELPER_XAS_RESTART as pointer -> Not possible.
- Correct wording of commit message for patch "rust: xarray: use `xas_load` instead of `xa_load` in `Guard::load`".
- Correct wording of commit message for patch "rust: xarray: add `find_next` and `find_next_mut`".
- Remove last patch (lockdep static key fix) from series, to be sent separately.
- Expand note on why store to occupied slot cannot fail.
- Change signature of `OccupiedEntry::swap` to match core::mem::swap.
- Move // NOTEs about storing NULL closer to relevant checks.
- Move `insert_internal` to `XArrayState`.
- Share logic between `find_next` and `find_next_entry`.
- Rename `XArray::get_entry` to `XArray::entry`.
- Make `load_next` a method on `XArrayState`.
- Move load logic to `XArrayState`.
- Use `PhantomData` to capture lifetime of `Guard` for `XArrayState`.
- Link to v1: https://lore.kernel.org/r/20251203-xarray-entry-send-v1-0-9e5ffd5e3cf0@xxxxxxxxxx
To: Tamir Duberstein <tamird@xxxxxxxxxx>
To: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
To: Miguel Ojeda <ojeda@xxxxxxxxxx>
To: Boqun Feng <boqun@xxxxxxxxxx>
To: Gary Guo <gary@xxxxxxxxxxx>
To: Björn Roy Baron <bjorn3_gh@xxxxxxxxxxxxxx>
To: Benno Lossin <lossin@xxxxxxxxxx>
To: Alice Ryhl <aliceryhl@xxxxxxxxxx>
To: Trevor Gross <tmgross@xxxxxxxxx>
To: Danilo Krummrich <dakr@xxxxxxxxxx>
To: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
To: Alexandre Courbot <acourbot@xxxxxxxxxx>
To: Onur Özkan <work@xxxxxxxxxxxxx>
To: Matthew Wilcox <willy@xxxxxxxxxxxxx>
To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
To: Lorenzo Stoakes <ljs@xxxxxxxxxx>
To: "Liam R. Howlett" <liam@xxxxxxxxxxxxx>
To: Vlastimil Babka <vbabka@xxxxxxxxxx>
To: Harry Yoo <harry@xxxxxxxxxx>
To: Hao Li <hao.li@xxxxxxxxx>
To: Christoph Lameter <cl@xxxxxxxxxx>
To: David Rientjes <rientjes@xxxxxxxxxx>
To: Roman Gushchin <roman.gushchin@xxxxxxxxx>
Cc: rust-for-linux@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Cc: linux-mm@xxxxxxxxx
---
Andreas Hindborg (12):
rust: xarray: minor formatting fixes
rust: xarray: add debug format for `StoreError`
xarray: move xas_result() and xa_zero_to_null() to the header
rust: xarray: add `XArrayState`
rust: xarray: simplify `Guard::load`
rust: xarray: add `find_next` and `find_next_mut`
rust: xarray: add entry API
rust: mm: add abstractions for allocating from a `sheaf`
rust: mm: sheaf: allow use of C initialized static caches
xarray, radix-tree: enable sheaf support for kmem_cache
rust: xarray: add preload API
rust: xarray: document `Guard` lock drop semantics
MAINTAINERS | 1 +
include/linux/radix-tree.h | 3 +
include/linux/xarray.h | 26 ++
lib/radix-tree.c | 19 +-
lib/xarray.c | 12 -
mm/slub.c | 4 +
rust/bindings/bindings_helper.h | 11 +
rust/helpers/xarray.c | 15 +
rust/kernel/mm.rs | 1 +
rust/kernel/mm/sheaf.rs | 769 ++++++++++++++++++++++++++++++++++++++++
rust/kernel/xarray.rs | 599 +++++++++++++++++++++++++++++--
rust/kernel/xarray/entry.rs | 373 +++++++++++++++++++
12 files changed, 1782 insertions(+), 51 deletions(-)
---
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20251203-xarray-entry-send-00230f0744e6
Best regards,
--
Andreas Hindborg <a.hindborg@xxxxxxxxxx>