diff --git a/runtime/src/bucket_map_holder_stats.rs b/runtime/src/bucket_map_holder_stats.rs index 84eaa7cb188c9a..0deec6ffd4b3f8 100644 --- a/runtime/src/bucket_map_holder_stats.rs +++ b/runtime/src/bucket_map_holder_stats.rs @@ -34,6 +34,7 @@ pub struct BucketMapHolderStats { pub count_in_mem: AtomicU64, pub per_bucket_count: Vec, pub flush_entries_updated_on_disk: AtomicU64, + pub flush_entries_removed_from_mem: AtomicU64, pub active_threads: AtomicU64, pub get_range_us: AtomicU64, last_age: AtomicU8, @@ -66,13 +67,17 @@ impl BucketMapHolderStats { } pub fn insert_or_delete_mem(&self, insert: bool, bin: usize) { + self.insert_or_delete_mem_count(insert, bin, 1) + } + + pub fn insert_or_delete_mem_count(&self, insert: bool, bin: usize, count: u64) { let per_bucket = self.per_bucket_count.get(bin); if insert { - self.count_in_mem.fetch_add(1, Ordering::Relaxed); - per_bucket.map(|count| count.fetch_add(1, Ordering::Relaxed)); + self.count_in_mem.fetch_add(count, Ordering::Relaxed); + per_bucket.map(|stat| stat.fetch_add(count, Ordering::Relaxed)); } else { - self.count_in_mem.fetch_sub(1, Ordering::Relaxed); - per_bucket.map(|count| count.fetch_sub(1, Ordering::Relaxed)); + self.count_in_mem.fetch_sub(count, Ordering::Relaxed); + per_bucket.map(|stat| stat.fetch_sub(count, Ordering::Relaxed)); } } @@ -364,6 +369,12 @@ impl BucketMapHolderStats { .swap(0, Ordering::Relaxed), i64 ), + ( + "flush_entries_removed_from_mem", + self.flush_entries_removed_from_mem + .swap(0, Ordering::Relaxed), + i64 + ), ); } } diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 0c4eae03088625..c91c48a17b4a5c 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -778,6 +778,7 @@ impl InMemAccountsIndex { return false; // range said to hold 'all', so not completed } + let mut removed = 0; // consider chunking these so we don't hold the write lock too long let mut map = self.map().write().unwrap(); for k in removes { @@ -815,10 +816,14 @@ impl InMemAccountsIndex { } // all conditions for removing succeeded, so really remove item from in-mem cache - self.stats().insert_or_delete_mem(false, self.bin); + removed += 1; occupied.remove(); } } + self.stats() + .insert_or_delete_mem_count(false, self.bin, removed); + Self::update_stat(&self.stats().flush_entries_removed_from_mem, removed); + completed_scan }