Skip to content

docs: audit macOS fast_io fallback vs Linux io_uring (#1652)#4008

Merged
oferchen merged 1 commit into
masterfrom
docs/macos-fastio-audit-1652
May 13, 2026
Merged

docs: audit macOS fast_io fallback vs Linux io_uring (#1652)#4008
oferchen merged 1 commit into
masterfrom
docs/macos-fastio-audit-1652

Conversation

@oferchen
Copy link
Copy Markdown
Owner

Summary

  • Adds docs/audits/macos-fastio-fallback.md, a static source-grounded audit of the macOS fallback path in crates/fast_io/ (closes Enforce coverage thresholds in CI #1652).
  • Maps every Linux io_uring entry point to its macOS equivalent (StdFileReader / StdFileWriter from crates/fast_io/src/traits.rs via the stub at crates/fast_io/src/io_uring_stub.rs, plus the PlatformCopy clonefile / fcopyfile chain at crates/fast_io/src/platform_copy/dispatch.rs).
  • Identifies one concrete unshipped win: the MacosWriter type at crates/fast_io/src/macos_io.rs:58 (F_NOCACHE >= 1 MiB plus writev with MAX_IOV_COUNT = 64) is implemented, exported from crates/fast_io/src/lib.rs:155, and has zero callers outside its own tests. Wiring it into make_writer at crates/transfer/src/disk_commit/process.rs:269 is a one-screen change.

Test plan

  • No code changes; doc-only PR.
  • cargo fmt --all -- --check (no Rust changes).
  • Render docs/audits/macos-fastio-fallback.md on GitHub and verify all in-repo paths and line refs resolve.

Static, source-grounded audit of the macOS fallback chain in
crates/fast_io/. Maps each Linux io_uring path to its macOS
equivalent, identifies that MacosWriter (F_NOCACHE + writev) is
implemented but unwired from the disk-commit dispatcher, and
recommends a one-screen fix in disk_commit/process.rs to deliver
the win.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 13, 2026
@oferchen oferchen merged commit c2bdbfc into master May 13, 2026
8 checks passed
oferchen added a commit that referenced this pull request May 14, 2026
Darwin ships a BSD-style sendfile(2) syscall, but the dispatch in
crates/fast_io/src/sendfile.rs only branched on Linux and fell
through to a read/write loop on every other unix target. The macOS
fast_io audit at docs/audits/macos-fastio-fallback.md flagged this
as one of two unshipped wins identified during the post-merge
review of PR #4008.

This change adds a target_os = "macos" arm in send_file_to_fd and
send_file_to_fd_with_policy that calls libc::sendfile with the
Darwin signature:

    int sendfile(int fd, int s, off_t offset, off_t *len,
                 struct sf_hdtr *hdtr, int flags);

The implementation handles the in/out `len` parameter (bytes to
send -> bytes actually sent), treats a return of 0 as success, and
preserves the "transfer from the current file position" contract
by querying the source offset with lseek(SEEK_CUR) and advancing
the position with lseek(SEEK_SET) after the transfer. Partial
sends on EAGAIN/EINTR are reported as forward progress so the
socket peer always sees a consistent prefix.

Non-socket destinations (pipes, regular files) fail with
ENOTSOCK; the dispatch transparently falls back to the buffered
read/write loop in that case, matching the behaviour Linux
already had for non-sendfile-capable targets.

Tests gated to target_os = "macos" exercise the new path through
a SOCK_STREAM socketpair (native sendfile fast path), the public
dispatch entry point, and a pipe destination that must fall back
to read/write.

Refs #2152.
@oferchen oferchen deleted the docs/macos-fastio-audit-1652 branch May 14, 2026 14:57
oferchen added a commit that referenced this pull request May 18, 2026
Static, source-grounded audit of the macOS fallback chain in
crates/fast_io/. Maps each Linux io_uring path to its macOS
equivalent, identifies that MacosWriter (F_NOCACHE + writev) is
implemented but unwired from the disk-commit dispatcher, and
recommends a one-screen fix in disk_commit/process.rs to deliver
the win.
oferchen added a commit that referenced this pull request May 18, 2026
Darwin ships a BSD-style sendfile(2) syscall, but the dispatch in
crates/fast_io/src/sendfile.rs only branched on Linux and fell
through to a read/write loop on every other unix target. The macOS
fast_io audit at docs/audits/macos-fastio-fallback.md flagged this
as one of two unshipped wins identified during the post-merge
review of PR #4008.

This change adds a target_os = "macos" arm in send_file_to_fd and
send_file_to_fd_with_policy that calls libc::sendfile with the
Darwin signature:

    int sendfile(int fd, int s, off_t offset, off_t *len,
                 struct sf_hdtr *hdtr, int flags);

The implementation handles the in/out `len` parameter (bytes to
send -> bytes actually sent), treats a return of 0 as success, and
preserves the "transfer from the current file position" contract
by querying the source offset with lseek(SEEK_CUR) and advancing
the position with lseek(SEEK_SET) after the transfer. Partial
sends on EAGAIN/EINTR are reported as forward progress so the
socket peer always sees a consistent prefix.

Non-socket destinations (pipes, regular files) fail with
ENOTSOCK; the dispatch transparently falls back to the buffered
read/write loop in that case, matching the behaviour Linux
already had for non-sendfile-capable targets.

Tests gated to target_os = "macos" exercise the new path through
a SOCK_STREAM socketpair (native sendfile fast path), the public
dispatch entry point, and a pipe destination that must fall back
to read/write.

Refs #2152.
oferchen added a commit that referenced this pull request May 18, 2026
Darwin ships a BSD-style sendfile(2) syscall, but the dispatch in
crates/fast_io/src/sendfile.rs only branched on Linux and fell
through to a read/write loop on every other unix target. The macOS
fast_io audit at docs/audits/macos-fastio-fallback.md flagged this
as one of two unshipped wins identified during the post-merge
review of PR #4008.

This change adds a target_os = "macos" arm in send_file_to_fd and
send_file_to_fd_with_policy that calls libc::sendfile with the
Darwin signature:

    int sendfile(int fd, int s, off_t offset, off_t *len,
                 struct sf_hdtr *hdtr, int flags);

The implementation handles the in/out `len` parameter (bytes to
send -> bytes actually sent), treats a return of 0 as success, and
preserves the "transfer from the current file position" contract
by querying the source offset with lseek(SEEK_CUR) and advancing
the position with lseek(SEEK_SET) after the transfer. Partial
sends on EAGAIN/EINTR are reported as forward progress so the
socket peer always sees a consistent prefix.

Non-socket destinations (pipes, regular files) fail with
ENOTSOCK; the dispatch transparently falls back to the buffered
read/write loop in that case, matching the behaviour Linux
already had for non-sendfile-capable targets.

Tests gated to target_os = "macos" exercise the new path through
a SOCK_STREAM socketpair (native sendfile fast path), the public
dispatch entry point, and a pipe destination that must fall back
to read/write.

Refs #2152.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant