diff --git a/Cargo.lock b/Cargo.lock index cd55b720c65e2b..bf9cb8cfd56845 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4898,6 +4898,7 @@ name = "solana-bucket-map" version = "1.15.0" dependencies = [ "fs_extra", + "lazy_static", "log", "memmap2", "modular-bitfield", diff --git a/bucket_map/Cargo.toml b/bucket_map/Cargo.toml index 40f91d60b8fcf0..7fd2eb901efaf2 100644 --- a/bucket_map/Cargo.toml +++ b/bucket_map/Cargo.toml @@ -11,6 +11,7 @@ license = "Apache-2.0" edition = "2021" [dependencies] +lazy_static = "1.4.0" log = { version = "0.4.17" } memmap2 = "0.5.3" modular-bitfield = "0.11.2" diff --git a/bucket_map/src/bucket_map.rs b/bucket_map/src/bucket_map.rs index 02666316f55a4a..ef239270927fe7 100644 --- a/bucket_map/src/bucket_map.rs +++ b/bucket_map/src/bucket_map.rs @@ -3,10 +3,20 @@ use { crate::{bucket_api::BucketApi, bucket_stats::BucketMapStats, MaxSearch, RefCount}, solana_sdk::pubkey::Pubkey, - std::{convert::TryInto, fmt::Debug, fs, path::PathBuf, sync::Arc}, + std::{ + convert::TryInto, + fmt::Debug, + fs, + path::PathBuf, + sync::{atomic::AtomicU64, Arc}, + }, tempfile::TempDir, }; +lazy_static! { + pub static ref ACCOUNT_INDEX_MMAPPED_FILES_OPEN: AtomicU64 = AtomicU64::default(); +} + #[derive(Debug, Default, Clone)] pub struct BucketMapConfig { pub max_buckets: usize, diff --git a/bucket_map/src/bucket_storage.rs b/bucket_map/src/bucket_storage.rs index dac4e9b11caf03..c418721f8e14ab 100644 --- a/bucket_map/src/bucket_storage.rs +++ b/bucket_map/src/bucket_storage.rs @@ -1,5 +1,5 @@ use { - crate::{bucket_stats::BucketStats, MaxSearch}, + crate::{bucket_map::ACCOUNT_INDEX_MMAPPED_FILES_OPEN, bucket_stats::BucketStats, MaxSearch}, memmap2::MmapMut, rand::{thread_rng, Rng}, solana_measure::measure::Measure, @@ -92,6 +92,7 @@ pub enum BucketStorageError { impl Drop for BucketStorage { fn drop(&mut self) { let _ = remove_file(&self.path); + ACCOUNT_INDEX_MMAPPED_FILES_OPEN.fetch_sub(1, Ordering::Relaxed); } } @@ -107,6 +108,7 @@ impl BucketStorage { ) -> Self { let cell_size = elem_size * num_elems + std::mem::size_of::
() as u64; let (mmap, path) = Self::new_map(&drives, cell_size as usize, capacity_pow2, &stats); + ACCOUNT_INDEX_MMAPPED_FILES_OPEN.fetch_add(1, Ordering::Relaxed); Self { path, mmap, diff --git a/bucket_map/src/lib.rs b/bucket_map/src/lib.rs index a61cae4e36817a..0a92aa8e49dee4 100644 --- a/bucket_map/src/lib.rs +++ b/bucket_map/src/lib.rs @@ -1,4 +1,8 @@ #![allow(clippy::integer_arithmetic)] + +#[macro_use] +extern crate lazy_static; + mod bucket; pub mod bucket_api; mod bucket_item; diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 03446bfa495cf0..58ddf98c51cb8c 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4333,6 +4333,7 @@ dependencies = [ name = "solana-bucket-map" version = "1.15.0" dependencies = [ + "lazy_static", "log", "memmap2", "modular-bitfield", diff --git a/runtime/src/bucket_map_holder_stats.rs b/runtime/src/bucket_map_holder_stats.rs index 15cdf826d642fc..87b851249d1b6b 100644 --- a/runtime/src/bucket_map_holder_stats.rs +++ b/runtime/src/bucket_map_holder_stats.rs @@ -1,5 +1,6 @@ use { crate::{accounts_index::IndexValue, bucket_map_holder::BucketMapHolder}, + solana_bucket_map::bucket_map::ACCOUNT_INDEX_MMAPPED_FILES_OPEN, solana_sdk::timing::AtomicInterval, std::{ fmt::Debug, @@ -478,6 +479,11 @@ impl BucketMapHolderStats { .swap(0, Ordering::Relaxed), i64 ), + ( + "account_index_mmap_open", + ACCOUNT_INDEX_MMAPPED_FILES_OPEN.load(Ordering::Relaxed) as i64, + i64 + ), ); } else { datapoint_info!( @@ -573,6 +579,11 @@ impl BucketMapHolderStats { ("items", self.items.swap(0, Ordering::Relaxed), i64), ("items_us", self.items_us.swap(0, Ordering::Relaxed), i64), ("keys", self.keys.swap(0, Ordering::Relaxed), i64), + ( + "account_index_mmap_open", + ACCOUNT_INDEX_MMAPPED_FILES_OPEN.load(Ordering::Relaxed) as i64, + i64 + ), ); } }