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();
}
/// 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<T: IndexValue> InMemAccountsIndex<T> {
) -> 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) {