Skip to content

Commit 5d51a99

Browse files
committed
atomic_bitmap: support enlarging the bitmap
This patch adds the support the enlarge the atomic bitmap. Some use cases in cloud-Hypervisor needs to enlarge the bitmap on-demand. Signed-off-by: Muminul Islam <[email protected]>
1 parent 13965ef commit 5d51a99

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/bitmap/backend/atomic_bitmap.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ impl AtomicBitmap {
3737
}
3838
}
3939

40+
/// Enlarge the vector with additionsl byte size, with one bit per page
41+
/// Reserve the existing bits and filling out the new space with default.
42+
pub fn enlarge(&mut self, additional_size: usize) {
43+
let num_pages = additional_size.div_ceil(self.page_size.get());
44+
self.size += num_pages;
45+
let map_size = self.size.div_ceil(u64::BITS as usize);
46+
self.map.resize_with(map_size, Default::default);
47+
}
48+
4049
/// Is bit `n` set? Bits outside the range of the bitmap are always unset.
4150
pub fn is_bit_set(&self, index: usize) -> bool {
4251
if index < self.size {

0 commit comments

Comments
 (0)