diff --git a/src/transactions.rs b/src/transactions.rs index c2bbe47b..317a24b7 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -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(), diff --git a/src/tree_store/page_store/page_manager.rs b/src/tree_store/page_store/page_manager.rs index fc653815..4ce0ad94 100644 --- a/src/tree_store/page_store/page_manager.rs +++ b/src/tree_store/page_store/page_manager.rs @@ -1132,6 +1132,16 @@ impl TransactionalMemory { Ok(count) } + pub(crate) fn count_free_pages(&self) -> Result { + 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() }