From 2ec74474e97e6e438b3e9de2d57bb7ded64ee84c Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Wed, 29 Sep 2021 16:41:54 -0500 Subject: [PATCH] AcctIdx: optimize should_remove_from_mem (#20327) --- runtime/src/in_mem_accounts_index.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 6560eef05..bce6dd358 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -621,6 +621,7 @@ impl InMemAccountsIndex { self.storage.wait_dirty_or_aged.notify_one(); } + /// return true if 'entry' should be removed from the in-mem index fn should_remove_from_mem( &self, current_age: Age, @@ -629,16 +630,18 @@ impl InMemAccountsIndex { ) -> bool { // this could be tunable dynamically based on memory pressure // we could look at more ages or we could throw out more items we are choosing to keep in the cache - { + if startup || (current_age == entry.age()) { + // only read the slot list if we are planning to throw the item out let slot_list = entry.slot_list.read().unwrap(); if slot_list.len() != 1 { - return false; // keep 0 and > 1 slot lists in mem. They will be cleaned or shrunk soon. - } - if slot_list.iter().any(|(_, info)| info.is_cached()) { - return false; // keep items with slot lists that contained cached items + false // keep 0 and > 1 slot lists in mem. They will be cleaned or shrunk soon. + } else { + // keep items with slot lists that contained cached items + !slot_list.iter().any(|(_, info)| info.is_cached()) } + } else { + false } - startup || (current_age == entry.age()) } fn flush_internal(&self) {