turbo_persistence/mmap_helper.rs
1/// Apply Linux-specific mmap advice flags that should be set on all persistent mmaps.
2///
3/// - `DontFork`: prevents mmap regions from being copied into child processes on `fork()`, avoiding
4/// unnecessary memory duplication and potential SIGBUS.
5/// - `Unmergeable`: opts pages out of KSM (Kernel Same-page Merging) since our data is unique
6/// compressed content that won't benefit from deduplication scanning.
7#[cfg(target_os = "linux")]
8pub fn advise_mmap_for_persistence(mmap: &memmap2::Mmap) -> anyhow::Result<()> {
9 mmap.advise(memmap2::Advice::DontFork)?;
10 mmap.advise(memmap2::Advice::Unmergeable)?;
11 Ok(())
12}
13
14#[cfg(not(target_os = "linux"))]
15pub fn advise_mmap_for_persistence(_mmap: &memmap2::Mmap) -> anyhow::Result<()> {
16 Ok(())
17}