Skip to content

Commit

Permalink
tune ancient append vec size to 128M (#34067)
Browse files Browse the repository at this point in the history
* tune ancient append vec size to 130M

* fix a test and get rid of the assert since it is covered in the test

* use 128M

* assert max append vec size for ancient append vec

---------

Co-authored-by: HaoranYi <haoran.yi@solana.com>
  • Loading branch information
HaoranYi and HaoranYi authored Dec 11, 2023
1 parent 967f1cd commit aab12c3
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,26 @@ impl<'a> AccountsToStore<'a> {
}

/// capacity of an ancient append vec
pub fn get_ancient_append_vec_capacity() -> u64 {
#[allow(clippy::assertions_on_constants, dead_code)]
pub const fn get_ancient_append_vec_capacity() -> u64 {
// There is a trade-off for selecting the ancient append vec size. Smaller non-ancient append vec are getting
// combined into large ancient append vec. Too small size of ancient append vec will result in too many ancient append vec
// memory mapped files. Too big size will make it difficult to clean and shrink them. Hence, we choose approximately
// 128MB for the ancient append vec size.
const RESULT: u64 = 128 * 1024 * 1024;

use crate::append_vec::MAXIMUM_APPEND_VEC_FILE_SIZE;
// smaller than max by a bit just in case
// some functions add slop on allocation
// The bigger an append vec is, the more unwieldy it becomes to shrink, create, write.
// 1/10 of max is a reasonable size in practice.
MAXIMUM_APPEND_VEC_FILE_SIZE / 10 - 2048
const _: () = assert!(
RESULT < MAXIMUM_APPEND_VEC_FILE_SIZE,
"ancient append vec size should be less than the maximum append vec size"
);
const PAGE_SIZE: u64 = 4 * 1024;
const _: () = assert!(
RESULT % PAGE_SIZE == 0,
"ancient append vec size should be a multiple of PAGE_SIZE"
);

RESULT
}

/// is this a max-size append vec designed to be used as an ancient append vec?
Expand Down Expand Up @@ -2078,10 +2091,7 @@ pub mod tests {

#[test]
fn test_get_ancient_append_vec_capacity() {
assert_eq!(
get_ancient_append_vec_capacity(),
crate::append_vec::MAXIMUM_APPEND_VEC_FILE_SIZE / 10 - 2048
);
assert_eq!(get_ancient_append_vec_capacity(), 128 * 1024 * 1024);
}

#[test]
Expand Down

0 comments on commit aab12c3

Please sign in to comment.