diff --git a/runtime/src/bucket_map_holder.rs b/runtime/src/bucket_map_holder.rs index 9c22461ca7..791ed80bf8 100644 --- a/runtime/src/bucket_map_holder.rs +++ b/runtime/src/bucket_map_holder.rs @@ -2,7 +2,7 @@ use crate::accounts_index::{AccountsIndexConfig, IndexValue}; use crate::bucket_map_holder_stats::BucketMapHolderStats; use crate::waitable_condvar::WaitableCondvar; use std::fmt::Debug; -use std::sync::atomic::{AtomicU8, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering}; use std::sync::Mutex; pub type Age = u8; @@ -16,6 +16,12 @@ pub struct BucketMapHolder { pub wait_dirty_bucket: WaitableCondvar, next_bucket_to_flush: Mutex, bins: usize, + + /// startup is a special time for flush to focus on moving everything to disk as fast and efficiently as possible + /// with less thread count limitations. LRU and access patterns are not important. Freeing memory + /// and writing to disk in parallel are. + /// Note startup is an optimization and is not required for correctness. + startup: AtomicBool, _phantom: std::marker::PhantomData, } @@ -36,6 +42,15 @@ impl BucketMapHolder { assert!(previous >= self.bins); // we should not have increased age before previous age was fully flushed } + /// used by bg processes to determine # active threads and how aggressively to flush + pub fn get_startup(&self) -> bool { + self.startup.load(Ordering::Relaxed) + } + + pub fn set_startup(&self, value: bool) { + self.startup.store(value, Ordering::Relaxed) + } + pub fn current_age(&self) -> Age { self.age.load(Ordering::Relaxed) } @@ -57,6 +72,7 @@ impl BucketMapHolder { wait_dirty_bucket: WaitableCondvar::default(), next_bucket_to_flush: Mutex::new(0), bins, + startup: AtomicBool::default(), _phantom: std::marker::PhantomData::::default(), } }