Add accounts-filler-size command line option (#23896)

This commit is contained in:
Giorgio Gambino
2022-04-11 19:10:09 +01:00
committed by GitHub
parent eb478d72d1
commit 60b2155bd3
6 changed files with 83 additions and 33 deletions

View File

@@ -65,6 +65,7 @@ use {
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
pubkey::Pubkey,
rent::Rent,
timing::AtomicInterval,
},
std::{
@@ -128,14 +129,14 @@ const CACHE_VIRTUAL_STORED_SIZE: StoredSize = 0;
pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_TESTING),
accounts_hash_cache_path: None,
filler_account_count: None,
filler_accounts_config: FillerAccountsConfig::const_default(),
hash_calc_num_passes: None,
write_cache_limit_bytes: None,
};
pub const ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS: AccountsDbConfig = AccountsDbConfig {
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS),
accounts_hash_cache_path: None,
filler_account_count: None,
filler_accounts_config: FillerAccountsConfig::const_default(),
hash_calc_num_passes: None,
write_cache_limit_bytes: None,
};
@@ -148,11 +149,31 @@ pub struct AccountsAddRootTiming {
pub store_us: u64,
}
#[derive(Debug, Clone, Copy)]
pub struct FillerAccountsConfig {
/// Number of filler accounts
pub count: usize,
/// Data size per account, in bytes
pub size: usize,
}
impl FillerAccountsConfig {
pub const fn const_default() -> Self {
Self { count: 0, size: 0 }
}
}
impl Default for FillerAccountsConfig {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, Default, Clone)]
pub struct AccountsDbConfig {
pub index: Option<AccountsIndexConfig>,
pub accounts_hash_cache_path: Option<PathBuf>,
pub filler_account_count: Option<usize>,
pub filler_accounts_config: FillerAccountsConfig,
pub hash_calc_num_passes: Option<usize>,
pub write_cache_limit_bytes: Option<u64>,
}
@@ -1090,7 +1111,7 @@ pub struct AccountsDb {
/// GeyserPlugin accounts update notifier
accounts_update_notifier: Option<AccountsUpdateNotifier>,
filler_account_count: usize,
filler_accounts_config: FillerAccountsConfig,
pub filler_account_suffix: Option<Pubkey>,
active_stats: ActiveStats,
@@ -1633,7 +1654,7 @@ impl AccountsDb {
dirty_stores: DashMap::default(),
zero_lamport_accounts_to_purge_after_full_snapshot: DashSet::default(),
accounts_update_notifier: None,
filler_account_count: 0,
filler_accounts_config: FillerAccountsConfig::default(),
filler_account_suffix: None,
num_hash_scan_passes,
}
@@ -1677,11 +1698,13 @@ impl AccountsDb {
let accounts_hash_cache_path = accounts_db_config
.as_ref()
.and_then(|x| x.accounts_hash_cache_path.clone());
let filler_account_count = accounts_db_config
let filler_accounts_config = accounts_db_config
.as_ref()
.and_then(|cfg| cfg.filler_account_count)
.map(|config| config.filler_accounts_config)
.unwrap_or_default();
let filler_account_suffix = if filler_account_count > 0 {
let filler_account_suffix = if filler_accounts_config.count > 0 {
Some(solana_sdk::pubkey::new_rand())
} else {
None
@@ -1694,7 +1717,7 @@ impl AccountsDb {
caching_enabled,
shrink_ratio,
accounts_update_notifier,
filler_account_count,
filler_accounts_config,
filler_account_suffix,
write_cache_limit_bytes: accounts_db_config
.as_ref()
@@ -5741,7 +5764,7 @@ impl AccountsDb {
};
let hash = AccountsHash {
filler_account_suffix: if self.filler_account_count > 0 {
filler_account_suffix: if self.filler_accounts_config.count > 0 {
self.filler_account_suffix
} else {
None
@@ -6857,15 +6880,18 @@ impl AccountsDb {
/// The filler accounts are added to each slot in the snapshot after index generation.
/// The accounts added in a slot are setup to have pubkeys such that rent will be collected from them before (or when?) their slot becomes an epoch old.
/// Thus, the filler accounts are rewritten by rent and the old slot can be thrown away successfully.
pub fn maybe_add_filler_accounts(&self, epoch_schedule: &EpochSchedule) {
if self.filler_account_count == 0 {
pub fn maybe_add_filler_accounts(&self, epoch_schedule: &EpochSchedule, rent: &Rent) {
if self.filler_accounts_config.count == 0 {
return;
}
let max_root_inclusive = self.accounts_index.max_root_inclusive();
let epoch = epoch_schedule.get_epoch(max_root_inclusive);
info!("adding {} filler accounts", self.filler_account_count);
info!(
"adding {} filler accounts with size {}",
self.filler_accounts_config.count, self.filler_accounts_config.size,
);
// break this up to force the accounts out of memory after each pass
let passes = 100;
let mut roots = self.storage.all_slots();
@@ -6879,8 +6905,9 @@ impl AccountsDb {
let string = "FiLLERACCoUNTooooooooooooooooooooooooooooooo";
let hash = Hash::from_str(string).unwrap();
let owner = Pubkey::from_str(string).unwrap();
let lamports = 100_000_000;
let space = 0;
let space = self.filler_accounts_config.size;
let rent_exempt_reserve = rent.minimum_balance(space);
let lamports = rent_exempt_reserve;
let account = AccountSharedData::new(lamports, space, &owner);
let added = AtomicUsize::default();
for pass in 0..=passes {
@@ -6907,8 +6934,8 @@ impl AccountsDb {
let subrange = crate::bank::Bank::pubkey_range_from_partition(partition);
let idx = overall_index.fetch_add(1, Ordering::Relaxed);
let filler_entries = (idx + 1) * self.filler_account_count / root_count
- idx * self.filler_account_count / root_count;
let filler_entries = (idx + 1) * self.filler_accounts_config.count / root_count
- idx * self.filler_accounts_config.count / root_count;
let accounts = (0..filler_entries)
.map(|_| {
let my_id = added.fetch_add(1, Ordering::Relaxed);

View File

@@ -642,7 +642,7 @@ where
genesis_config,
);
accounts_db.maybe_add_filler_accounts(&genesis_config.epoch_schedule);
accounts_db.maybe_add_filler_accounts(&genesis_config.epoch_schedule, &genesis_config.rent);
handle.join().unwrap();
measure_notify.stop();