From 1d13594c1cb567b8b26e1fb4b173712b429cccf3 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Thu, 23 Sep 2021 19:56:44 -0500 Subject: [PATCH] AcctIdx: store # threads in BucketHolder. Used later. (#20151) --- runtime/src/accounts_index_storage.rs | 14 +++++++------- runtime/src/bucket_map_holder.rs | 16 ++++++++-------- runtime/src/in_mem_accounts_index.rs | 1 + 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/runtime/src/accounts_index_storage.rs b/runtime/src/accounts_index_storage.rs index 911fa53efc..9781d702df 100644 --- a/runtime/src/accounts_index_storage.rs +++ b/runtime/src/accounts_index_storage.rs @@ -44,19 +44,19 @@ impl Drop for AccountsIndexStorage { impl AccountsIndexStorage { pub fn new(bins: usize, config: &Option) -> AccountsIndexStorage { - let storage = Arc::new(BucketMapHolder::new(bins, config)); - - let in_mem = (0..bins) - .into_iter() - .map(|bin| Arc::new(InMemAccountsIndex::new(&storage, bin))) - .collect::>(); - const DEFAULT_THREADS: usize = 1; // soon, this will be a cpu calculation let threads = config .as_ref() .and_then(|config| config.flush_threads) .unwrap_or(DEFAULT_THREADS); + let storage = Arc::new(BucketMapHolder::new(bins, config, threads)); + + let in_mem = (0..bins) + .into_iter() + .map(|bin| Arc::new(InMemAccountsIndex::new(&storage, bin))) + .collect::>(); + let exit = Arc::new(AtomicBool::default()); let handles = Some( (0..threads) diff --git a/runtime/src/bucket_map_holder.rs b/runtime/src/bucket_map_holder.rs index d06109ded6..58ac85dafb 100644 --- a/runtime/src/bucket_map_holder.rs +++ b/runtime/src/bucket_map_holder.rs @@ -28,6 +28,8 @@ pub struct BucketMapHolder { next_bucket_to_flush: Mutex, bins: usize, + _threads: usize, + // how much mb are we allowed to keep in the in-mem index? // Rest goes to disk. pub mem_budget_mb: Option, @@ -38,7 +40,6 @@ pub struct BucketMapHolder { /// and writing to disk in parallel are. /// Note startup is an optimization and is not required for correctness. startup: AtomicBool, - _phantom: std::marker::PhantomData, } impl Debug for BucketMapHolder { @@ -113,7 +114,7 @@ impl BucketMapHolder { } } - pub fn new(bins: usize, config: &Option) -> Self { + pub fn new(bins: usize, config: &Option, threads: usize) -> Self { const DEFAULT_AGE_TO_STAY_IN_CACHE: Age = 5; let ages_to_stay_in_cache = config .as_ref() @@ -125,7 +126,6 @@ impl BucketMapHolder { let mem_budget_mb = config.as_ref().and_then(|config| config.index_limit_mb); // only allocate if mem_budget_mb is Some let disk = mem_budget_mb.map(|_| BucketMap::new(bucket_config)); - Self { disk, ages_to_stay_in_cache, @@ -138,7 +138,7 @@ impl BucketMapHolder { bins, startup: AtomicBool::default(), mem_budget_mb, - _phantom: std::marker::PhantomData::::default(), + _threads: threads, } } @@ -195,7 +195,7 @@ pub mod tests { fn test_next_bucket_to_flush() { solana_logger::setup(); let bins = 4; - let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default())); + let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default()), 1); let visited = (0..bins) .into_iter() .map(|_| AtomicUsize::default()) @@ -219,7 +219,7 @@ pub mod tests { fn test_age_increment() { solana_logger::setup(); let bins = 4; - let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default())); + let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default()), 1); for age in 0..513 { assert_eq!(test.current_age(), (age % 256) as Age); @@ -239,7 +239,7 @@ pub mod tests { fn test_age_time() { solana_logger::setup(); let bins = 1; - let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default())); + let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default()), 1); let threads = 2; let time = AGE_MS * 5 / 2; let expected = (time / AGE_MS) as Age; @@ -259,7 +259,7 @@ pub mod tests { fn test_age_broad() { solana_logger::setup(); let bins = 4; - let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default())); + let test = BucketMapHolder::::new(bins, &Some(AccountsIndexConfig::default()), 1); assert_eq!(test.current_age(), 0); for _ in 0..bins { assert!(!test.all_buckets_flushed_at_current_age()); diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 69c2e7fd23..7c595cc22c 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -717,6 +717,7 @@ mod tests { let holder = Arc::new(BucketMapHolder::new( BINS_FOR_TESTING, &Some(AccountsIndexConfig::default()), + 1, )); let bin = 0; InMemAccountsIndex::new(&holder, bin)