Skip to content

Commit

Permalink
AcctIdx: set_slot_for_caching
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Oct 13, 2021
1 parent 215c8af commit 8996a2c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
4 changes: 4 additions & 0 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,10 @@ impl AccountsDb {

reclaims_time.stop();

if let Some(slot) = max_clean_root {
self.accounts_index.set_slot_for_caching(slot);
}

self.clean_accounts_stats.report();
datapoint_info!(
"clean_accounts",
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,11 @@ impl<T: IndexValue> AccountsIndex<T> {
self.storage.storage.set_startup(value);
}

/// tell the accounts index the slot above which accounts index entries should be cached
pub fn set_slot_for_caching(&self, slot: Slot) {
self.storage.storage.set_slot_for_caching(slot);
}

/// Get an account
/// The latest account that appears in `ancestors` or `roots` is returned.
pub(crate) fn get(
Expand Down
13 changes: 11 additions & 2 deletions runtime/src/bucket_map_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::in_mem_accounts_index::{InMemAccountsIndex, SlotT};
use crate::waitable_condvar::WaitableCondvar;
use solana_bucket_map::bucket_map::{BucketMap, BucketMapConfig};
use solana_measure::measure::Measure;
use solana_sdk::clock::SLOT_MS;
use solana_sdk::clock::{Slot, SLOT_MS};
use solana_sdk::timing::AtomicInterval;
use std::fmt::Debug;
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicU8, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::time::Duration;
pub type Age = u8;
Expand Down Expand Up @@ -40,6 +40,9 @@ pub struct BucketMapHolder<T: IndexValue> {
/// and writing to disk in parallel are.
/// Note startup is an optimization and is not required for correctness.
startup: AtomicBool,

/// used as an input for cache retention
pub slot_for_caching: AtomicU64,
}

impl<T: IndexValue> Debug for BucketMapHolder<T> {
Expand Down Expand Up @@ -75,6 +78,11 @@ impl<T: IndexValue> BucketMapHolder<T> {
self.startup.load(Ordering::Relaxed)
}

/// tell the accounts index the slot above which accounts index entries should be cached
pub fn set_slot_for_caching(&self, slot: Slot) {
self.slot_for_caching.store(slot, Ordering::Relaxed);
}

pub fn set_startup(&self, value: bool) {
if !value {
self.wait_for_idle();
Expand Down Expand Up @@ -151,6 +159,7 @@ impl<T: IndexValue> BucketMapHolder<T> {
bins,
startup: AtomicBool::default(),
mem_budget_mb,
slot_for_caching: AtomicU64::new(u64::MAX),
_threads: threads,
}
}
Expand Down
6 changes: 6 additions & 0 deletions runtime/src/bucket_map_holder_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const STATS_INTERVAL_MS: u64 = 10_000;
pub struct BucketMapHolderStats {
pub held_in_mem_slot_list_len: AtomicU64,
pub held_in_mem_slot_list_cached: AtomicU64,
pub held_in_mem_slot: AtomicU64,
pub get_mem_us: AtomicU64,
pub gets_from_mem: AtomicU64,
pub get_missing_us: AtomicU64,
Expand Down Expand Up @@ -178,6 +179,11 @@ impl BucketMapHolderStats {
self.held_in_mem_slot_list_cached.swap(0, Ordering::Relaxed),
i64
),
(
"held_in_mem_slot",
self.held_in_mem_slot.swap(0, Ordering::Relaxed),
i64
),
("min_in_bin_mem", in_mem_stats.0, i64),
("max_in_bin_mem", in_mem_stats.1, i64),
("count_from_bins_mem", in_mem_stats.2, i64),
Expand Down
23 changes: 17 additions & 6 deletions runtime/src/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,23 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
}
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
let remove = !slot_list.iter().any(|(_, info)| info.is_cached());
if !remove && update_stats {
Self::update_stat(&self.stats().held_in_mem_slot_list_cached, 1);
}
remove
!slot_list.iter().any(|(slot, info)| {
if info.is_cached() {
// keep items with slot lists that contained cached items
if update_stats {
Self::update_stat(&self.stats().held_in_mem_slot_list_cached, 1);
}
true
} else if slot >= &self.storage.slot_for_caching.load(Ordering::Relaxed) {
// keep items with entries where slot >= slot_for_caching
if update_stats {
Self::update_stat(&self.stats().held_in_mem_slot, 1);
}
true
} else {
false
}
})
}
} else {
false
Expand Down

0 comments on commit 8996a2c

Please sign in to comment.