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 15, 2021
1 parent 0d58b5d commit 0899c06
Show file tree
Hide file tree
Showing 5 changed files with 42 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 @@ -2210,6 +2210,10 @@ impl AccountsDb {
reclaims_time.stop();
measure_all.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.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
12 changes: 10 additions & 2 deletions runtime/src/bucket_map_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,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 @@ -43,6 +43,8 @@ pub struct BucketMapHolder<T: IndexValue> {
startup: AtomicBool,

startup_worker_threads: Mutex<Option<AccountsIndexStorage<T>>>,
/// used as an input for cache retention
pub slot_for_caching: AtomicU64,
}

impl<T: IndexValue> Debug for BucketMapHolder<T> {
Expand Down Expand Up @@ -78,6 +80,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, storage: &AccountsIndexStorage<T>, value: bool) {
if value {
let num_threads = std::cmp::max(2, num_cpus::get() / 4);
Expand Down Expand Up @@ -161,6 +168,7 @@ impl<T: IndexValue> BucketMapHolder<T> {
startup: AtomicBool::default(),
mem_budget_mb,
startup_worker_threads: Mutex::default(),
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 @@ -186,6 +187,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 @@ -676,12 +676,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 0899c06

Please sign in to comment.