Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop padding new append vecs to page size #33658

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5733,11 +5733,7 @@ impl AccountsDb {
.create_store_count
.fetch_add(1, Ordering::Relaxed);
let path_index = thread_rng().gen_range(0..paths.len());
let store = Arc::new(self.new_storage_entry(
slot,
Path::new(&paths[path_index]),
Self::page_align(size),
));
let store = Arc::new(self.new_storage_entry(slot, Path::new(&paths[path_index]), size));

debug!(
"creating store: {} slot: {} len: {} size: {} from: {} path: {:?}",
Expand Down Expand Up @@ -15054,16 +15050,13 @@ pub mod tests {
let account1 = AccountSharedData::new(1, 0, AccountSharedData::default().owner());

// Store into slot 0
db.store_cached((0, &[(&account_key1, &account1)][..]), None);
db.store_cached((0, &[(&account_key2, &account1)][..]), None);
// This has to be done uncached since we are trying to add another account to the append vec AFTER it has been flushed.
// This doesn't work if the flush creates an append vec of exactly the right size.
// Normal operations NEVER write the same account to the same append vec twice during a write cache flush.
db.store_uncached(0, &[(&account_key1, &account1)][..]);
db.store_uncached(0, &[(&account_key2, &account1)][..]);
db.add_root(0);
if !do_intra_cache_clean {
// If we don't want the cache doing purges before flush,
// then we cannot flush multiple roots at once, otherwise the later
// roots will clean the earlier roots before they are stored.
// Thus flush the roots individually
db.flush_accounts_cache(true, None);

// Add an additional ref within the same slot to pubkey 1
db.store_uncached(0, &[(&account_key1, &account1)]);
}
Expand Down Expand Up @@ -17391,17 +17384,14 @@ pub mod tests {
assert_eq!(shrink_collect.aligned_total_bytes, 0);
assert_eq!(shrink_collect.alive_total_bytes, 0);
}
// these constants are multiples of page size (4096).
// They are determined by what size append vec gets created when the write cache is flushed to an append vec.
// Thus, they are dependent on the # of accounts that are written. They were identified by hitting the asserts and noting the value
// for shrink_collect.original_bytes at each account_count and then encoding it here.
let expected_capacity = if account_count >= 100 {
16384
} else if account_count >= 50 {
8192
} else {
4096
};
// expected_capacity is determined by what size append vec gets created when the write cache is flushed to an append vec.
let mut expected_capacity =
(account_count * aligned_stored_size(space)) as u64;
if append_opposite_zero_lamport_account && space != 0 {
// zero lamport accounts always write space = 0
expected_capacity -= space as u64;
}

assert_eq!(shrink_collect.capacity, expected_capacity);
assert_eq!(shrink_collect.total_starting_accounts, account_count);
let mut expected_all_are_zero_lamports = lamports == 0;
Expand Down