AcctIdx: optimize should_remove_from_mem (#20327)

This commit is contained in:
Jeff Washington (jwash) 2021-09-29 16:41:54 -05:00 committed by GitHub
parent 4bf6d0c4d7
commit 2ec74474e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -621,6 +621,7 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
self.storage.wait_dirty_or_aged.notify_one(); 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( fn should_remove_from_mem(
&self, &self,
current_age: Age, current_age: Age,
@ -629,16 +630,18 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
) -> bool { ) -> bool {
// this could be tunable dynamically based on memory pressure // 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 // 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(); let slot_list = entry.slot_list.read().unwrap();
if slot_list.len() != 1 { if slot_list.len() != 1 {
return false; // keep 0 and > 1 slot lists in mem. They will be cleaned or shrunk soon. false // keep 0 and > 1 slot lists in mem. They will be cleaned or shrunk soon.
} } else {
if slot_list.iter().any(|(_, info)| info.is_cached()) { // keep items with slot lists that contained cached items
return false; // 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) { fn flush_internal(&self) {