From 2d78f8ad2ad29d36a7045d093dfd74b3c7bdb8ab Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Mon, 4 Oct 2021 19:20:10 -0400 Subject: [PATCH] parallelize unref_from_storage from clean_dead_slots_from_accounts_index (#20411) --- runtime/src/accounts_db.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index b7fbdd1db1..2540fca327 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5804,12 +5804,23 @@ impl AccountsDb { purged_stored_account_slots: Option<&mut AccountSlots>, ) { if let Some(purged_stored_account_slots) = purged_stored_account_slots { + let len = purged_stored_account_slots.len(); + // we could build a higher level function in accounts_index to group by bin + const BATCH_SIZE: usize = 10_000; + let batches = 1 + (len / BATCH_SIZE); + self.thread_pool_clean.install(|| { + (0..batches).into_par_iter().for_each(|batch| { + let skip = batch * BATCH_SIZE; + for (_slot, pubkey) in purged_slot_pubkeys.iter().skip(skip).take(BATCH_SIZE) { + self.accounts_index.unref_from_storage(pubkey); + } + }) + }); for (slot, pubkey) in purged_slot_pubkeys { purged_stored_account_slots .entry(pubkey) .or_default() .insert(slot); - self.accounts_index.unref_from_storage(&pubkey); } }