Skip to content

feat: add io_uring buffer registration for READ_FIXED/WRITE_FIXED ops - #3035

Merged
oferchen merged 7 commits into
masterfrom
feature/iouring-buffer-registration
Mar 28, 2026
Merged

oferchen merged 7 commits into
masterfrom
feature/iouring-buffer-registration

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add RegisteredBufferGroup type that allocates page-aligned buffers and registers them with io_uring via IORING_REGISTER_BUFFERS for zero-copy fixed-buffer I/O
  • Add submit_read_fixed_batch and submit_write_fixed_batch helpers for IORING_OP_READ_FIXED/IORING_OP_WRITE_FIXED SQE submission
  • Wire registered buffers into IoUringReader and IoUringWriter - they transparently use fixed-buffer ops when available, falling back to regular Read/Write ops
  • Add register_buffers and registered_buffer_count fields to IoUringConfig (enabled by default)
  • Full stub module for non-Linux platforms returning None/Unsupported

Design decisions

  • Page-aligned allocation via std::alloc::alloc with Layout aligned to sysconf(_SC_PAGESIZE) for optimal DMA
  • Lock-free checkout/return using atomic bitset (AtomicU64 words) for buffer slot management
  • Max 1024 buffers matching kernel limit for IORING_REGISTER_BUFFERS
  • Transparent fallback - if buffer registration fails (seccomp, kernel limit) or all slots are busy, silently falls back to regular IORING_OP_READ/IORING_OP_WRITE
  • Default 8 buffers for general workloads, 16 for large-file preset
  • Slot info struct (RegisteredBufferSlotInfo) avoids lifetime complications when passing buffer metadata into batch functions

Test plan

  • page_size_is_positive_and_power_of_two - verifies system page size detection
  • registered_buffer_group_rejects_zero_count/size - validates input bounds
  • registered_buffer_group_create_and_checkout - tests full lifecycle (create, checkout all, exhaust, return, re-acquire)
  • buffer_slot_read_write_memory - verifies buffer memory read/write correctness
  • read_fixed_write_fixed_roundtrip - end-to-end ReadFixed/WriteFixed batch test
  • test_registered_buffer_group_via_writer/reader - writer and reader with registered buffers
  • test_registered_buffer_write_read_roundtrip - full write-then-read cycle
  • test_registered_buffer_disabled_still_works - verifies fallback when registration is disabled
  • Stub platform tests: try_new returns None, new returns Unsupported
  • Config field tests across all presets
  • All 119 fast_io tests pass (3 new tests added)

@github-actions github-actions Bot added the enhancement New feature or request label Mar 28, 2026
…rations

Register page-aligned buffers with io_uring via IORING_REGISTER_BUFFERS,
enabling READ_FIXED and WRITE_FIXED opcodes that eliminate per-SQE
get_user_pages() overhead. This reduces kernel-side memory mapping cost
for high-throughput sequential I/O.

Key components:
- RegisteredBufferGroup: manages page-aligned buffer allocation,
  kernel registration, lock-free checkout/return via atomic bitset
- submit_read_fixed_batch/submit_write_fixed_batch: batch SQE helpers
  for the new fixed-buffer opcodes
- IoUringReader/IoUringWriter: transparently use WRITE_FIXED/READ_FIXED
  when registered buffers are available, falling back to regular ops
- IoUringConfig gains register_buffers and registered_buffer_count fields
- Full stub module for non-Linux platforms (returns None/Unsupported)
- Allow mut_from_ref on as_mut_slice (unsafe interior mutability)
- Use io::Error::other() instead of io::Error::new(ErrorKind::Other)
- Use enumerate().take(n) instead of needless range loops
Change as_mut_ptr() and as_mut_slice() to take &mut self instead of
&self, properly encoding exclusive access at the type level. Removes
the #[allow(clippy::mut_from_ref)] workaround.
@oferchen
oferchen force-pushed the feature/iouring-buffer-registration branch from d1aa146 to cf932b2 Compare March 28, 2026 17:24
@oferchen
oferchen merged commit c6296e7 into master Mar 28, 2026
35 checks passed
@oferchen
oferchen deleted the feature/iouring-buffer-registration branch March 28, 2026 17:51
oferchen added a commit that referenced this pull request May 1, 2026
…#3035)

* feat: add io_uring buffer registration for READ_FIXED/WRITE_FIXED operations

Register page-aligned buffers with io_uring via IORING_REGISTER_BUFFERS,
enabling READ_FIXED and WRITE_FIXED opcodes that eliminate per-SQE
get_user_pages() overhead. This reduces kernel-side memory mapping cost
for high-throughput sequential I/O.

Key components:
- RegisteredBufferGroup: manages page-aligned buffer allocation,
  kernel registration, lock-free checkout/return via atomic bitset
- submit_read_fixed_batch/submit_write_fixed_batch: batch SQE helpers
  for the new fixed-buffer opcodes
- IoUringReader/IoUringWriter: transparently use WRITE_FIXED/READ_FIXED
  when registered buffers are available, falling back to regular ops
- IoUringConfig gains register_buffers and registered_buffer_count fields
- Full stub module for non-Linux platforms (returns None/Unsupported)

* fix: resolve clippy warnings in registered_buffers

- Allow mut_from_ref on as_mut_slice (unsafe interior mutability)
- Use io::Error::other() instead of io::Error::new(ErrorKind::Other)
- Use enumerate().take(n) instead of needless range loops

* fix: add missing register_buffers fields to IoUringConfig test literals

* fix: replace needless return with unit value in match arms

* refactor: require &mut self for RegisteredBufferSlot mutable access

Change as_mut_ptr() and as_mut_slice() to take &mut self instead of
&self, properly encoding exclusive access at the type level. Removes
the #[allow(clippy::mut_from_ref)] workaround.

* fix: declare slot variables as mut for as_mut_ptr calls

* fix: use if-let instead of single-pattern match for clippy
oferchen added a commit that referenced this pull request May 5, 2026
…#3035)

* feat: add io_uring buffer registration for READ_FIXED/WRITE_FIXED operations

Register page-aligned buffers with io_uring via IORING_REGISTER_BUFFERS,
enabling READ_FIXED and WRITE_FIXED opcodes that eliminate per-SQE
get_user_pages() overhead. This reduces kernel-side memory mapping cost
for high-throughput sequential I/O.

Key components:
- RegisteredBufferGroup: manages page-aligned buffer allocation,
  kernel registration, lock-free checkout/return via atomic bitset
- submit_read_fixed_batch/submit_write_fixed_batch: batch SQE helpers
  for the new fixed-buffer opcodes
- IoUringReader/IoUringWriter: transparently use WRITE_FIXED/READ_FIXED
  when registered buffers are available, falling back to regular ops
- IoUringConfig gains register_buffers and registered_buffer_count fields
- Full stub module for non-Linux platforms (returns None/Unsupported)

* fix: resolve clippy warnings in registered_buffers

- Allow mut_from_ref on as_mut_slice (unsafe interior mutability)
- Use io::Error::other() instead of io::Error::new(ErrorKind::Other)
- Use enumerate().take(n) instead of needless range loops

* fix: add missing register_buffers fields to IoUringConfig test literals

* fix: replace needless return with unit value in match arms

* refactor: require &mut self for RegisteredBufferSlot mutable access

Change as_mut_ptr() and as_mut_slice() to take &mut self instead of
&self, properly encoding exclusive access at the type level. Removes
the #[allow(clippy::mut_from_ref)] workaround.

* fix: declare slot variables as mut for as_mut_ptr calls

* fix: use if-let instead of single-pattern match for clippy
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