Skip to content

Commit

Permalink
Add config option to mlock the mmap'ed headers of the shard
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerfiliba committed Aug 22, 2024
1 parent 7c9c51a commit 3685777
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ parking_lot = "0.12.3"
uuid = { version = "1.10.0" }
rand = "0.8.5"
fslock = "0.2.1"
libc = "0.2.158"

[features]
whitebox_testing = []
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub struct Config {
pub max_concurrent_list_ops: u32, // number of keyed locks for concurrent list ops
pub truncate_up: bool, // whether or not to truncate up shard files to their max size (spare files)
pub clear_on_unsupported_version: bool, // whether or not to clear the DB if the version is unsupported
pub mlock_headers: bool, // whether or not to mlock the shard headers to RAM (POSIX only)
}

impl Default for Config {
Expand All @@ -121,6 +122,7 @@ impl Default for Config {
max_concurrent_list_ops: 64,
truncate_up: true,
clear_on_unsupported_version: false,
mlock_headers: true,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ impl Shard {

let mut mmap = unsafe { MmapOptions::new().len(HEADER_SIZE as usize).map_mut(&file) }?;

if cfg!(target_family = "unix") {
unsafe { libc::mlock(mmap.as_ptr() as *const _, mmap.len()) };
}

let header = unsafe { &mut *(mmap.as_mut_ptr() as *mut ShardHeader) };
header.metadata.magic = SHARD_FILE_MAGIC;
header.metadata.version = SHARD_FILE_VERSION;
Expand Down

0 comments on commit 3685777

Please sign in to comment.