Skip to content

feat(fast_io): add macOS F_NOCACHE + writev optimized write path (#1657) - #3998

Merged
oferchen merged 3 commits into
masterfrom
feat/macos-fast-io-1657
May 13, 2026
Merged

oferchen merged 3 commits into
masterfrom
feat/macos-fast-io-1657

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add MacosWriter in crates/fast_io/src/macos_io.rs combining F_NOCACHE cache bypass (via fcntl) and writev scatter-gather I/O for large sequential file writes on macOS
  • F_NOCACHE is applied only to files above the 1 MB threshold (F_NOCACHE_THRESHOLD); smaller files use standard buffered I/O where the cache is beneficial
  • Non-macOS platforms compile a stub that delegates to BufWriter with the same public API, following the same pattern as io_uring_stub.rs and iocp_stub.rs
  • Public standalone utilities set_nocache(), is_nocache_set(), and writev_buffers() exposed for callers managing their own file handles
  • platform_io_capabilities() now reports F_NOCACHE and writev on macOS

Test plan

  • small_file_skips_nocache - verifies F_NOCACHE is not set below threshold
  • large_file_enables_nocache_on_macos - verifies F_NOCACHE is set above threshold
  • threshold_boundary_below / threshold_boundary_exact - boundary tests at 1 MB
  • write_and_read_roundtrip - basic write/read correctness
  • write_large_payload_roundtrip - 64 KB payload correctness
  • write_above_threshold_with_nocache - write correctness with F_NOCACHE active
  • writev_buffers_multiple_buffers - scatter-gather batches multiple buffers
  • writev_buffers_empty / writev_buffers_single_buffer - edge cases
  • write_chunks_exceed_flush_threshold - auto-flush via writev when pending exceeds 256 KB
  • flush_on_drop_writes_data - Drop impl flushes pending buffers
  • multiple_flush_calls_are_idempotent - repeated flush is safe
  • create_invalid_path_returns_error - error handling for bad paths
  • set_nocache_returns_expected_value - standalone F_NOCACHE utility
  • CI must pass on all platforms (macOS uses real path, Linux/Windows use stubs)

Add a macOS-specific file writer that combines two optimizations for
large sequential writes:

- F_NOCACHE via fcntl bypasses the unified buffer cache for files above
  1 MB, reducing memory pressure without alignment requirements.
- writev scatter-gather I/O batches multiple buffers into a single
  syscall, reducing transition overhead.

Small files below the threshold use standard buffered I/O. Non-macOS
platforms compile a stub that delegates to BufWriter. The module follows
the same cfg-gated pattern as io_uring and IOCP with platform stubs.
@github-actions github-actions Bot added the enhancement New feature or request label May 13, 2026
oferchen added 2 commits May 13, 2026 18:40
Clippy flags `assert!(CONST > 0)` as `assert!(true)` since the
compiler evaluates and optimizes it away. Use `assert_eq!` with
the expected value instead.
Keep both macOS F_NOCACHE/writev and Windows ReFS reflink
capabilities in platform_io_capabilities doc comment.
@oferchen
oferchen merged commit bacb146 into master May 13, 2026
38 of 39 checks passed
@oferchen
oferchen deleted the feat/macos-fast-io-1657 branch May 14, 2026 14:57
oferchen added a commit that referenced this pull request May 18, 2026
…) (#3998)

* feat(fast_io): add macOS F_NOCACHE + writev optimized write path (#1657)

Add a macOS-specific file writer that combines two optimizations for
large sequential writes:

- F_NOCACHE via fcntl bypasses the unified buffer cache for files above
  1 MB, reducing memory pressure without alignment requirements.
- writev scatter-gather I/O batches multiple buffers into a single
  syscall, reducing transition overhead.

Small files below the threshold use standard buffered I/O. Non-macOS
platforms compile a stub that delegates to BufWriter. The module follows
the same cfg-gated pattern as io_uring and IOCP with platform stubs.

* fix: replace assertions on constants with value equality check

Clippy flags `assert!(CONST > 0)` as `assert!(true)` since the
compiler evaluates and optimizes it away. Use `assert_eq!` with
the expected value instead.
oferchen added a commit that referenced this pull request Aug 24, 2026
…) (#3998)

* feat(fast_io): add macOS F_NOCACHE + writev optimized write path (#1657)

Add a macOS-specific file writer that combines two optimizations for
large sequential writes:

- F_NOCACHE via fcntl bypasses the unified buffer cache for files above
  1 MB, reducing memory pressure without alignment requirements.
- writev scatter-gather I/O batches multiple buffers into a single
  syscall, reducing transition overhead.

Small files below the threshold use standard buffered I/O. Non-macOS
platforms compile a stub that delegates to BufWriter. The module follows
the same cfg-gated pattern as io_uring and IOCP with platform stubs.

* fix: replace assertions on constants with value equality check

Clippy flags `assert!(CONST > 0)` as `assert!(true)` since the
compiler evaluates and optimizes it away. Use `assert_eq!` with
the expected value instead.
oferchen added a commit that referenced this pull request Aug 24, 2026
…) (#3998)

* feat(fast_io): add macOS F_NOCACHE + writev optimized write path (#1657)

Add a macOS-specific file writer that combines two optimizations for
large sequential writes:

- F_NOCACHE via fcntl bypasses the unified buffer cache for files above
  1 MB, reducing memory pressure without alignment requirements.
- writev scatter-gather I/O batches multiple buffers into a single
  syscall, reducing transition overhead.

Small files below the threshold use standard buffered I/O. Non-macOS
platforms compile a stub that delegates to BufWriter. The module follows
the same cfg-gated pattern as io_uring and IOCP with platform stubs.

* fix: replace assertions on constants with value equality check

Clippy flags `assert!(CONST > 0)` as `assert!(true)` since the
compiler evaluates and optimizes it away. Use `assert_eq!` with
the expected value instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant