Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dmakarov committed Oct 1, 2024
1 parent 9d9c67b commit f865192
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ const MAX_ITEMS_PER_CHUNK: Slot = 2_500;
// This allows us to split up accounts index accesses across multiple threads.
const SHRINK_COLLECT_CHUNK_SIZE: usize = 50;

/// The number of shrink candidate slots that is small enough so that
/// additional storages from ancient slots can be added to the
/// candidates for shrinking.
const SHRINK_INSERT_ANCIENT_THRESHOLD: usize = 10;

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum CreateAncientStorage {
/// ancient storages are created by appending
Expand Down Expand Up @@ -2059,13 +2064,13 @@ impl ShrinkStats {
(
"ancient_slots_added_to_shrink",
self.ancient_slots_added_to_shrink
.swap(0, Ordering::Relaxed) as i64,
.swap(0, Ordering::Relaxed),
i64
),
(
"ancient_bytes_added_to_shrink",
self.ancient_bytes_added_to_shrink
.swap(0, Ordering::Relaxed) as i64,
.swap(0, Ordering::Relaxed),
i64
),
(
Expand Down Expand Up @@ -2516,7 +2521,6 @@ impl AccountsDb {
const ACCOUNTS_STACK_SIZE: usize = 8 * 1024 * 1024;

AccountsDb {
best_ancient_slots_to_shrink: RwLock::default(),
create_ancient_storage: CreateAncientStorage::default(),
verify_accounts_hash_in_bg: VerifyAccountsHashInBackground::default(),
active_stats: ActiveStats::default(),
Expand Down Expand Up @@ -2580,6 +2584,7 @@ impl AccountsDb {
epoch_accounts_hash_manager: EpochAccountsHashManager::new_invalid(),
test_skip_rewrites_but_include_in_bank_hash: false,
latest_full_snapshot_slot: SeqLock::new(None),
best_ancient_slots_to_shrink: RwLock::default(),
}
}

Expand Down Expand Up @@ -5122,7 +5127,7 @@ impl AccountsDb {
let mut ancient_slots_added = 0;
// If there are too few slots to shrink, add an ancient slot
// for shrinking.
if shrink_slots.len() < 10 {
if shrink_slots.len() < SHRINK_INSERT_ANCIENT_THRESHOLD {
let mut ancients = self.best_ancient_slots_to_shrink.write().unwrap();
if let Some((slot, capacity)) = ancients.first_mut() {
if let Some(store) = self.storage.get_slot_storage_entry(*slot) {
Expand All @@ -5132,15 +5137,11 @@ impl AccountsDb {
{
*capacity = 0;
ancient_slots_added += 1;
let ancient_bytes_added_to_shrink = store.alive_bytes() as u64;
shrink_slots.insert(*slot, store);
self.shrink_stats
.ancient_bytes_added_to_shrink
.fetch_add(store.alive_bytes() as u64, Ordering::Relaxed);
shrink_slots.insert(*slot, store);
log::debug!(
"ancient_slots_added: {ancient_slots_added}, {}, avail: {}",
shrink_slots.len(),
ancients.len()
);
.fetch_add(ancient_bytes_added_to_shrink, Ordering::Relaxed);
self.shrink_stats
.ancient_slots_added_to_shrink
.fetch_add(ancient_slots_added, Ordering::Relaxed);
Expand Down

0 comments on commit f865192

Please sign in to comment.