diff --git a/Cargo.lock b/Cargo.lock index ae09bcaefb8..f4b3d81014d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7197,6 +7197,7 @@ dependencies = [ "dashmap", "indexmap 2.12.1", "itertools 0.14.0", + "libc", "libsecp256k1", "log", "lz4", diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index 9d545184079..2125690a1c2 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -48,6 +48,7 @@ crossbeam-channel = { workspace = true } dashmap = { workspace = true, features = ["rayon", "raw-api"] } indexmap = { workspace = true } itertools = { workspace = true } +libc = { workspace = true } log = { workspace = true } lz4 = { workspace = true } memmap2 = { workspace = true } diff --git a/accounts-db/src/append_vec.rs b/accounts-db/src/append_vec.rs index f105516535a..319e8f0a16e 100644 --- a/accounts-db/src/append_vec.rs +++ b/accounts-db/src/append_vec.rs @@ -41,6 +41,7 @@ use { fs::{remove_file, File, OpenOptions}, io::{self, BufRead, Seek, SeekFrom, Write}, mem::{self, MaybeUninit}, + os::fd::{AsFd, AsRawFd}, path::{Path, PathBuf}, ptr, slice, sync::{ @@ -262,6 +263,12 @@ impl AppendVec { }) .unwrap(); + // tell the kernel that we expect to randomly access the file and not to bother using + // page cache and reading ahead + unsafe { + libc::posix_fadvise(data.as_fd().as_raw_fd(), 0, 0, libc::POSIX_FADV_RANDOM); + } + // Theoretical performance optimization: write a zero to the end of // the file so that we won't have to resize it later, which may be // expensive.