Skip to content

[TENT] Add an opt-in pinned staging pool to the io_uring transport - #5012

Merged
staryxchen merged 1 commit into
kvcache-ai:mainfrom
zxue2:iouring_pinned_staging
Oct 28, 2026
Merged

staryxchen merged 1 commit into
kvcache-ai:mainfrom
zxue2:iouring_pinned_staging

Conversation

@zxue2

@zxue2 zxue2 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

io_uring staging buffer comes from posix_memalign(), which is pageable, so the device copy into it is slow. IOUringStagingPool added to address it: one pinned host allocation made at install(), split into fixed slots. Requests that need staging take a slot; when none is free or the request is larger than a slot they fall back to posix_memalign() as before, so the pool never blocks a submission. A task holds a shared_ptr to the pool while it owns a slot, so a slot returned after uninstall() still has a live pool.

Pinned memory comes from a new Platform::allocatePinnedHost / freePinnedHost hook: cudaHostAlloc(cudaHostAllocPortable) on CUDA, and page-aligned posix_memalign() elsewhere. On XPU the posix_memalign() pages are also registered with the driver through prepare_for_device_copy, so device copies stay fast. USM host memory (sycl::aligned_alloc_host) is not used: the kernel cannot pin it, so every O_DIRECT request on a slot would fail with EFAULT.

The pool is off by default:

  • MC_IOURING_PINNED_STAGING transports/io_uring/pinned_staging (off)
  • MC_IOURING_STAGING_SLOT_KB transports/io_uring/staging_slot_kb (4096)
  • MC_IOURING_STAGING_SLOTS transports/io_uring/staging_slots (32)

The size keys only take effect when pinned_staging is on. Slot sizes are rounded up to whole pages. If the pinned allocation fails, install() logs a warning and stages with pageable buffers.

Add tests for the pool, including O_DIRECT I/O through a staging slot on a real filesystem (the other transport tests use tmpfs, which has no O_DIRECT and so hides pinning failures).

Description

Suggested Merge Priority

  • P0 — Urgent: Critical security vulnerability, data loss/corruption, or widespread production outage requiring immediate action
  • P1 — High: Significant correctness or stability issue in existing functionality, or a regression blocking users without a practical workaround
  • P2 — Normal: Routine bug fix, validated performance/compatibility improvement, or new feature for a confirmed use case
  • P3 — Low: Experimental feature, optional enhancement, refactoring, or cleanup with no urgent user impact

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Test commands:

# Example: bash scripts/run_ci_test.sh

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

Copilot AI balanced review requested due to automatic review settings October 27, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Adds an opt-in pinned staging pool for the io_uring transport to speed up device↔host staging by reusing pinned, page-aligned host slots, plus platform hooks and tests to validate O_DIRECT behavior.

Changes:

  • Introduces IOUringStagingPool and integrates it into io_uring staging buffer selection with fallback to posix_memalign().
  • Adds Platform::allocatePinnedHost/freePinnedHost with CUDA and XPU specializations.
  • Adds new unit/integration-style tests, including O_DIRECT I/O on a real filesystem.
File Description
mooncake-transfer-engine/​tent/​tests/​io_uring_transport_test.cpp Adds staging pool unit tests and an O_DIRECT validation test path.
mooncake-transfer-engine/​tent/​src/​transport/​io_uring/​io_uring_transport.cpp Implements staging pool logic, lifecycle, and usage in submissions.
mooncake-transfer-engine/​tent/​src/​runtime/​platform.cpp Adds default pinned-host allocation/free hooks (fallback implementation).
mooncake-transfer-engine/​tent/​src/​platform/​xpu/​xpu_sycl_backend.h Adds pinned host allocation/free via prepare/release_for_device_copy.
mooncake-transfer-engine/​tent/​src/​platform/​xpu/​xpu_platform.cpp Exposes pinned host allocation/free overrides for XPU platform.
mooncake-transfer-engine/​tent/​src/​platform/​cuda/​cuda_allocator.cpp Adds CUDA pinned host allocation/free using cudaHostAlloc/cudaFreeHost.
mooncake-transfer-engine/​tent/​src/​common/​config.cpp Adds env/config wiring for pinned staging feature and sizing knobs.
mooncake-transfer-engine/​tent/​include/​tent/​transport/​io_uring/​io_uring_transport.h Declares IOUringStagingPool, task ownership, and transport accessor.
mooncake-transfer-engine/​tent/​include/​tent/​runtime/​platform.h Extends platform interface with allocate/free pinned host APIs.
mooncake-transfer-engine/​tent/​include/​tent/​platform/​xpu.h Declares XPU overrides for pinned host allocation/free.
mooncake-transfer-engine/​tent/​include/​tent/​platform/​cuda.h Declares CUDA overrides for pinned host allocation/free.

Review effort: Lite

Comment on lines +65 to +66
auto p = static_cast<const char *>(buffer);
return base_ && p >= base_ && p < base_ + slot_size_ * slot_count_;
Comment on lines +149 to +155
const size_t kPageSize = 4096;
const size_t slot_kb =
conf_->get("transports/io_uring/staging_slot_kb", size_t{4096});
const size_t slot_bytes =
(slot_kb * 1024 + kPageSize - 1) / kPageSize * kPageSize;
const size_t slots =
conf_->get("transports/io_uring/staging_slots", size_t{32});
Comment on lines +69 to +70
if (base_)
Platform::getLoader().freePinnedHost(base_, slot_size_ * slot_count_);
ThreadLocalStorage<FileContextMap> tl_file_context_map_;
uint64_t async_memcpy_threshold_;
// Null unless transports/io_uring/pinned_staging is set and the pinned
// allocation succeeded; staging then uses posix_memalign() only.
@zxue2
zxue2 force-pushed the iouring_pinned_staging branch 2 times, most recently from 12680e5 to def1b4c Compare October 27, 2026 13:27
@github-actions github-actions Bot added run-ci Transfer Engine size/M 100-1000 changed lines (additions + deletions) labels Oct 27, 2026

@alogfans alogfans left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zxue2
zxue2 force-pushed the iouring_pinned_staging branch 2 times, most recently from c177146 to 66ed04c Compare October 28, 2026 03:12

@staryxchen staryxchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@staryxchen
staryxchen merged commit 5fa91fe into kvcache-ai:main Oct 28, 2026
29 of 32 checks passed
io_uring staging buffer comes from posix_memalign(), which is
pageable, so the device copy into it is slow. IOUringStagingPool
added to address it: one pinned host allocation made at install(),
split into fixed slots. Requests that need staging take a slot; when
none is free or the request is larger than a slot they fall back to
posix_memalign() as before, so the pool never blocks a submission. A
task holds a shared_ptr to the pool while it owns a slot, so a slot
returned after uninstall() still has a live pool.

Pinned memory comes from a new Platform::allocatePinnedHost /
freePinnedHost hook: cudaHostAlloc(cudaHostAllocPortable) on CUDA,
and page-aligned posix_memalign() elsewhere. On XPU the
posix_memalign() pages are also registered with the driver through
prepare_for_device_copy, so device copies stay fast. USM host memory
(sycl::aligned_alloc_host) is not used: the kernel cannot pin it, so
every O_DIRECT request on a slot would fail with EFAULT.

The pool is off by default.
- MC_IOURING_PINNED_STAGING  transports/io_uring/pinned_staging  (off)
- MC_IOURING_STAGING_SLOT_KB transports/io_uring/staging_slot_kb (4096)
- MC_IOURING_STAGING_SLOTS   transports/io_uring/staging_slots   (32)

The size keys only take effect when pinned_staging is on. Slot sizes are
rounded up to whole pages. If the pinned allocation fails, install()
logs a warning and stages with pageable buffers.

Add tests for the pool, including O_DIRECT I/O through a staging slot
on a real filesystem (the other transport tests use tmpfs, which has
no O_DIRECT and so hides pinning failures).

Signed-off-by: Zhan Xue <zhan.xue@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci size/M 100-1000 changed lines (additions + deletions) Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants