Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4605,10 +4605,12 @@ impl AccountsDb {
excess_slot_count = old_slots.len();
let mut flush_stats = FlushStats::default();
old_slots.into_iter().for_each(|old_slot| {
// Don't flush slots that are known to be unrooted
// Only flush unrooted slots > max_flushed_root. Slots older < max_flushed_root
// cannot have max_flushed_root as an ancestor, and thus will never become rooted.
// The unrootable slots will get purged later.
Comment thread
brooksprumo marked this conversation as resolved.
if old_slot > max_flushed_root {
if self.should_aggressively_flush_cache() {
if let Some(stats) = self.flush_slot_cache(old_slot) {
if let Some(stats) = self.flush_unrooted_slot_cache(old_slot) {
flush_stats.accumulate(&stats);
}
}
Expand Down Expand Up @@ -4859,8 +4861,19 @@ impl AccountsDb {
flush_stats
}

/// flush all accounts in this slot
fn flush_slot_cache(&self, slot: Slot) -> Option<FlushStats> {
/// Flushes an unrooted slot from the write cache to storage to free up memory
#[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))]
fn flush_unrooted_slot_cache(&self, slot: Slot) -> Option<FlushStats> {
assert!(
!self
.accounts_index
.roots_tracker
.read()
.unwrap()
.alive_roots
.contains(&slot),
"slot: {slot}"
);
self.flush_slot_cache_with_clean(slot, None::<&mut fn(&_) -> bool>, None)
}

Expand Down Expand Up @@ -6999,7 +7012,7 @@ impl AccountsDb {
}

pub fn flush_accounts_cache_slot_for_tests(&self, slot: Slot) {
self.flush_slot_cache(slot);
self.flush_slot_cache_with_clean(slot, None::<&mut fn(&_) -> bool>, None);
}

/// useful to adapt tests written prior to introduction of the write cache
Expand Down
4 changes: 2 additions & 2 deletions accounts-db/src/accounts_db/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4496,7 +4496,7 @@ fn test_cache_flush_delayed_remove_unrooted_race() {
if flush_trial_start_receiver.recv().is_err() {
return;
}
db.flush_slot_cache(10);
db.flush_unrooted_slot_cache(10);
flush_done_sender.send(()).unwrap();
})
.unwrap()
Expand Down Expand Up @@ -4558,7 +4558,7 @@ fn test_cache_flush_remove_unrooted_race_multiple_slots() {
return;
}
for slot in 0..num_cached_slots {
db.flush_slot_cache(slot);
db.flush_unrooted_slot_cache(slot);
}
flush_done_sender.send(()).unwrap();
})
Expand Down
5 changes: 4 additions & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5486,7 +5486,10 @@ fn test_clean_nonrooted() {
test_utils::deposit(&bank1, &pubkey0, some_lamports).unwrap();
goto_end_of_slot(bank1.clone());
bank1.freeze();
bank1.flush_accounts_cache_slot_for_tests();
bank1
.accounts()
.accounts_db
.flush_unrooted_slot_cache(bank1.slot());

bank1.print_accounts_stats();

Expand Down
Loading