From ddfd4f86f3196f297a8e1d64a9d527f068496c47 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 3 Mar 2022 08:47:39 -0600 Subject: [PATCH] exit early from acct bg svc if no shrink candidates (#23459) --- runtime/src/accounts_db.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 1b5c8d5706..e8866cd4d5 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -2943,7 +2943,6 @@ impl AccountsDb { /// achieved, it will stop and return the filtered-down candidates and the candidates which /// are skipped in this round and might be eligible for the future shrink. fn select_candidates_by_total_usage( - &self, shrink_slots: &ShrinkCandidates, shrink_ratio: f64, ) -> (ShrinkCandidates, ShrinkCandidates) { @@ -3032,20 +3031,29 @@ impl AccountsDb { } pub fn shrink_candidate_slots(&self) -> usize { - let _guard = self.active_stats.activate(ActiveStatItem::Shrink); - let shrink_candidates_slots = std::mem::take(&mut *self.shrink_candidate_slots.lock().unwrap()); let (shrink_slots, shrink_slots_next_batch) = { if let AccountShrinkThreshold::TotalSpace { shrink_ratio } = self.shrink_ratio { let (shrink_slots, shrink_slots_next_batch) = - self.select_candidates_by_total_usage(&shrink_candidates_slots, shrink_ratio); + Self::select_candidates_by_total_usage(&shrink_candidates_slots, shrink_ratio); (shrink_slots, Some(shrink_slots_next_batch)) } else { (shrink_candidates_slots, None) } }; + if shrink_slots.is_empty() + && shrink_slots_next_batch + .as_ref() + .map(|s| s.is_empty()) + .unwrap_or(true) + { + return 0; + } + + let _guard = self.active_stats.activate(ActiveStatItem::Shrink); + let mut measure_shrink_all_candidates = Measure::start("shrink_all_candidate_slots-ms"); let num_candidates = shrink_slots.len(); let shrink_candidates_count: usize = self.thread_pool_clean.install(|| { @@ -6065,7 +6073,7 @@ impl AccountsDb { { assert_eq!( *slot, store.slot(), - "AccountDB::accounts_index corrupted. Storage pointed to: {}, expected: {}, should only point to one slot", + "AccountsDB::accounts_index corrupted. Storage pointed to: {}, expected: {}, should only point to one slot", store.slot(), *slot ); let count = @@ -10769,11 +10777,12 @@ pub mod tests { fn test_select_candidates_by_total_usage_no_candidates() { // no input candidates -- none should be selected solana_logger::setup(); - let accounts = AccountsDb::new_single_for_tests(); let candidates: ShrinkCandidates = HashMap::new(); - let (selected_candidates, next_candidates) = - accounts.select_candidates_by_total_usage(&candidates, DEFAULT_ACCOUNTS_SHRINK_RATIO); + let (selected_candidates, next_candidates) = AccountsDb::select_candidates_by_total_usage( + &candidates, + DEFAULT_ACCOUNTS_SHRINK_RATIO, + ); assert_eq!(0, selected_candidates.len()); assert_eq!(0, next_candidates.len()); @@ -10783,7 +10792,6 @@ pub mod tests { fn test_select_candidates_by_total_usage_3_way_split_condition() { // three candidates, one selected for shrink, one is put back to the candidate list and one is ignored solana_logger::setup(); - let accounts = AccountsDb::new_single_for_tests(); let mut candidates: ShrinkCandidates = HashMap::new(); let common_store_path = Path::new(""); @@ -10847,7 +10855,7 @@ pub mod tests { // to the candidates list for next round. let target_alive_ratio = 0.6; let (selected_candidates, next_candidates) = - accounts.select_candidates_by_total_usage(&candidates, target_alive_ratio); + AccountsDb::select_candidates_by_total_usage(&candidates, target_alive_ratio); assert_eq!(1, selected_candidates.len()); assert_eq!(1, selected_candidates[&common_slot_id].len()); assert!(selected_candidates[&common_slot_id].contains(&store1.append_vec_id())); @@ -10859,7 +10867,6 @@ pub mod tests { fn test_select_candidates_by_total_usage_2_way_split_condition() { // three candidates, 2 are selected for shrink, one is ignored solana_logger::setup(); - let accounts = AccountsDb::new_single_for_tests(); let mut candidates: ShrinkCandidates = HashMap::new(); let common_store_path = Path::new(""); @@ -10920,7 +10927,7 @@ pub mod tests { // Set the target ratio to default (0.8), both store1 and store2 must be selected and store3 is ignored. let target_alive_ratio = DEFAULT_ACCOUNTS_SHRINK_RATIO; let (selected_candidates, next_candidates) = - accounts.select_candidates_by_total_usage(&candidates, target_alive_ratio); + AccountsDb::select_candidates_by_total_usage(&candidates, target_alive_ratio); assert_eq!(1, selected_candidates.len()); assert_eq!(2, selected_candidates[&common_slot_id].len()); assert!(selected_candidates[&common_slot_id].contains(&store1.append_vec_id())); @@ -10932,7 +10939,6 @@ pub mod tests { fn test_select_candidates_by_total_usage_all_clean() { // 2 candidates, they must be selected to achieve the target alive ratio solana_logger::setup(); - let accounts = AccountsDb::new_single_for_tests(); let mut candidates: ShrinkCandidates = HashMap::new(); let slot1 = 12; @@ -10981,7 +10987,7 @@ pub mod tests { // Set the target ratio to default (0.8), both stores from the two different slots must be selected. let target_alive_ratio = DEFAULT_ACCOUNTS_SHRINK_RATIO; let (selected_candidates, next_candidates) = - accounts.select_candidates_by_total_usage(&candidates, target_alive_ratio); + AccountsDb::select_candidates_by_total_usage(&candidates, target_alive_ratio); assert_eq!(2, selected_candidates.len()); assert_eq!(1, selected_candidates[&slot1].len()); assert_eq!(1, selected_candidates[&slot2].len());