Skip to content

Allocation APIs

Wedson Almeida Filho lkml rust-for-linux 3 versions – Applied

Status from this message: Applied to `rust-next` -- thanks everyone!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest10 patches 20 repliesApplied
  2. v210 patches 7 repliesSuperseded
  3. v110 patches 19 repliesSuperseded

Changes in v3 from the cover letter

- Rebased on top of the latest rust-next branch.
- Updated krealloc_aligned to use Flags instead of bindings::gfp_t.
- Added __GFP_ZERO to flags, as part of the previous change.
- Avoiding temporary stack value in Box::new_uninit.
- Implement Box::new using Box::new_uninit (so only one of them actually allocates).
- Added examples/tests to VecExt methods.
- Fixed bug in length in extend_from_slice
- Link to v2: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/10rust: kernel: move `allocator` module under `alloc`rust/kernel/alloc.rs rust/kernel/alloc/allocator.rs rust/kernel/lib.rs+8 -30 replies
2/10rust: alloc: introduce the `VecExt` traitrust/kernel/alloc.rs rust/kernel/alloc/vec_ext.rs rust/kernel/lib.rs +1 more+52 -00 replies
3/10kbuild: use the upstream `alloc` craterust/Makefile rust/kernel/str.rs scripts/generate_rust_analyzer.py+5 -140 replies
4/10rust: alloc: remove our fork of the `alloc` craterust/alloc/README.md rust/alloc/alloc.rs rust/alloc/boxed.rs +12 more+0 -98140 replies
5/10rust: alloc: introduce allocation flagsrust/bindings/bindings_helper.h rust/kernel/alloc.rs rust/kernel/alloc/allocator.rs +1 more+71 -120 replies
6/10rust: alloc: introduce the `BoxExt` traitrust/kernel/alloc.rs rust/kernel/alloc/allocator.rs rust/kernel/alloc/box_ext.rs +3 more+72 -93 replies
7/10rust: alloc: update `VecExt` to take allocation flagsrust/kernel/alloc/vec_ext.rs rust/kernel/error.rs rust/kernel/lib.rs +3 more+152 -341 reply
8/10rust: sync: update `Arc` and `UniqueArc` to take allocation flagsrust/kernel/init.rs rust/kernel/sync/arc.rs samples/rust/rust_print.rs+18 -180 replies
9/10rust: init: update `init` module to take allocation flagsrust/kernel/init.rs rust/kernel/sync/arc.rs rust/kernel/sync/condvar.rs +3 more+50 -410 replies
10/10rust: kernel: remove usage of `allocator_api` unstable featurerust/kernel/alloc.rs rust/kernel/alloc/box_ext.rs rust/kernel/alloc/vec_ext.rs +6 more+14 -150 replies

Reviews trailers per patch

9 of 10 patches have a Reviewed-by or Acked-by.

PatchBenno LossinBoqun Feng
1/10R-b
2/10R-b
3/10
4/10R-b
5/10R-b
6/10R-b R-b
7/10R-b R-b
8/10R-b
9/10R-b
10/10R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/10] Allocation APIs

From: Wedson Almeida Filho <[email protected]>

Revamp how we use the alloc crate.

We currently have a fork of the crate with changes to Vec; other changes have been upstreamed (to the Rust project). This series removes the fork and exposes all the functionality as extension traits.

Additionally, it also introduces allocation flag parameters to all functions that may result in allocations (e.g., Box::new, Arc::new, Vec::push, etc.) without the try_ prefix -- the names are available because we build alloc with no_global_oom_handling.

Lastly, the series also removes our reliance on the allocator_api unstable feature.

Long term, we still want to make such functionality available in upstream Rust, but this allows us to make progress now and reduces our maintainance burden.

In summary:
1. Removes alloc fork
2. Removes use of allocator_api unstable feature
3. Introduces flags (e.g., GFP_KERNEL, GFP_ATOMIC) when allocating

---

Changes in v3:
- Rebased on top of the latest rust-next branch.
- Updated krealloc_aligned to use Flags instead of bindings::gfp_t.
- Added __GFP_ZERO to flags, as part of the previous change.
- Avoiding temporary stack value in Box::new_uninit.
- Implement Box::new using Box::new_uninit (so only one of them actually allocates).
- Added examples/tests to VecExt methods.
- Fixed bug in length in extend_from_slice
- Link to v2: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t

Changes in v2:
- Updated description of alloc crate.
- Renamed vecext and boxext modules to vec_ext and box_ext.
- Added derive directive to AllocError.
- Updated safety comment in BoxExt::new.
- Updated VecExt::push and VecExt::extend_from_slice to use
spare_capacity_mut
- Added directive to not compile destructure and rebuild when test or testlib are configured. Otherwise we have a warning because push and extend_from_slice don't use them anymore.
- Updated indentation in Arc::new_uninit
- Moved the removal of TryReserveError convesion to Error to patch 7, where usage of TryReserveError is actually removed.
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t

Wedson Almeida Filho (10):
rust: kernel: move allocator module under alloc
rust: alloc: introduce the VecExt trait
kbuild: use the upstream alloc crate
rust: alloc: remove our fork of the alloc crate
rust: alloc: introduce allocation flags
rust: alloc: introduce the BoxExt trait
rust: alloc: update VecExt to take allocation flags
rust: sync: update Arc and UniqueArc to take allocation flags
rust: init: update init module to take allocation flags
rust: kernel: remove usage of allocator_api unstable feature

 rust/Makefile                        |   16 +-
 rust/alloc/README.md                 |   36 -
 rust/alloc/alloc.rs                  |  452 ----
 rust/alloc/boxed.rs                  | 2463 -----------------
 rust/alloc/collections/mod.rs        |  160 --
 rust/alloc/lib.rs                    |  288 --
 rust/alloc/raw_vec.rs                |  611 -----
 rust/alloc/slice.rs                  |  890 -------
 rust/alloc/vec/drain.rs              |  255 --
 rust/alloc/vec/extract_if.rs         |  115 -
 rust/alloc/vec/into_iter.rs          |  454 ----
 rust/alloc/vec/is_zero.rs            |  204 --
 rust/alloc/vec/mod.rs                | 3683 --------------------------
 rust/alloc/vec/partial_eq.rs         |   49 -
 rust/alloc/vec/set_len_on_drop.rs    |   35 -
 rust/alloc/vec/spec_extend.rs        |  119 -
 rust/bindings/bindings_helper.h      |    3 +
 rust/kernel/alloc.rs                 |   74 +
 rust/kernel/{ => alloc}/allocator.rs |   17 +-
 rust/kernel/alloc/box_ext.rs         |   59 +
 rust/kernel/alloc/vec_ext.rs         |  176 ++
 rust/kernel/error.rs                 |   13 +-
 rust/kernel/init.rs                  |   57 +-
 rust/kernel/lib.rs                   |    5 +-
 rust/kernel/prelude.rs               |    2 +
 rust/kernel/str.rs                   |    6 +-
 rust/kernel/sync/arc.rs              |   50 +-
 rust/kernel/sync/condvar.rs          |    2 +-
 rust/kernel/sync/lock/mutex.rs       |    2 +-
 rust/kernel/sync/lock/spinlock.rs    |    2 +-
 rust/kernel/types.rs                 |    4 +-
 rust/kernel/workqueue.rs             |   14 +-
 samples/rust/rust_minimal.rs         |    6 +-
 samples/rust/rust_print.rs           |    4 +-
 scripts/generate_rust_analyzer.py    |    2 +-
 35 files changed, 405 insertions(+), 9923 deletions(-)
 delete mode 100644 rust/alloc/README.md
 delete mode 100644 rust/alloc/alloc.rs
 delete mode 100644 rust/alloc/boxed.rs
 delete mode 100644 rust/alloc/collections/mod.rs
 delete mode 100644 rust/alloc/lib.rs
 delete mode 100644 rust/alloc/raw_vec.rs
 delete mode 100644 rust/alloc/slice.rs
 delete mode 100644 rust/alloc/vec/drain.rs
 delete mode 100644 rust/alloc/vec/extract_if.rs
 delete mode 100644 rust/alloc/vec/into_iter.rs
 delete mode 100644 rust/alloc/vec/is_zero.rs
 delete mode 100644 rust/alloc/vec/mod.rs
 delete mode 100644 rust/alloc/vec/partial_eq.rs
 delete mode 100644 rust/alloc/vec/set_len_on_drop.rs
 delete mode 100644 rust/alloc/vec/spec_extend.rs
 create mode 100644 rust/kernel/alloc.rs
 rename rust/kernel/{ => alloc}/allocator.rs (86%)
 create mode 100644 rust/kernel/alloc/box_ext.rs
 create mode 100644 rust/kernel/alloc/vec_ext.rs

base-commit: 768409cff6cc89fe1194da880537a09857b6e4db

Signature · 1 line
2.34.1