-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor remove_uncleaned_slots to reduce memory consumption #2954
base: master
Are you sure you want to change the base?
Conversation
72d178b
to
7cc70c2
Compare
accounts-db/src/accounts_db.rs
Outdated
{ | ||
removed_pubkeys | ||
.iter() | ||
.for_each(|pubkey| self.insert_pubkey(candidates, pubkey)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removed_pubkeys
here is an owned vec of Pubkeys, right? And it looks like insert_pubkey()
take a &Pubkey
. So we end up having to make a copy of each pubkey inside insert_pubkey()
, even though we might not need to.
If insert_pubkey()
took the pubkey by value, I think that would allow us to do something like
for removed_pubkey in removed_pubkeys {
self.insert_pubkey(candidates, pubkey);
}
To avoid the copy.
And since inside insert_pubkey()
we always copy, this seems like an improvement to me. The callers that only have a &Pubkey
now explicitly do the copy themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change. Thank you.
accounts-db/src/accounts_db.rs
Outdated
fn insert_pubkey(&self, candidates: &[RwLock<HashMap<Pubkey, CleaningInfo>>], pubkey: &Pubkey) { | ||
let index = self.accounts_index.bin_calculator.bin_from_pubkey(pubkey); | ||
let mut candidates_bin = candidates[index].write().unwrap(); | ||
candidates_bin.insert(*pubkey, CleaningInfo::default()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here:
fn insert_pubkey(&self, candidates: &[RwLock<HashMap<Pubkey, CleaningInfo>>], pubkey: &Pubkey) { | |
let index = self.accounts_index.bin_calculator.bin_from_pubkey(pubkey); | |
let mut candidates_bin = candidates[index].write().unwrap(); | |
candidates_bin.insert(*pubkey, CleaningInfo::default()); | |
} | |
fn insert_pubkey(&self, candidates: &[RwLock<HashMap<Pubkey, CleaningInfo>>], pubkey: Pubkey) { | |
let index = self.accounts_index.bin_calculator.bin_from_pubkey(&pubkey); | |
let mut candidates_bin = candidates[index].write().unwrap(); | |
candidates_bin.insert(pubkey, CleaningInfo::default()); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
Problem
Cleaning algorithm creates many temporary data sets that consume significant amount of heap, increasing memory requirements of the validator.
Summary of Changes
Avoid making another temporary container of pubkeys that are candidates for cleaning.
This change reduces the used heap memory by 14% on a sample snapshot cleaning from 166,737,546,218 to 143,515,886,322 bytes.
Also collapse two small functions where the first is the only caller of the second into a single function, and remove a unit test that is almost a duplicate of another existing test that exercises the first of the functions.