feat: wire MacosWriter into the disk-commit dispatcher#4018
Merged
Conversation
Adds a Writer::Macos variant guarded by #[cfg(target_os = "macos")] and extends make_writer with a matching arm so non-sparse, append_offset=0 writes on macOS go through fast_io::MacosWriter. The new path pairs F_NOCACHE (for files >= 1 MiB) with writev(2) scatter-gather flushes (up to 64 iovecs per syscall), eliminating page-cache pollution on tree-wide transfers larger than RAM and batching more buffers per syscall than ReusableBufWriter's one-or-two-iovec ceiling. Sparse mode and append mode continue to use ReusableBufWriter because both require Seek, which MacosWriter does not implement (it issues writes from the current position without preserving the seek). The gate mirrors the existing io_uring and IOCP arms. Also adds a MacosWriter::sync() helper that drains pending writev buffers and fsyncs the underlying file, so the dispatcher's flush_and_sync(do_fsync, ...) path keeps its existing semantics.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
Adds a Writer::Macos variant guarded by #[cfg(target_os = "macos")] and extends make_writer with a matching arm so non-sparse, append_offset=0 writes on macOS go through fast_io::MacosWriter. The new path pairs F_NOCACHE (for files >= 1 MiB) with writev(2) scatter-gather flushes (up to 64 iovecs per syscall), eliminating page-cache pollution on tree-wide transfers larger than RAM and batching more buffers per syscall than ReusableBufWriter's one-or-two-iovec ceiling. Sparse mode and append mode continue to use ReusableBufWriter because both require Seek, which MacosWriter does not implement (it issues writes from the current position without preserving the seek). The gate mirrors the existing io_uring and IOCP arms. Also adds a MacosWriter::sync() helper that drains pending writev buffers and fsyncs the underlying file, so the dispatcher's flush_and_sync(do_fsync, ...) path keeps its existing semantics.
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
Writer::Macos(MacosWriter)variant incrates/transfer/src/disk_commit/writer.rs, guarded by#[cfg(target_os = "macos")].make_writerincrates/transfer/src/disk_commit/process.rswith a macOS arm that wraps the per-fileFileinfast_io::MacosWriter::from_file(file, target_size)when!use_sparse && append_offset == 0, mirroring the existing io_uring and IOCP arms.MacosWriter::sync()so the dispatcher'sflush_and_sync(do_fsync, ...)can drain pendingwritevbuffers andfsyncthe underlying file.Motivation
MacosWriter(crates/fast_io/src/macos_io.rs) has shipped for a while: it pairsF_NOCACHE(above the 1 MiB threshold) withwritev(2)flushes (up to 64 iovecs). It is re-exported fromcrates/fast_io/src/lib.rs, but the disk-commit thread still constructsReusableBufWriterdirectly on macOS, so the optimization has zero callers in the workspace.The audit at
docs/audits/macos-fastio-fallback.md(PR #4008, task #1652) called out this gap and recommended exactly the wiring in this PR as the fix for #1657.Behaviour
append_offset == 0: routes throughWriter::Macos(MacosWriter). Files >= 1 MiB getF_NOCACHE(page-cache bypass for tree-wide transfers larger than RAM); writes >= 256 KiB flush viawritevcovering up to 64 iovecs per syscall.append_offset != 0: falls through toWriter::Buffered(ReusableBufWriter).MacosWriterdoes not implementSeekand would not preserve the file position used by sparse/append mode.Writer::Macosdoes not exist off-target.Test plan
cargo nextest run -p transferon macOS picks upmake_writer_selects_macos_for_non_sparse_zero_offsetandmake_writer_falls_back_to_buffered_when_seek_required.#[cfg(target_os = "macos")]and the dispatcher signature only adds asize_hint: u64parameter.References
docs/audits/macos-fastio-fallback.md(PR docs: audit macOS fast_io fallback vs Linux io_uring (#1652) #4008).F_NOCACHE+writevinto disk-commit.