From ad30a60059b23b07831ca84ef8eaf18ff6bb64ce Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 18 Apr 2023 15:33:02 -0500 Subject: [PATCH] update stats for packed ancient (#31255) --- runtime/src/accounts_db.rs | 6 ++++++ runtime/src/ancient_append_vecs.rs | 28 ++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index cd2a8bcc4b..8eeb85e32b 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -1945,6 +1945,7 @@ pub(crate) struct ShrinkAncientStats { pub(crate) random_shrink: AtomicU64, pub(crate) slots_considered: AtomicU64, pub(crate) ancient_scanned: AtomicU64, + pub(crate) second_pass_one_ref: AtomicU64, } #[derive(Debug, Default)] @@ -2228,6 +2229,11 @@ impl ShrinkAncientStats { self.total_us.swap(0, Ordering::Relaxed) as i64, i64 ), + ( + "second_pass_one_ref", + self.second_pass_one_ref.swap(0, Ordering::Relaxed) as i64, + i64 + ), ); } } diff --git a/runtime/src/ancient_append_vecs.rs b/runtime/src/ancient_append_vecs.rs index 1a3e8ec274..3e745d1838 100644 --- a/runtime/src/ancient_append_vecs.rs +++ b/runtime/src/ancient_append_vecs.rs @@ -430,6 +430,17 @@ impl AccountsDb { .zip(packed_contents) .collect::>(); + // keep track of how many slots were shrunk away + self.shrink_ancient_stats + .ancient_append_vecs_shrunk + .fetch_add( + accounts_to_combine + .target_slots_sorted + .len() + .saturating_sub(packer.len()) as u64, + Ordering::Relaxed, + ); + self.thread_pool_clean.install(|| { packer.par_iter().for_each(|(target_slot, pack)| { let mut write_ancient_accounts_local = WriteAncientAccounts::default(); @@ -587,6 +598,7 @@ impl AccountsDb { // collect pk values here to avoid borrow checker let pks = Self::get_many_refs_pubkeys(shrink_collect); let mut index = 0; + let mut saved = 0; self.accounts_index.scan( pks.iter(), |_pubkey, slots_refs, _entry| { @@ -596,15 +608,16 @@ impl AccountsDb { // This entry has been unref'd during shrink ancient, so it can now move out of `many_refs` and into `one_ref`. // This could happen if the same pubkey is in 2 append vecs that are BOTH being shrunk right now. // Note that `shrink_collect()`, which was previously called to create `shrink_collect`, unrefs any dead accounts. - let account = shrink_collect - .alive_accounts - .many_refs - .accounts - .remove(index - 1); + let many_refs = &mut shrink_collect.alive_accounts.many_refs; + let account = many_refs.accounts.remove(index - 1); + if many_refs.accounts.is_empty() { + // all accounts in `many_refs` now have only 1 ref, so this slot can now be combined into another. + saved += 1; + } let bytes = account.stored_size(); shrink_collect.alive_accounts.one_ref.accounts.push(account); saturating_add_assign!(shrink_collect.alive_accounts.one_ref.bytes, bytes); - shrink_collect.alive_accounts.many_refs.bytes -= bytes; + many_refs.bytes -= bytes; // since we removed an entry from many_refs.accounts, we need to index one less index -= 1; } @@ -614,6 +627,9 @@ impl AccountsDb { None, false, ); + self.shrink_ancient_stats + .second_pass_one_ref + .fetch_add(saved, Ordering::Relaxed); } /// create packed storage and write contents of 'packed' to it.