On Wed, Sep 30, 2026 at 11:42:56AM +0900, Eliot Courtney wrote: > Add `IdPool::reserve_ids` which allocates a contiguous range with the > given offset, count, and alignment. > > Reviewed-by: Burak Emir <[email protected]> > Reviewed-by: Alexandre Courbot <[email protected]> > Signed-off-by: Eliot Courtney <[email protected]>
Reviewed-by: Yury Norov <[email protected]> > --- > rust/kernel/id_pool.rs | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/rust/kernel/id_pool.rs b/rust/kernel/id_pool.rs > index 384753fe0e44..06a4c71c4c6c 100644 > --- a/rust/kernel/id_pool.rs > +++ b/rust/kernel/id_pool.rs > @@ -4,8 +4,14 @@ > > //! Rust API for an ID pool backed by a [`BitmapVec`]. > > +use core::{ > + num::NonZero, > + ops::Range, // > +}; > + > use crate::alloc::{AllocError, Flags}; > use crate::bitmap::BitmapVec; > +use crate::ptr::Alignment; > > /// Represents a dynamic ID pool backed by a [`BitmapVec`]. > /// > @@ -240,6 +246,32 @@ pub fn find_unused_id(&mut self, offset: usize) -> > Option<UnusedId<'_>> { > pub fn release_id(&mut self, id: usize) { > self.map.clear_bit(id); > } > + > + /// Reserves a contiguous area of `count` IDs at or after `offset`. > + /// > + /// The start of the returned area is a multiple of `align`. > + /// > + /// Returns the reserved range upon success, or [`None`] if no such area > could be found. > + #[inline] > + #[must_use] > + pub fn reserve_ids( > + &mut self, > + offset: usize, > + count: NonZero<usize>, > + align: Alignment, > + ) -> Option<Range<usize>> { > + let start = self.map.next_zero_area(offset, count, align)?; > + self.map.set(start, count); > + Some(start..start + count.get()) > + } > + > + /// Releases a contiguous area of IDs. > + #[inline] > + pub fn release_ids(&mut self, range: &Range<usize>) { > + if let Some(nbits) = NonZero::new(range.len()) { > + self.map.clear(range.start, nbits); > + } > + } > } > > /// Represents an unused id in an [`IdPool`]. > > -- > 2.55.0
