Skip to content

Commit

Permalink
Include empty pages in fragmented statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Dec 11, 2024
1 parent 3862242 commit 949cc7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,8 @@ impl WriteTransaction {
+ freed_tree_stats.stored_leaf_bytes;
let total_fragmented = data_tree_stats.fragmented_bytes()
+ system_tree_stats.fragmented_bytes
+ freed_tree_stats.fragmented_bytes;
+ freed_tree_stats.fragmented_bytes
+ self.mem.count_free_pages()? * (self.mem.get_page_size() as u64);

Ok(DatabaseStats {
tree_height: data_tree_stats.tree_height(),
Expand Down
10 changes: 10 additions & 0 deletions src/tree_store/page_store/page_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,16 @@ impl TransactionalMemory {
Ok(count)
}

pub(crate) fn count_free_pages(&self) -> Result<u64> {
let state = self.state.lock().unwrap();
let mut count = 0u64;
for i in 0..state.header.layout().num_regions() {
count += u64::from(state.get_region(i).count_free_pages());
}

Ok(count)
}

pub(crate) fn get_page_size(&self) -> usize {
self.page_size.try_into().unwrap()
}
Expand Down

0 comments on commit 949cc7c

Please sign in to comment.