Skip to content

Commit 53deadb

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 f56ca47 commit 53deadb

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 this bitmap with enough bits to track `additional_size` additional bytes at page granularity.
41+
/// New bits are initialized to zero.
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)