From aab12c31c7bfa7060f1a94b0cd27dfaef8c08b7e Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Mon, 11 Dec 2023 15:45:35 -0600 Subject: [PATCH] tune ancient append vec size to 128M (#34067) * 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 --- accounts-db/src/ancient_append_vecs.rs | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/accounts-db/src/ancient_append_vecs.rs b/accounts-db/src/ancient_append_vecs.rs index 0b567da483f3d3..4566a8923924d2 100644 --- a/accounts-db/src/ancient_append_vecs.rs +++ b/accounts-db/src/ancient_append_vecs.rs @@ -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? @@ -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]