Skip to content

Commit

Permalink
DLPX-81825 same-checkpoint alloc and free leaks blocks (openzfs#500)
Browse files Browse the repository at this point in the history
When a segment is marked as allocated and then gets freed within the
same checkpoint it never actually makes it back to the set of
allocatable segments effectively leaking its space.
  • Loading branch information
sdimitro committed Jun 30, 2022
1 parent f230a33 commit 17b18ba
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions cmd/zfs_object_agent/zettacache/src/block_allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,7 @@ impl SlabTrait for BitmapSlab {
"double free at slot {:?}",
slot
);

if self.allocating.contains(slot) {
assert!(!self.freeing.contains(slot));
self.allocating.remove(slot);
} else {
self.freeing.insert(slot);
}
self.freeing.insert(slot);
}

fn flush_to_spacemap(&mut self, spacemap: &mut SpaceMap) {
Expand All @@ -269,14 +263,12 @@ impl SlabTrait for BitmapSlab {
}
self.allocating.clear();

// Space freed during this checkpoint is now available for reallocation.
for (slot, run) in self.freeing.iter_ranges() {
spacemap.free(Extent {
location: self.slot_to_location(slot),
size: u64::from(run) * u64::from(self.slot_size),
});
}
// Space freed during this checkpoint is now available for reallocation.
for (slot, run) in self.freeing.iter_ranges() {
with_alloctag(Self::ALLOCATABLE_TAG, || {
self.allocatable.insert_range(slot..(slot + run))
});
Expand Down Expand Up @@ -502,17 +494,7 @@ impl SlabTrait for ExtentSlab {
let size = extent.size;

self.allocatable.verify_absent(offset, size);

match self.allocating.overlap(offset, size) {
Some(_) => {
self.freeing.verify_absent(offset, size);
self.allocating.remove(offset, size);
}
None => {
self.allocating.verify_absent(offset, size);
self.freeing.add(offset, size);
}
}
self.freeing.add(offset, size);
}

fn flush_to_spacemap(&mut self, spacemap: &mut SpaceMap) {
Expand Down

0 comments on commit 17b18ba

Please sign in to comment.