Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dmakarov
Copy link

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.

@dmakarov dmakarov force-pushed the cleaning branch 2 times, most recently from 72d178b to 7cc70c2 Compare September 19, 2024 14:23
{
removed_pubkeys
.iter()
.for_each(|pubkey| self.insert_pubkey(candidates, pubkey))

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.

Copy link
Author

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.

Comment on lines 3099 to 3103
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());
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here:

Suggested change
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());
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants