rust: mem: add `Align` type
Gary Guo
reviewerPATCH v2 1/1 rust: mem: add `Align` type
Rust's repr(align()) only works with integers. Add an Align type so it can also be specified via const generics.
---
Andreas, could you see if this patch meets your need for cache-line aligning?
Changes in v2:
- Added Clone, Copy, Debug impl. (Sashiko)
- Expand impl to 65536, i.e. PAGE_SIZE_64K. Kernel technically support PAGE_SIZE_256K, but it's uncommon enough so I think there's no need to support it unless a need arises. (Sashiko)
- Use _align in example, as usually the field is not going to be referenced.
- Link to v1: https://patch.msgid.link/[email protected]
--- rust/kernel/lib.rs | 1 + rust/kernel/mem.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+)
rust/kernel/lib.rs +1 -0
@@ -92,6 +92,7 @@pub mod kunit;pub mod list;pub mod maple_tree; +pub mod mem;pub mod miscdevice;pub mod mm;pub mod module_param;
rust/kernel/mem.rs new file +70 -0
70 lines not on this page · raw message
---
base-commit: a87737435cfa134f9cdcc696ba3080759d04cf72
change-id: 20260610-const-align-7020a76367ce
Best regards,
Signature · 1 line
Gary Guo <[email protected]>
Quoted 4 lines · Gary Guo
Rust's
repr(align())only works with integers. Add anAligntype so it can also be specified via const generics.Signed-off-by Gary Guo <[email protected]>
Quoted 3 lines
---
Andreas, could you see if this patch meets your need for cache-line aligning?
Yes, with new type wrapper as discussed.
Best regards,
Andreas Hindborg
Miguel Ojeda
AppliedQuoted 5 lines · Gary Guo
Rust's
repr(align())only works with integers. Add anAligntype so it can also be specified via const generics.Signed-off-by Gary Guo <[email protected]>
Applied to rust-next -- thanks!
[ Adjusted the title of the new module to match the one used in patch
"rust: mem: add transmute with deferred size check" (landing via driver-core), which is also closer to the upstream standard library title. - Miguel ]
Cheers,
Miguel