* [PATCH 0/2] rnull: support 64K pages @ 2026-12-02 9:23 Vitaly Wool 2026-12-02 9:23 ` [PATCH 1/2] rust: bitmap: add BitmapArray Vitaly Wool 2026-12-02 14:13 ` [PATCH 0/2] rnull: support 64K pages Yury Norov 0 siblings, 2 replies; 4+ messages in thread From: Vitaly Wool @ 2026-12-02 9:23 UTC (permalink / raw) To: Andreas Hindborg, Jens Axboe, Yury Norov Cc: Burak Emir, Boqun Feng, Alice Ryhl, Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin, Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein, Alexandre Courbot, Onur Özkan, linux-block, rust-for-linux, linux-kernel, Vitaly Wool rnull does not build with 64K pages: NullBlockPage keeps the status of a page's sectors in a single u64, and a static assertion limits pages to 64 sectors, while a 64K page has 128. This also affects other architectures with pages larger than 32K. Patch 1 adds BitmapArray, a kernel::bitmap type that stores up to a compile-time number of words of bits inline, never allocates and dereferences to Bitmap like BitmapVec. Patch 2 uses it for the status, sized for the sectors of a page, so that a backing page still needs no extra allocation. This also resolves the TODO to use the Rust bitmap. The series is based on rnull-v7.4-rc2 from Andreas' tree [1]. Vitaly Wool (2): rust: bitmap: add BitmapArray rnull: size the sector status bitmap for any page size drivers/block/rnull/disk_storage/page.rs | 44 ++++++------ rust/kernel/bitmap.rs | 91 ++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 20 deletions(-) base-commit: 9c0fceca4feed5f1056f55abe9c7c70731402776 -- 2.39.5 [1] https://github.com/metaspace/linux ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] rust: bitmap: add BitmapArray 2026-12-02 9:23 [PATCH 0/2] rnull: support 64K pages Vitaly Wool @ 2026-12-02 9:23 ` Vitaly Wool 2026-12-02 15:02 ` Yury Norov 2026-12-02 14:13 ` [PATCH 0/2] rnull: support 64K pages Yury Norov 1 sibling, 1 reply; 4+ messages in thread From: Vitaly Wool @ 2026-12-02 9:23 UTC (permalink / raw) To: Andreas Hindborg, Jens Axboe, Yury Norov Cc: Burak Emir, Boqun Feng, Alice Ryhl, Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin, Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein, Alexandre Courbot, Onur Özkan, linux-block, rust-for-linux, linux-kernel, Vitaly Wool, Igor Belousov, Claude Opus 5 . 5 A `BitmapVec` keeps up to `usize::BITS` bits inline and allocates its storage with `bitmap_zalloc()` beyond that. A bitmap embedded in a structure that is allocated anyway, with a maximum length known at compile time, then needs a second allocation and a pointer to follow, or `unsafe` code that wraps an array with `Bitmap::from_raw()`. Add `BitmapArray<WORDS>`, an owned bitmap of up to `WORDS` words of bits stored inline, which never allocates and dereferences to `Bitmap` like `BitmapVec`. Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se> Tested-by: Igor Belousov <igor.b@beldev.am> Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> --- rust/kernel/bitmap.rs | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs index 610d565535cc..7d7bd40e2e2b 100644 --- a/rust/kernel/bitmap.rs +++ b/rust/kernel/bitmap.rs @@ -8,6 +8,7 @@ use crate::alloc::{AllocError, Flags}; use crate::bindings; +use crate::error::{code::EINVAL, Result}; #[cfg(not(CONFIG_RUST_BITMAP_HARDENED))] use crate::pr_err; use crate::ptr::Alignment; @@ -320,6 +321,96 @@ pub fn fill_random(&mut self) { } } +/// An owned bitmap of up to `WORDS * usize::BITS` bits, stored inline. +/// +/// Unlike [`BitmapVec`], it never allocates, so it suits bitmaps whose maximum length is known at +/// compile time and that are embedded in other structures. See [`Bitmap`] for available methods. +/// +/// # Examples +/// +/// ``` +/// use kernel::bitmap::BitmapArray; +/// +/// let mut b = BitmapArray::<2>::new(100)?; +/// +/// assert_eq!(100, b.len()); +/// b.set_bit(3); +/// b.set_bit(99); +/// assert_eq!(Some(3), b.next_bit(0)); +/// assert_eq!(Some(99), b.next_bit(4)); +/// assert_eq!(Some(99), b.last_bit()); +/// +/// b.clear_all(); +/// assert_eq!(None, b.next_bit(0)); +/// +/// assert!(BitmapArray::<2>::new(129).is_err()); +/// # Ok::<(), Error>(()) +/// ``` +/// +/// # Invariants +/// +/// `nbits` is at most [`BitmapArray::CAPACITY`] and at most [`BitmapVec::MAX_LEN`]. +pub struct BitmapArray<const WORDS: usize> { + /// Storage of the bitmap. + words: [usize; WORDS], + /// Length of this bitmap. + nbits: usize, +} + +impl<const WORDS: usize> BitmapArray<WORDS> { + /// The maximum length of a `BitmapArray` with `WORDS` words. + pub const CAPACITY: usize = WORDS.saturating_mul(usize::BITS as usize); + + /// Constructs a new [`BitmapArray`] of `nbits` bits, all clear. + /// + /// Fails with [`EINVAL`] if `nbits` is greater than [`BitmapArray::CAPACITY`] or than + /// [`BitmapVec::MAX_LEN`]. + #[inline] + pub fn new(nbits: usize) -> Result<Self> { + if nbits > Self::CAPACITY || nbits > BitmapVec::MAX_LEN { + return Err(EINVAL); + } + // INVARIANT: `nbits` was checked above. + Ok(Self { + words: [0; WORDS], + nbits, + }) + } + + /// Returns length of this [`BitmapArray`]. + #[allow(clippy::len_without_is_empty)] + #[inline] + pub fn len(&self) -> usize { + self.nbits + } + + /// Clears all bits of this [`BitmapArray`]. + #[inline] + pub fn clear_all(&mut self) { + self.words = [0; WORDS]; + } +} + +impl<const WORDS: usize> core::ops::Deref for BitmapArray<WORDS> { + type Target = Bitmap; + + #[inline] + fn deref(&self) -> &Bitmap { + // SAFETY: `self.words` is an initialized array that holds `CAPACITY >= nbits` bits, + // `nbits <= MAX_LEN` by the type invariants, and the array lives as long as the returned + // shared borrow of `self`. + unsafe { Bitmap::from_raw(self.words.as_ptr(), self.nbits) } + } +} + +impl<const WORDS: usize> core::ops::DerefMut for BitmapArray<WORDS> { + #[inline] + fn deref_mut(&mut self) -> &mut Bitmap { + // SAFETY: As in `deref`, and the returned borrow of `self` is exclusive. + unsafe { Bitmap::from_raw_mut(self.words.as_mut_ptr(), self.nbits) } + } +} + impl Bitmap { /// Set bit with index `index`. /// -- 2.39.5 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] rust: bitmap: add BitmapArray 2026-12-02 9:23 ` [PATCH 1/2] rust: bitmap: add BitmapArray Vitaly Wool @ 2026-12-02 15:02 ` Yury Norov 0 siblings, 0 replies; 4+ messages in thread From: Yury Norov @ 2026-12-02 15:02 UTC (permalink / raw) To: Vitaly Wool Cc: Andreas Hindborg, Jens Axboe, Yury Norov, Burak Emir, Boqun Feng, Alice Ryhl, Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin, Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein, Alexandre Courbot, Onur Özkan, linux-block, rust-for-linux, linux-kernel, Igor Belousov, Claude Opus 5 . 5 On Wed, Dec 02, 2026 at 10:23:31AM +0100, Vitaly Wool wrote: > A `BitmapVec` keeps up to `usize::BITS` bits inline and allocates its > storage with `bitmap_zalloc()` beyond that. A bitmap embedded in a > structure that is allocated anyway, with a maximum length known at > compile time, then needs a second allocation and a pointer to follow, > or `unsafe` code that wraps an array with `Bitmap::from_raw()`. > > Add `BitmapArray<WORDS>`, an owned bitmap of up to `WORDS` words of > bits stored inline, which never allocates and dereferences to `Bitmap` > like `BitmapVec`. BitmapArray is a tautology. Bitmap is already an "array of bits". So unless you're talking about 2d bitmaps, the name is wrong > Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se> > Tested-by: Igor Belousov <igor.b@beldev.am> > Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> > --- > rust/kernel/bitmap.rs | 91 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 91 insertions(+) > > diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs > index 610d565535cc..7d7bd40e2e2b 100644 > --- a/rust/kernel/bitmap.rs > +++ b/rust/kernel/bitmap.rs > @@ -8,6 +8,7 @@ > > use crate::alloc::{AllocError, Flags}; > use crate::bindings; > +use crate::error::{code::EINVAL, Result}; > #[cfg(not(CONFIG_RUST_BITMAP_HARDENED))] > use crate::pr_err; > use crate::ptr::Alignment; > @@ -320,6 +321,96 @@ pub fn fill_random(&mut self) { > } > } > > +/// An owned bitmap of up to `WORDS * usize::BITS` bits, stored inline. > +/// > +/// Unlike [`BitmapVec`], it never allocates, so it suits bitmaps whose maximum length is known at > +/// compile time and that are embedded in other structures. See [`Bitmap`] for available methods. > +/// > +/// # Examples You need it to embed in a structure? Why don't you show how it works in the example? Maybe even add pahole output to convince me that you did it right... > +/// ``` > +/// use kernel::bitmap::BitmapArray; > +/// > +/// let mut b = BitmapArray::<2>::new(100)?; This is simply wrong. On my 32-bit box this wouldn't work, for sure. Check how DECLARE_BITMAP() works in C. It doesn't take the number of words. The same holds for every other bitmap function. That's on purpose, because one of the main goals of the API is to decouple the data structure from machine specifics. Just look at the implementation and see how much work has been done to keep bitmaps working smoothly across the different word lengths. Sorry, but strong NAK. But not a NAK for the idea of embedded long bitmaps. I would first experiment with something like Bitmap<100>. This should look like; struct Device { my_bitmap: Bitmap<100>, } And from pahole perspective, should be the full analogue of struct device { unsigned long my_bitmap[2]; }; on your 64-bit machine. Thanks, Yury > +/// assert_eq!(100, b.len()); > +/// b.set_bit(3); > +/// b.set_bit(99); > +/// assert_eq!(Some(3), b.next_bit(0)); > +/// assert_eq!(Some(99), b.next_bit(4)); > +/// assert_eq!(Some(99), b.last_bit()); > +/// > +/// b.clear_all(); > +/// assert_eq!(None, b.next_bit(0)); > +/// > +/// assert!(BitmapArray::<2>::new(129).is_err()); > +/// # Ok::<(), Error>(()) > +/// ``` > +/// > +/// # Invariants > +/// > +/// `nbits` is at most [`BitmapArray::CAPACITY`] and at most [`BitmapVec::MAX_LEN`]. > +pub struct BitmapArray<const WORDS: usize> { > + /// Storage of the bitmap. > + words: [usize; WORDS], > + /// Length of this bitmap. > + nbits: usize, > +} > + > +impl<const WORDS: usize> BitmapArray<WORDS> { > + /// The maximum length of a `BitmapArray` with `WORDS` words. > + pub const CAPACITY: usize = WORDS.saturating_mul(usize::BITS as usize); > + > + /// Constructs a new [`BitmapArray`] of `nbits` bits, all clear. > + /// > + /// Fails with [`EINVAL`] if `nbits` is greater than [`BitmapArray::CAPACITY`] or than > + /// [`BitmapVec::MAX_LEN`]. > + #[inline] > + pub fn new(nbits: usize) -> Result<Self> { > + if nbits > Self::CAPACITY || nbits > BitmapVec::MAX_LEN { > + return Err(EINVAL); > + } > + // INVARIANT: `nbits` was checked above. > + Ok(Self { > + words: [0; WORDS], > + nbits, > + }) > + } > + > + /// Returns length of this [`BitmapArray`]. > + #[allow(clippy::len_without_is_empty)] > + #[inline] > + pub fn len(&self) -> usize { > + self.nbits > + } > + > + /// Clears all bits of this [`BitmapArray`]. > + #[inline] > + pub fn clear_all(&mut self) { > + self.words = [0; WORDS]; > + } > +} > + > +impl<const WORDS: usize> core::ops::Deref for BitmapArray<WORDS> { > + type Target = Bitmap; > + > + #[inline] > + fn deref(&self) -> &Bitmap { > + // SAFETY: `self.words` is an initialized array that holds `CAPACITY >= nbits` bits, > + // `nbits <= MAX_LEN` by the type invariants, and the array lives as long as the returned > + // shared borrow of `self`. > + unsafe { Bitmap::from_raw(self.words.as_ptr(), self.nbits) } > + } > +} > + > +impl<const WORDS: usize> core::ops::DerefMut for BitmapArray<WORDS> { > + #[inline] > + fn deref_mut(&mut self) -> &mut Bitmap { > + // SAFETY: As in `deref`, and the returned borrow of `self` is exclusive. > + unsafe { Bitmap::from_raw_mut(self.words.as_mut_ptr(), self.nbits) } > + } > +} > + > impl Bitmap { > /// Set bit with index `index`. > /// > -- > 2.39.5 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] rnull: support 64K pages 2026-12-02 9:23 [PATCH 0/2] rnull: support 64K pages Vitaly Wool 2026-12-02 9:23 ` [PATCH 1/2] rust: bitmap: add BitmapArray Vitaly Wool @ 2026-12-02 14:13 ` Yury Norov 1 sibling, 0 replies; 4+ messages in thread From: Yury Norov @ 2026-12-02 14:13 UTC (permalink / raw) To: Vitaly Wool Cc: Andreas Hindborg, Jens Axboe, Yury Norov, Burak Emir, Boqun Feng, Alice Ryhl, Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin, Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein, Alexandre Courbot, Onur Özkan, linux-block, rust-for-linux, linux-kernel On Wed, Dec 02, 2026 at 10:23:30AM +0100, Vitaly Wool wrote: > rnull does not build with 64K pages: NullBlockPage keeps the status of > a page's sectors in a single u64, and a static assertion limits pages > to 64 sectors, while a 64K page has 128. This also affects other > architectures with pages larger than 32K. > > Patch 1 adds BitmapArray, a kernel::bitmap type that stores up to a > compile-time number of words of bits inline, never allocates and > dereferences to Bitmap like BitmapVec. Patch 2 uses it for the status, > sized for the sectors of a page, so that a backing page still needs no > extra allocation. This also resolves the TODO to use the Rust bitmap. I'm #3 in the To list, but I didn't receive the 2nd patch. How that?.. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 15:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 9:23 [PATCH 0/2] rnull: support 64K pages Vitaly Wool 2026-12-02 9:23 ` [PATCH 1/2] rust: bitmap: add BitmapArray Vitaly Wool 2026-12-02 15:02 ` Yury Norov 2026-12-02 14:13 ` [PATCH 0/2] rnull: support 64K pages Yury Norov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox