Skip to content

Commit

Permalink
Fix zcachedb slabs overflow (openzfs#227)
Browse files Browse the repository at this point in the history
With the total_slots field converted to a u16 recently for BitmapSlabs
an integer overflow comes up on zcachedb when we multiply that field
by 100 to get a percentage. This patch fixes this overflow by promoting
the integer to a u64 just for this calculation.
  • Loading branch information
sdimitro authored Feb 18, 2022
1 parent 64c24eb commit 3c27bef
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/zfs_object_agent/zettacache/src/block_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ impl SlabTrait for BitmapSlab {
fn dump_info(&self) {
let used_slots = self.total_slots - self.allocatable.len();
writeln_stdout!(
"slab_offset: {} slot_size: {} slots_used: {}/{} utilization: {}%",
"slab_offset: {} slot_size: {} slots_used: {}/{} utilization: {:.1}%",
self.location.offset(),
nice_p2size(u64::from(self.slot_size)),
used_slots,
self.total_slots,
(used_slots * 100) / self.total_slots
(f64::from(used_slots) * 100.0) / f64::from(self.total_slots)
);
for (slot, run) in self.allocatable.iter_inverse_ranges(0, self.total_slots) {
let first_location = self.slot_to_location(slot);
Expand Down

0 comments on commit 3c27bef

Please sign in to comment.