Skip to content

[core][rdt] Implement receive side memory pool - #64487

Merged
Sparks0219 merged 11 commits into
ray-project:masterfrom
Sparks0219:joshlee/receive-side-memory-pool
Nov 20, 2026
Merged

Sparks0219 merged 11 commits into
ray-project:masterfrom
Sparks0219:joshlee/receive-side-memory-pool

Conversation

@Sparks0219

@Sparks0219 Sparks0219 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Follows up on #61573 with the receive side of the NIXL memory pool.

When the receiver has registered a pool with register_nixl_memory_pool and passes no target buffers, ray.get reads the incoming tensors into regions of the pool, which is registered with NIXL once, instead of registering new buffers for every transfer. Once the transfer lands, the tensors are copied out into ordinary tensors on the source's device type, and the regions go straight back to the pool. The tensors you get are independent of the pool, so the pool size bounds how much data can be in flight at once, not how much received data you can hold. An earlier version of this PR tied blocks to the returned tensors with weakref, which broke when a view outlived the tensor, so it copies out instead.

  • MemoryPoolManager.allocate_regions, copy_out_and_free and free_blocks make up the receive-side allocator. Regions start on _MAX_ALIGNMENT, so the sender's packed layout decodes in place. The pool now has a lock, since sends and receives use it from both the main and _ray_system threads.
  • A failed or abandoned receive gives its regions back only after its transfer handle is released, including when that release waits for _finish_transfers ([core][rdt] nixl: don't remove a remote agent while transfers on it are in flight #67389) to stop polling the handle.
  • Every pool call runs with the cleanups that garbage collection triggers deferred, as the cache lock already does, so a fetch request's __del__ can't deadlock on the pool's lock.
  • An object with an empty tensor skips the receive pool: NIXL can't find a zero-length descriptor inside a registered region (NIXL_ERR_NOT_FOUND).
  • With user target buffers the pool is bypassed, as before.

Not a duplicate: this is the receive-side follow-up to #61573. Searching open PRs for the NIXL memory pool turns up #68142 (pool statistics, which touches the same files but not the receive path) and nothing else on the receive side.

Tests (4x T4, UCX with UCX_TLS=^gdr_copy, Ray nightly 2b3daa8 with this branch's python/ray/experimental and python/ray/tests linked in):

  • pytest python/ray/tests/rdt/test_rdt_nixl.py python/ray/tests/rdt/test_nixl_agent_lock.py python/ray/tests/rdt/test_nixl_memory_pool.py: 95 passed, 1 skipped (test_nixl_borrow_after_abort, skipped on master).
  • pytest python/ray/tests/rdt/test_nixl_backend_selection.py python/ray/tests/rdt/test_rdt_custom.py python/ray/tests/rdt/test_rdt_gloo.py (with the two unit files above): 101 passed, 1 skipped.
  • Each new test fails with its fix reverted.

AI assistance (Claude Code) was used for this PR.

🤖 Generated with Claude Code

@Sparks0219
Sparks0219 requested a review from a team as a code owner July 1, 2026 22:57

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request implements receiver-side memory pool management for NIXL RDT optimization, enabling incoming tensors to be read directly into a pre-registered pool and automatically freed via weakref finalizers. The review feedback highlights several critical issues: a deduplication collision and OOM risk when forwarding existing pool-backed views, potential alignment errors during tensor viewing due to unaligned block offsets, crashes when handling empty (0-sized) tensors, and a memory leak where pool blocks are not immediately freed if a transfer fails.

Signed-off-by: Joshua Lee <[email protected]>
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Jul 2, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jul 22, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Aug 5, 2026
@Sparks0219 Sparks0219 reopened this Aug 24, 2026
@Sparks0219 Sparks0219 removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 24, 2026
@stephanie-wang stephanie-wang self-assigned this Aug 24, 2026
Signed-off-by: Joshua Lee <[email protected]>
@Sparks0219 Sparks0219 added the go add ONLY when ready to merge, run all tests label Sep 1, 2026
Signed-off-by: Joshua Lee <[email protected]>
Signed-off-by: Joshua Lee <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 82f292b. Configure here.

Signed-off-by: Joshua Lee <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 16, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Sep 30, 2026
@Sparks0219 Sparks0219 reopened this Nov 18, 2026
Sparks0219 and others added 3 commits November 18, 2026 08:31
Resolves the conflict in NixlTensorTransport._cleanup_transfer with
ray-project#67389, which made it defer while the thread holds the cache lock and
serialized handle releases with the remote agent locks. The receive
pool blocks are carried through the deferred cleanup and freed after
the rest of it, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Joshua Lee <[email protected]>
Two follow-ups to merging ray-project#67389 into the receive pool:

- When garbage collection cleans up a fetch request while
  _finish_transfers still polls its handle, the handle's release waits
  for the polling to end. Its pool blocks now wait with it, so the next
  receive can't take a block that the transfer may still write into.
- The pool's lock is not reentrant, and garbage collection can run a
  fetch request's cleanup on a thread that holds it, which would then
  wait for the pool's lock itself, or for the cache lock or an agent
  lock whose holder waits for the pool's lock. Every pool call now runs
  with those cleanups deferred, as the cache lock already did.

Also adds a test that a receive failing after it took its buffers from
the pool returns them without deregistering anything, and that the
pool still receives afterwards.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Joshua Lee <[email protected]>
NIXL can't find a zero-length descriptor inside a registered region
(NIXL_ERR_NOT_FOUND), so an object holding an empty tensor failed to
transfer once the receiver had a memory pool, while it works without
one. Such an object now uses the per-transfer buffers instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Joshua Lee <[email protected]>
@Sparks0219

Copy link
Copy Markdown
Contributor Author

Merged master and pushed two more fixes:

  • Merging [core][rdt] nixl: don't remove a remote agent while transfers on it are in flight #67389 needed two follow-ups (d24677e): a transfer that _finish_transfers is still polling now keeps its pool blocks until its handle is released, and every pool call runs with GC-triggered cleanups deferred, so a fetch request's __del__ can't deadlock on the pool's non-reentrant lock.
  • An object with an empty tensor failed to transfer once the receiver had a pool (NIXL can't find a zero-length descriptor inside a registered region), so such an object now skips the pool (59c6fea).

The weakref, alignment and pool-backed-view bot threads from July are about code the copy-out design replaced.

@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Nov 18, 2026
@Sparks0219
Sparks0219 merged commit 1f4fcb6 into ray-project:master Nov 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants