diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index ef8981f9b57f4c..57b1f6e488c847 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -141,6 +141,11 @@ const MAX_ITEMS_PER_CHUNK: Slot = 2_500; // This allows us to split up accounts index accesses across multiple threads. const SHRINK_COLLECT_CHUNK_SIZE: usize = 50; +/// The number of shrink candidate slots that is small enough so that +/// additional storages from ancient slots can be added to the +/// candidates for shrinking. +const SHRINK_INSERT_ANCIENT_THRESHOLD: usize = 10; + #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] pub enum CreateAncientStorage { /// ancient storages are created by appending @@ -2059,13 +2064,13 @@ impl ShrinkStats { ( "ancient_slots_added_to_shrink", self.ancient_slots_added_to_shrink - .swap(0, Ordering::Relaxed) as i64, + .swap(0, Ordering::Relaxed), i64 ), ( "ancient_bytes_added_to_shrink", self.ancient_bytes_added_to_shrink - .swap(0, Ordering::Relaxed) as i64, + .swap(0, Ordering::Relaxed), i64 ), ( @@ -2516,7 +2521,6 @@ impl AccountsDb { const ACCOUNTS_STACK_SIZE: usize = 8 * 1024 * 1024; AccountsDb { - best_ancient_slots_to_shrink: RwLock::default(), create_ancient_storage: CreateAncientStorage::default(), verify_accounts_hash_in_bg: VerifyAccountsHashInBackground::default(), active_stats: ActiveStats::default(), @@ -2580,6 +2584,7 @@ impl AccountsDb { epoch_accounts_hash_manager: EpochAccountsHashManager::new_invalid(), test_skip_rewrites_but_include_in_bank_hash: false, latest_full_snapshot_slot: SeqLock::new(None), + best_ancient_slots_to_shrink: RwLock::default(), } } @@ -5122,7 +5127,7 @@ impl AccountsDb { let mut ancient_slots_added = 0; // If there are too few slots to shrink, add an ancient slot // for shrinking. - if shrink_slots.len() < 10 { + if shrink_slots.len() < SHRINK_INSERT_ANCIENT_THRESHOLD { let mut ancients = self.best_ancient_slots_to_shrink.write().unwrap(); if let Some((slot, capacity)) = ancients.first_mut() { if let Some(store) = self.storage.get_slot_storage_entry(*slot) { @@ -5132,15 +5137,11 @@ impl AccountsDb { { *capacity = 0; ancient_slots_added += 1; + let ancient_bytes_added_to_shrink = store.alive_bytes() as u64; + shrink_slots.insert(*slot, store); self.shrink_stats .ancient_bytes_added_to_shrink - .fetch_add(store.alive_bytes() as u64, Ordering::Relaxed); - shrink_slots.insert(*slot, store); - log::debug!( - "ancient_slots_added: {ancient_slots_added}, {}, avail: {}", - shrink_slots.len(), - ancients.len() - ); + .fetch_add(ancient_bytes_added_to_shrink, Ordering::Relaxed); self.shrink_stats .ancient_slots_added_to_shrink .fetch_add(ancient_slots_added, Ordering::Relaxed);