Skip to content

RDT: register_nixl_memory cache false-hits on a resized/recycled pointer, skipping registration of the new extent #65701

Closed

Description

@BatshevaBlack

Description

register_nixl_memory's cache is keyed on the storage's data_ptr(). If a tensor's storage is freed and a later allocation reuses the same address but with a larger size, the cache sees a hit on the pointer and skips re-registration.
NIXL still only has the old, smaller extent [P, P+S1) registered. A subsequent transfer of that tensor will fail with NIXL_ERR_NOT_FOUND, since NIXL requires the full transfer range to be covered by a single registered region.

Use case

  1. On register_nixl_memory(tensor), when the cache has a hit on data_ptr(), also compare the previously-registered size against the current storage's nbytes():
    • Sizes match → current behavior (cache hit, skip registration).
    • Sizes differ → deregister the old registration and register the new extent as if fresh.
  2. Add a docstring/comment on register_nixl_memory making explicit that resizing a preregistered buffer in place is inefficient and user should prefer allocating a big buffer size.

Activity

  1. added
    enhancement
    triage
    on Aug 24, 2026
  2. added
    P1
    good-first-issue
    and removed
    triage
    on Aug 24, 2026
  3. added
    core
    on Aug 24, 2026
  4. binaydhakal commented on Aug 24, 2026

    @binaydhakal

    I'd like to work on this.

    I reproduced the bug on current master with a CPU-only fake NIXL agent: registering a storage at pointer 0x1000 with 16 bytes and then a recycled storage at the same pointer with 32 bytes performs only the first registration and never deregisters the stale extent.

    My plan is to:

    • retain the registered storage size alongside each traditional cached descriptor;
    • preserve the existing cache-hit/reference-count behavior when pointer and size both match;
    • when the pointer matches but the size differs, deregister the stale descriptor, advance the agent metadata version, and register the current extent as a fresh entry;
    • add CPU-only unit coverage for same-size hits, resized/recycled-pointer replacement, and the re-registration failure state;
    • document that in-place resizing of preregistered buffers is inefficient and that allocating the maximum required size up front is preferred.

    I checked open PRs by issue number and by register_nixl_memory, NIXL registration cache, recycled pointer, and extent terms; I found no overlapping implementation. This investigation and the proposed patch are AI-assisted, and I will include the required disclosure and exact local test results in any PR.

  5. namviet157 commented on Aug 27, 2026

    @namviet157

    Hi @BatshevaBlack,

    I'd like to work on this issue as well.

    I reviewed the proposed fix and would like to implement the cache-entry size tracking and re-registration path for recycled pointers, together with CPU-only unit tests covering:

    • cache hit when pointer and storage size are unchanged;
    • recycled pointer with a larger storage size;
    • deregistration of the stale extent before re-registration;
    • re-registration failure handling.

    I also plan to add the requested documentation about avoiding in-place resizing of preregistered buffers.

    I noticed @binaydhakal has also expressed interest. If this is still available, could you please confirm whether there is a particular scope you'd like me to take, or whether I should coordinate with @binaydhakal?

    Thanks!

  6. BatshevaBlack commented on Aug 30, 2026

    @BatshevaBlack
    ContributorAuthor

    @binaydhakal @namviet157 thanks for offering to contribute
    It would be great if you can prepose a PR with the points mentioned above and share it here so we can review

  7. Sparks0219 commented on Sep 4, 2026

    @Sparks0219
    Contributor

    I'm a bit hesitant to have us handle this case since we did introduce deregister_nixl_memory to have the user specifically handle the lifecycle of the registered memory since it's beyond ray's purview. If the tensor's storage is freed, that would mean that the python ref count for that tensor hit 0 and was returned to torch and the user forgot to call deregister_nixl_memory. Perhaps to keep this simple, maybe we could just raise an error on the case where the we try to register a region with the same storage ptr repeatedly? What do you think @BatshevaBlack

  8. BatshevaBlack commented on Sep 7, 2026

    @BatshevaBlack
    ContributorAuthor

    @Sparks0219 Yes, you're right - this is simpler and more correct approach. Let's go with this.

    @namviet157 if you don't mind changing this to:

    • Keep the cache as (pointer → size) - no weak_ref/storage-identity tracking.
    • When register_nixl_memory is called on a pointer already in the cache but with a different size, raise an error
      instead of silently deregister+reregister.
    • Keep the docstring comment noting that resizing a preregistered buffer isn't free, so the guidance to allocate max size in advance still applies.
    • Apply the same ptr+size check to _tensor_memory_registered (pool eligibility) for consistency.

    thanks!

  9. BatshevaBlack commented on Oct 6, 2026

    @BatshevaBlack
    ContributorAuthor

    @Sparks0219 I opened a minimal PR solving this issue, can you take a look at this?
    Thanks!

  10. added a commit that references this issue on Oct 6, 2026
    dcbc42f
  11. added a commit that references this issue on Oct 8, 2026
    07197d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1community-backlogcoreenhancementgood-first-issuestability

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions