Skip to contentSkip to conversation

rust: mem: add `Align` type

PATCH Applied Gary Guo 3 participants 3 messages Jun 10 – Oct 2 Rust

lore
Share & tools
lore

Gary Guo

author reviewer
#0 lore raw

PATCH 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
index 9512af7156df..0a12c3011c61 100644
@@ -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]>
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Gary Guo

Rust's repr(align()) only works with integers. Add an Align type so it can also be specified via const generics.

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

Applied
#2 lore raw
In reply to Gary Guo
Quoted 5 lines · Gary Guo

Rust's repr(align()) only works with integers. Add an Align type so it can also be specified via const generics.

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