next.js
83ae8ad6 - Set DontFork and Unmergeable on all mmap sites in turbo-persistence (#90941)

Commit
163 days ago
Set DontFork and Unmergeable on all mmap sites in turbo-persistence (#90941) ## Summary - Add `madvise(MADV_DONTFORK)` and `madvise(MADV_UNMERGEABLE)` to all mmap sites in turbo-persistence - Extract a shared `advise_mmap_for_persistence` helper into a dedicated `mmap_helper` module ## Why `read_blob` in `db.rs` already correctly sets `DontFork` and `Unmergeable` on its mmap, but three other mmap sites were missing these flags: - **`static_sorted_file.rs`** (`open_internal`) — SST file mmaps used for lookups and compaction - **`meta_file.rs`** (`open_internal`) — meta file mmaps storing AMQF filters and SST metadata - **`sst_inspect.rs`** (`analyze_sst_file`) — diagnostic tool mmap `MADV_DONTFORK` prevents mmap regions from being copied into child processes on `fork()`, avoiding unnecessary memory duplication and potential SIGBUS issues if the parent unmaps before the child accesses the page. `MADV_UNMERGEABLE` opts the pages out of KSM (Kernel Same-page Merging), avoiding the overhead of scanning these pages for deduplication since they contain unique compressed data. Both flags are Linux-only (`#[cfg(target_os = "linux")]`), matching the existing pattern in `read_blob`. ## Implementation Rather than duplicating `#[cfg(target_os = "linux")]` madvise calls at each mmap site, a shared helper `advise_mmap_for_persistence()` is extracted into `src/mmap_helper.rs`. The function applies both flags on Linux and is a no-op on other platforms. All four mmap sites (`db.rs`, `static_sorted_file.rs`, `meta_file.rs`, `sst_inspect.rs`) now call this single helper. ## Test Plan - `cargo check -p turbo-persistence` passes - `cargo fmt` clean - No behavioral change on non-Linux platforms (flags are gated behind `#[cfg(target_os = "linux")]`)
Author
Parents
Loading