Set DontFork and Unmergeable on all mmap sites in turbo-persistence#90941
Merged
lukesandberg merged 3 commits intocanaryfrom Mar 6, 2026
Merged
Set DontFork and Unmergeable on all mmap sites in turbo-persistence#90941lukesandberg merged 3 commits intocanaryfrom
lukesandberg merged 3 commits intocanaryfrom
Conversation
Previously only read_blob set these madvise flags. Apply them consistently to SST file, meta file, and sst_inspect mmaps as well.
lukesandberg
reviewed
Mar 5, 2026
lukesandberg
approved these changes
Mar 5, 2026
Merging this PR will not alter performance
Comparing Footnotes
|
Collaborator
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles: **401 kB** → **401 kB** ✅ -14 B80 files with content-based hashes (individual files not comparable between builds) Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
bgw
approved these changes
Mar 5, 2026
Member
|
We should apply all these flags in a single helper function? |
Move duplicated DontFork + Unmergeable madvise calls into a shared helper function in a dedicated mmap_helper module. All mmap sites (db.rs, static_sorted_file.rs, meta_file.rs, sst_inspect.rs) now call this single function instead of inlining the cfg-gated advise calls.
Collaborator
Tests Passed |
Contributor
Merge activity
|
sokra
added a commit
that referenced
this pull request
Mar 6, 2026
…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")]`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
madvise(MADV_DONTFORK)andmadvise(MADV_UNMERGEABLE)to all mmap sites in turbo-persistenceadvise_mmap_for_persistencehelper into a dedicatedmmap_helpermoduleWhy
read_blobindb.rsalready correctly setsDontForkandUnmergeableon its mmap, but three other mmap sites were missing these flags:static_sorted_file.rs(open_internal) — SST file mmaps used for lookups and compactionmeta_file.rs(open_internal) — meta file mmaps storing AMQF filters and SST metadatasst_inspect.rs(analyze_sst_file) — diagnostic tool mmapMADV_DONTFORKprevents mmap regions from being copied into child processes onfork(), avoiding unnecessary memory duplication and potential SIGBUS issues if the parent unmaps before the child accesses the page.MADV_UNMERGEABLEopts 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 inread_blob.Implementation
Rather than duplicating
#[cfg(target_os = "linux")]madvise calls at each mmap site, a shared helperadvise_mmap_for_persistence()is extracted intosrc/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-persistencepassescargo fmtclean#[cfg(target_os = "linux")])