Skip to content

rust: xarray: add entry API with preloading

Andreas Hindborg linux-fsdevel linux-mm lkml rust-for-linux 6 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected] change-id 20251203-xarray-entry-send-00230f0744e6

Versions newest first

  1. v6 Latest12 patches 7 repliesApplied
  2. v512 patches 4 repliesSuperseded
  3. v411 patches 21 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v312 patches47 repliesSuperseded
v211 patches1 replySuperseded
v110 patches43 repliesSuperseded

Changes in v6 from the cover letter

- Rebase on v7.4-rc2.
- Assert pointer alignment when inserting through the entry API (Sashiko).
- Correct the documentation of the sheaf capacity: the requested capacity is a minimum, and requesting a larger sheaf yields an oversize sheaf rather than a warning (Vlastimil, Sashiko).
- Describe static and dynamic caches by whether they are destroyed, rather than by the language creating them, in the sheaf documentation and commit message (Vlastimil).
- Document that dropping a Sheaf never destroys its cache (Sashiko).
- Document the reference counting done when allocating from a dynamic cache (Sashiko).
- Merge the two identical Sheaf::alloc implementations.
- Add missing #[inline] annotations to small forwarding functions (Sashiko).
- Move the trailing empty comment to the last item of the import list and mention the crate to kernel change in the commit message (Sashiko).
- Remove the drop call from the Entry::is_occupied example until Drop is implemented for XArrayState, to keep each patch clippy clean.
- Link to v5: https://msgid.link/[email protected]

Patches in v6 Applied

#Subject and filesSizeRepliesApplied
1/12rust: xarray: minor formatting fixesrust/kernel/xarray.rs+21 -51 reply
2/12rust: xarray: add debug format for `StoreError`rust/kernel/xarray.rs+10 -01 reply
3/12xarray: move xas_result() and xa_zero_to_null() to the headerinclude/linux/xarray.h lib/xarray.c+26 -121 reply
4/12rust: xarray: add `XArrayState`rust/bindings/bindings_helper.h rust/helpers/xarray.c rust/kernel/xarray.rs+82 -50 replies
5/12rust: xarray: simplify `Guard::load`rust/kernel/xarray.rs+11 -140 replies
6/12rust: xarray: add `find_next` and `find_next_mut`rust/kernel/xarray.rs+104 -00 replies
7/12rust: xarray: add entry APIMAINTAINERS rust/bindings/bindings_helper.h rust/helpers/xarray.c +2 more+556 -40 replies
8/12rust: mm: add abstractions for allocating from a `sheaf`rust/kernel/mm.rs rust/kernel/mm/sheaf.rs+484 -02 replies
9/12rust: mm: sheaf: allow use of C initialized static cachesmm/slub.c rust/kernel/mm/sheaf.rs+342 -590 replies
10/12xarray, radix-tree: enable sheaf support for kmem_cachelib/radix-tree.c+10 -40 replies
11/12rust: xarray: add preload APIinclude/linux/radix-tree.h lib/radix-tree.c rust/bindings/bindings_helper.h +2 more+216 -370 replies
12/12rust: xarray: document `Guard` lock drop semanticsrust/kernel/xarray.rs+21 -10 replies

Reviews trailers per patch

6 of 12 patches have a Reviewed-by or Acked-by.

PatchVlastimil Babka (SUSE)Daniel AlmeidaGary GuoDaniel GomezTamir DubersteinLiam R. HowlettMukesh Kumar Chaurasiya (IBM)Philipp Stanner
1/12R-b R-b R-b R-b A-b A-b R-b
2/12R-b R-b R-b A-b A-b
3/12R-b
4/12
5/12R-b
6/12
7/12
8/12A-b
9/12A-b
10/12
11/12
12/12

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 8 reviewers.

Read the v6 thread

Cover letter [PATCH v6 00/12] rust: xarray: add entry API with preloading

This patch series is a mashup of cleanups 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 adds 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.

- Patches 8-9 add support for sheaf-based object caches.

- Patch 10 enables sheaf support 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

---
Changes in v6:
- Rebase on v7.4-rc2.
- Assert pointer alignment when inserting through the entry API (Sashiko).
- Correct the documentation of the sheaf capacity: the requested capacity is a minimum, and requesting a larger sheaf yields an oversize sheaf rather than a warning (Vlastimil, Sashiko).
- Describe static and dynamic caches by whether they are destroyed, rather than by the language creating them, in the sheaf documentation and commit message (Vlastimil).
- Document that dropping a Sheaf never destroys its cache (Sashiko).
- Document the reference counting done when allocating from a dynamic cache (Sashiko).
- Merge the two identical Sheaf::alloc implementations.
- Add missing #[inline] annotations to small forwarding functions (Sashiko).
- Move the trailing empty comment to the last item of the import list and mention the crate to kernel change in the commit message (Sashiko).
- Remove the drop call from the Entry::is_occupied example until Drop is implemented for XArrayState, to keep each patch clippy clean.
- Link to v5: https://msgid.link/[email protected]

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/[email protected]

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/[email protected]

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/[email protected]

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/[email protected]

To: Tamir Duberstein <[email protected]>
To: Andreas Hindborg <[email protected]>
To: Miguel Ojeda <[email protected]>
To: Boqun Feng <[email protected]>
To: Gary Guo <[email protected]>
To: Björn Roy Baron <[email protected]>
To: Benno Lossin <[email protected]>
To: Alice Ryhl <[email protected]>
To: Trevor Gross <[email protected]>
To: Danilo Krummrich <[email protected]>
To: Daniel Almeida <[email protected]>
To: Alexandre Courbot <[email protected]>
To: Onur Özkan <[email protected]>
To: Matthew Wilcox <[email protected]>
To: Andrew Morton <[email protected]>
To: Lorenzo Stoakes <[email protected]>
To: "Liam R. Howlett" <[email protected]>
To: Vlastimil Babka <[email protected]>
To: Harry Yoo <[email protected]>
To: Hao Li <[email protected]>
To: Christoph Lameter <[email protected]>
To: David Rientjes <[email protected]>
To: Roman Gushchin <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
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         | 762 ++++++++++++++++++++++++++++++++++++++++
 rust/kernel/xarray.rs           | 605 +++++++++++++++++++++++++++++--
 rust/kernel/xarray/entry.rs     | 381 ++++++++++++++++++++
 12 files changed, 1791 insertions(+), 49 deletions(-)

---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20251203-xarray-entry-send-00230f0744e6

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>