Skip to content

Commit

Permalink
Fix calculations for target cache size in try_start_merge_task() (ope…
Browse files Browse the repository at this point in the history
…nzfs#35)

The calculations done by try_start_merge_task() to determine if we
should start a merge, and potentially trigger evictions, currently uses
the block access object to determine the total size of the cache.

This is incorrect, as that size includes the amount of space reserved
for various forms of metadata used by the cache. What we actually want
to use, is the total size available to the block allocator object, as
that correctly excludes all the space reserved for cache metadata.
  • Loading branch information
Prakash Surya authored Nov 30, 2021
1 parent b219e2e commit e0b3fc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/zfs_object_agent/zettacache/src/block_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,10 @@ impl BlockAllocator {
self.freeing_space
}

pub fn size(&self) -> u64 {
self.coverage.size
}

//
// |----------------| Device Offset 0
// |... metadata ...|
Expand Down
10 changes: 5 additions & 5 deletions cmd/zfs_object_agent/zettacache/src/zettacache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ impl ZettaCacheState {
) -> Option<tokio::sync::mpsc::Receiver<MergeMessage>> {
if self.pending_changes.len() < *MAX_PENDING_CHANGES
&& self.atime_histogram.sum()
< (self.block_access.size() / 100) * *HIGH_WATER_CACHE_SIZE_PCT
< (self.block_allocator.size() / 100) * *HIGH_WATER_CACHE_SIZE_PCT
{
trace!(
"not starting new merge, only {} pending changes",
Expand All @@ -1760,13 +1760,13 @@ impl ZettaCacheState {
return None;
}

let target_size = (self.block_access.size() / 100) * *TARGET_CACHE_SIZE_PCT;
let target_size = (self.block_allocator.size() / 100) * *TARGET_CACHE_SIZE_PCT;
info!(
"target cache size for storage size {}GB is {}GB; {}MB used; {}MB high-water; {}MB freeing; histogram covers {}MB",
self.block_access.size() / 1024 / 1024 / 1024,
self.block_allocator.size() / 1024 / 1024 / 1024,
target_size / 1024 / 1024 / 1024,
(self.block_access.size() - self.block_allocator.get_available()) / 1024 / 1024,
(self.block_access.size() / 100) * *HIGH_WATER_CACHE_SIZE_PCT / 1024 / 1024,
(self.block_allocator.size() - self.block_allocator.get_available()) / 1024 / 1024,
(self.block_allocator.size() / 100) * *HIGH_WATER_CACHE_SIZE_PCT / 1024 / 1024,
self.block_allocator.get_freeing() / 1024 / 1024,
self.atime_histogram.sum() / 1024 / 1024,
);
Expand Down

0 comments on commit e0b3fc8

Please sign in to comment.