Skip to content

feat(fast_io): add IocpDiskBatch matching IoUringDiskBatch surface (#1898)#3609

Merged
oferchen merged 5 commits into
masterfrom
feat/iocp-disk-batch
May 4, 2026
Merged

feat(fast_io): add IocpDiskBatch matching IoUringDiskBatch surface (#1898)#3609
oferchen merged 5 commits into
masterfrom
feat/iocp-disk-batch

Conversation

@oferchen
Copy link
Copy Markdown
Owner

@oferchen oferchen commented May 4, 2026

Summary

  • Adds IocpDiskBatch in crates/fast_io/src/iocp/disk_batch.rs that mirrors the IoUringDiskBatch public surface (begin_file / write_data / flush / commit_file / bytes_written / bytes_written_with_pending) but submits overlapped WriteFile calls through a private completion port and drains them with GetQueuedCompletionStatusEx.
  • Reopens the file with FILE_FLAG_OVERLAPPED via ReOpenFile, pins each in-flight OverlappedOp so WriteFile sees a stable OVERLAPPED pointer, and matches completions by overlapped address. Best-effort flush on Drop so partial submissions cannot leak overlapped I/O.
  • Wires the new batch into the disk-commit pipeline: DiskCommitConfig gains iocp_policy: fast_io::IocpPolicy (default Auto), Writer gains an Iocp variant (Windows + iocp feature only), and disk_thread_main constructs a single batch up-front but only when io_uring is not active so the two backends stay mutually exclusive.
  • Cross-platform builds keep compiling: iocp_stub.rs exposes the same surface returning Unsupported / None / 0. Sparse mode and append paths still take the buffered writer.

Resolves part of #1898 (does not touch the completion-port pump being reworked in #1897 - this layers on top).

Test plan

  • cargo nextest run -p fast_io --features iocp -E 'test(disk_batch)' (Windows runner via CI)
  • cargo nextest run -p transfer --all-features -E 'test(disk_commit)'
  • cargo check --workspace --all-targets on Linux + macOS to confirm the stub keeps non-Windows builds green
  • CI: fmt+clippy, nextest (stable), Windows (stable), macOS (stable), Linux musl (stable)

New unit tests in disk_batch.rs cover:

  • batched submission of N writes
  • completion ordering independent of submission order
  • error propagation from a failed reopen_overlapped
  • large writes that exceed the buffer
  • fsync via FlushFileBuffers on commit_file(true)
  • Drop flushing pending data
  • many file rotations to verify no leaked overlapped handles

…1898)

Adds a Windows IOCP batched-write API that mirrors the IoUringDiskBatch
public surface, so the disk-commit thread can batch overlapped WriteFile
submissions through a completion port and drain them with
GetQueuedCompletionStatusEx.

The new IocpDiskBatch:
- begin_file / write_data / flush / commit_file / bytes_written
- Reopens the file with FILE_FLAG_OVERLAPPED via ReOpenFile and
  associates it with a private completion port.
- Tracks in-flight overlapped operations as Pin<Box<OverlappedOp>> so
  pointers passed to WriteFile remain stable until completion, and
  matches each completion to its op by OVERLAPPED address.
- Best-effort flush on Drop to avoid leaking pending I/O.
- Stub on non-Windows / when the iocp feature is off so cross-platform
  builds keep compiling.

Wires through disk-commit:
- DiskCommitConfig gains iocp_policy: fast_io::IocpPolicy (default Auto)
- Writer enum gains an Iocp variant (Windows + iocp feature only)
- process_file / process_whole_file accept an iocp_batch parameter and
  select it in make_writer when sparse mode is off and append_offset
  is zero.
- The disk thread constructs a single IocpDiskBatch up-front (only when
  io_uring is unavailable so the two backends stay mutually exclusive)
  and threads it into every per-file call.

Tests cover policy plumbing, Windows batched submission of N writes,
completion ordering independent of submission order, error propagation
from a failed reopen, large writes that exceed the buffer, fsync via
FlushFileBuffers, drop semantics, and many rotations to verify no
leaked overlapped handles.
@github-actions github-actions Bot added the enhancement New feature or request label May 4, 2026
oferchen added 3 commits May 4, 2026 04:15
The transfer crate uses #[cfg(feature = "iocp")] in disk_commit/{process,writer}.rs
without declaring `iocp` as a feature in its own Cargo.toml. Under
RUSTFLAGS=-D warnings this triggers `unexpected_cfgs` as a hard clippy error,
breaking CI on the feat/iocp-disk-batch branch.

Add `iocp = ["fast_io/iocp"]` to the transfer crate features (mirroring the
io_uring pattern), and forward `transfer/iocp` from the workspace top-level
iocp feature so a single `--features iocp` activates both crates.
# Conflicts:
#	crates/fast_io/src/iocp/mod.rs
#	crates/fast_io/src/lib.rs
@oferchen
Copy link
Copy Markdown
Owner Author

oferchen commented May 4, 2026

@dependabot rebase

@oferchen oferchen merged commit 3b1a849 into master May 4, 2026
38 checks passed
@oferchen oferchen deleted the feat/iocp-disk-batch branch May 5, 2026 04:20
oferchen added a commit that referenced this pull request May 5, 2026
…1898) (#3609)

* feat(fast_io): add IocpDiskBatch matching IoUringDiskBatch surface (#1898)

Adds a Windows IOCP batched-write API that mirrors the IoUringDiskBatch
public surface, so the disk-commit thread can batch overlapped WriteFile
submissions through a completion port and drain them with
GetQueuedCompletionStatusEx.

The new IocpDiskBatch:
- begin_file / write_data / flush / commit_file / bytes_written
- Reopens the file with FILE_FLAG_OVERLAPPED via ReOpenFile and
  associates it with a private completion port.
- Tracks in-flight overlapped operations as Pin<Box<OverlappedOp>> so
  pointers passed to WriteFile remain stable until completion, and
  matches each completion to its op by OVERLAPPED address.
- Best-effort flush on Drop to avoid leaking pending I/O.
- Stub on non-Windows / when the iocp feature is off so cross-platform
  builds keep compiling.

Wires through disk-commit:
- DiskCommitConfig gains iocp_policy: fast_io::IocpPolicy (default Auto)
- Writer enum gains an Iocp variant (Windows + iocp feature only)
- process_file / process_whole_file accept an iocp_batch parameter and
  select it in make_writer when sparse mode is off and append_offset
  is zero.
- The disk thread constructs a single IocpDiskBatch up-front (only when
  io_uring is unavailable so the two backends stay mutually exclusive)
  and threads it into every per-file call.

Tests cover policy plumbing, Windows batched submission of N writes,
completion ordering independent of submission order, error propagation
from a failed reopen, large writes that exceed the buffer, fsync via
FlushFileBuffers, drop semantics, and many rotations to verify no
leaked overlapped handles.

* style: cargo fmt --all

* fix(transfer): add iocp feature forwarding to fast_io/iocp

The transfer crate uses #[cfg(feature = "iocp")] in disk_commit/{process,writer}.rs
without declaring `iocp` as a feature in its own Cargo.toml. Under
RUSTFLAGS=-D warnings this triggers `unexpected_cfgs` as a hard clippy error,
breaking CI on the feat/iocp-disk-batch branch.

Add `iocp = ["fast_io/iocp"]` to the transfer crate features (mirroring the
io_uring pattern), and forward `transfer/iocp` from the workspace top-level
iocp feature so a single `--features iocp` activates both crates.
oferchen added a commit that referenced this pull request May 18, 2026
…1898) (#3609)

* feat(fast_io): add IocpDiskBatch matching IoUringDiskBatch surface (#1898)

Adds a Windows IOCP batched-write API that mirrors the IoUringDiskBatch
public surface, so the disk-commit thread can batch overlapped WriteFile
submissions through a completion port and drain them with
GetQueuedCompletionStatusEx.

The new IocpDiskBatch:
- begin_file / write_data / flush / commit_file / bytes_written
- Reopens the file with FILE_FLAG_OVERLAPPED via ReOpenFile and
  associates it with a private completion port.
- Tracks in-flight overlapped operations as Pin<Box<OverlappedOp>> so
  pointers passed to WriteFile remain stable until completion, and
  matches each completion to its op by OVERLAPPED address.
- Best-effort flush on Drop to avoid leaking pending I/O.
- Stub on non-Windows / when the iocp feature is off so cross-platform
  builds keep compiling.

Wires through disk-commit:
- DiskCommitConfig gains iocp_policy: fast_io::IocpPolicy (default Auto)
- Writer enum gains an Iocp variant (Windows + iocp feature only)
- process_file / process_whole_file accept an iocp_batch parameter and
  select it in make_writer when sparse mode is off and append_offset
  is zero.
- The disk thread constructs a single IocpDiskBatch up-front (only when
  io_uring is unavailable so the two backends stay mutually exclusive)
  and threads it into every per-file call.

Tests cover policy plumbing, Windows batched submission of N writes,
completion ordering independent of submission order, error propagation
from a failed reopen, large writes that exceed the buffer, fsync via
FlushFileBuffers, drop semantics, and many rotations to verify no
leaked overlapped handles.

* style: cargo fmt --all

* fix(transfer): add iocp feature forwarding to fast_io/iocp

The transfer crate uses #[cfg(feature = "iocp")] in disk_commit/{process,writer}.rs
without declaring `iocp` as a feature in its own Cargo.toml. Under
RUSTFLAGS=-D warnings this triggers `unexpected_cfgs` as a hard clippy error,
breaking CI on the feat/iocp-disk-batch branch.

Add `iocp = ["fast_io/iocp"]` to the transfer crate features (mirroring the
io_uring pattern), and forward `transfer/iocp` from the workspace top-level
iocp feature so a single `--features iocp` activates both crates.
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