Skip to content

Commit d196d39

Browse files
russell-islamroypat
authored andcommitted
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 ff882be commit d196d39

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
@@ -39,6 +39,15 @@ impl AtomicBitmap {
3939
}
4040
}
4141

42+
/// Enlarge this bitmap with enough bits to track `additional_size` additional bytes at page granularity.
43+
/// New bits are initialized to zero.
44+
pub fn enlarge(&mut self, additional_size: usize) {
45+
self.byte_size += additional_size;
46+
self.size = self.byte_size.div_ceil(self.page_size.get());
47+
let map_size = self.size.div_ceil(u64::BITS as usize);
48+
self.map.resize_with(map_size, Default::default);
49+
}
50+
4251
/// Is bit `n` set? Bits outside the range of the bitmap are always unset.
4352
pub fn is_bit_set(&self, index: usize) -> bool {
4453
if index < self.size {

0 commit comments

Comments
 (0)