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#[cfg(target_os = "linux")]
6pub fn advise_mmap_for_persistence(mmap: &memmap2::Mmap) -> anyhow::Result<()> {
7 use anyhow::Context;
8 mmap.advise(memmap2::Advice::DontFork)
9 .context("Failed to advise mmap DontFork")?;
10 Ok(())
11}
12
13#[cfg(not(target_os = "linux"))]
14pub fn advise_mmap_for_persistence(_mmap: &memmap2::Mmap) -> anyhow::Result<()> {
15 Ok(())
16}