fs: add macOS F_RDADVISE + micro-prefetch to accelerate SwiftCompile reads#2348
Closed
erneestoc wants to merge 2 commits into
Closed
fs: add macOS F_RDADVISE + micro-prefetch to accelerate SwiftCompile reads#2348erneestoc wants to merge 2 commits into
erneestoc wants to merge 2 commits into
Conversation
Adds two best-effort kernel page-cache hints to FileSlot:
* `advise_sequential()` — Linux uses `posix_fadvise(SEQUENTIAL)`,
macOS issues `F_RDADVISE` over the first 4 MiB to kick off
readahead (the documented analogue), no-op elsewhere.
* `advise_willneed(offset, len)` — Linux uses
`posix_fadvise(WILLNEED)`, macOS uses `fcntl(F_RDADVISE)` with a
locally-declared `radvisory` struct (not exposed by the `libc`
crate), no-op elsewhere.
Wired into the read path:
* `filesystem_store::get_part` calls `advise_sequential` after the
file is opened and micro-prefetches the next two buffer-sized
chunks inside the read loop so kernel readahead overlaps with the
network send.
* `slow_update_store_with_file` does the same when streaming a
local file into a store.
* `directory_cache::get_or_create` fires a tokio task after each
successful cache-hit hardlink to walk the freshly-materialized
tree and `advise_willneed` every file, warming the page cache
before the action that triggered the materialization starts
reading.
For the macOS Mac-Mini iOS workload (SwiftCompile dominates, p95
input ~466 MB) this is a direct attack on read-side wall time and
complements the clonefile work landed in PR TraceMachina#2338. The Linux paths
use the existing `posix_fadvise` infrastructure for symmetry.
Tests: cross-platform smoke test that the helpers compile to
no-op-or-real on every target, plus a macOS-only test that drives
the raw `F_RDADVISE` fcntl directly and asserts it returns 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace raw tokio::spawn / tokio::task::spawn_blocking calls in directory_cache.rs with background_spawn! and spawn_blocking! from nativelink-util::task. The raw calls were tripping the workspace clippy::disallowed_methods lint and bypassing the tracing spans / OpenTelemetry context propagation the wrappers provide. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Adds macOS `F_RDADVISE` + sequential-read hints + page-cache warming to the worker's read paths. This is the read-side complement to the write-side optimizations in #2338's APFS `clonefile(2)` work — and the macOS equivalent of the Linux `POSIX_FADV_SEQUENTIAL` hint that's already used on this codepath.
For a Bazel SwiftCompile p95 input shape (~466 MB, ~1,978 files), the read side dominates wall time. `F_RDADVISE` tells the macOS kernel "I'm about to read this file sequentially" — enables aggressive readahead and removes per-syscall stalls.
What changes
Implementation notes
Tests
All 7 existing `fs` and `fs_util` tests pass.
Verification
Relationship to other work
🤖 Generated with Claude Code
This change is