mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #2511] [Bug]: When enable expandable_segments, mooncake register memory failed #664
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#664
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MARD1NO on GitHub (Jun 17, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/2511
Originally assigned to: @MARD1NO, @Icedcoco on GitHub.
Bug Report
When I export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
it will cause registration failed, like this issue mentioned: https://github.com/kvcache-ai/Mooncake/issues/351#issuecomment-2888725354
Will Mooncake support it?
Before submitting...
@github-actions[bot] commented on GitHub (Jun 17, 2026):
Thanks for opening this issue, @MARD1NO!
42901638A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide
@Icedcoco commented on GitHub (Jun 18, 2026):
Thanks for reporting this.
expandable_segments:Truechanges how PyTorch allocates CUDA memory, and Mooncake's RDMA registration depends on whether that GPU memory can be registered by the underlying GDR/RDMA stack. The sameregister memory failederror can also be caused by host RDMA/GDR configuration, so we need a bit more information to distinguish the cases.Could you share:
registerLocalMemory, especially lines containingFailed to retrieve dmabuf,ibv_reg_mr,ibv_reg_dmabuf_mr, orFailed to register memoryPYTORCH_CUDA_ALLOC_CONFinstead of settingexpandable_segments:Falsenvidia_peermemis loaded on the host:ibv_devinfo,nvidia-smi topo -m, and GDRCopy tests if availableThis will help us tell whether the failure is caused by PyTorch expandable CUDA VMM allocation compatibility, missing
nvidia_peermem/dmabuf support, or a more general RDMA environment issue.@MARD1NO commented on GitHub (Jun 18, 2026):
Thanks for your reply :D
Torch version is torch2.8 + cuda12.9, I check this commit, this contain the modification: https://github.com/pytorch/pytorch/pull/153261
I used in our Inference engine
When I unset the PYTORCH_CUDA_ALLOC_CONF, it disappear issue.
I'm sure nvidia_peermem has been loaded.
when I disable expandable_segements before create paged kv cache, the issue also disappear, and I notice that vllm also process in this way
@Icedcoco commented on GitHub (Jun 18, 2026):
Thanks for the details. This narrows the issue down quite a bit.
Since the failure disappears when
PYTORCH_CUDA_ALLOC_CONFis unset, and also disappears whenexpandable_segmentsis disabled before creating the paged KV cache, this does not look like a general RDMA/GDR environment issue. It is more likely related to howmooncake-transfer-engine 0.3.9registers PyTorch expandable CUDA VMM allocations.One relevant detail is that
0.3.9still has the older dmabuf registration path. After that release, we merged several related fixes, especially:#2035 is particularly relevant here because framework allocators can return a pointer inside a larger CUDA allocation, while
cuMemGetHandleForAddressRangerequires the real allocation boundary. PyTorch expandable segments are more likely to expose this.Could you try a Mooncake build from current
mainor any release that includes those fixes? If it still fails, please share the first Mooncake error lines around registration, especially whether the failure is fromFailed to retrieve dmabuf,ibv_reg_dmabuf_mr,ibv_reg_mr, orFailed to register memory ... Bad address.@MARD1NO commented on GitHub (Jun 18, 2026):
Thanks ! I will try a newer version of mooncake
@hope1262946533 commented on GitHub (Aug 19, 2026):
Retested on the latest release — still fails. Below are the exact error lines you asked for, and the root cause, which turns out to be #2035 itself rather than its absence.
Versions tested
mooncake-transfer-engine-cuda130.3.11.post1EINVALmooncake-transfer-engine-cuda130.3.12.post1 (latest on PyPI)EINVALon the same buffersSo the environment already had all three fixes you listed before this report; 0.3.12.post1 adds #2523 and does not change the outcome. Confirmed the new build was actually loaded (
mooncake.__file__pointed at the 0.3.12.post1 install, and the error line numbers moved fromrdma_context.cpp:346tordma_context.cpp:588).First error lines on 0.3.12.post1
Prefill side:
Decode side is identical in shape (
addr 0x12421e3d000 length 2013598080andaddr 0x1009700b000 length 201427200).To answer the specific question: the failure is
ibv_reg_dmabuf_mr()returningEINVAL—Failed to register memory ...: Invalid argument [22]. It is notFailed to retrieve dmabuf, notibv_reg_mr, and notBad address.Bad address [14]is what the other branch produces (WITH_NVIDIA_PEERMEM=1, plainibv_reg_mron a VMM pointer); this report is about the dma-buf branch withWITH_NVIDIA_PEERMEM=0.Per side, 16 error lines are logged on 0.3.12.post1 against 1944 on 0.3.11.post1, but those two counts are not comparable — registration aborts and rolls back on the first failing chunk, so a differing number of attempts is reached. In both versions the failures are on the large buffers (the KV buffer plus a ~190 MB buffer); buffers smaller than one expandable-segment chunk succeed. The first request then returns HTTP 500 with
Failed to get kvcache from prefill instance.Root cause
RdmaContext::exportDmabuf()derives the dma-buf export range fromcuMemGetAddressRange(). For memory allocated through the CUDA virtual memory management API (cuMemCreate+cuMemMap) — which is exactly what PyTorch uses withPYTORCH_CUDA_ALLOC_CONF=expandable_segments:True—cuMemGetAddressRange()returns only the physical mapping that containsaddr, not the surrounding contiguous VA reservation.PyTorch grows expandable segments in
large_segment_sizesteps, 20 MiB by default (c10/core/AllocatorConfig.h:std::atomic<size_t> large_segment_size_{20971520}; // 20 MB by default). So the exported dma-buf is 20 MiB while the registered buffer is often larger than 1 GiB. The kernel requiresoffset + length <= dma-buf size, which is violated, andibv_reg_dmabuf_mr()returnsEINVAL.Current
main(and 0.3.12.post1),mooncake-transfer-engine/src/transport/rdma_transport/rdma_context.cpp:Two things make this hard to diagnose:
exp.offset + length <= allocSize.PLOG(ERROR) << "Failed to register memory " << addr;— it prints neitherlength, norexp.offset, nor the exported size, so the log cannot point at the cause.Captured arguments from a real run
Interposed the actual
ibv_reg_dmabuf_mr()call with anLD_PRELOADlibrary that forwards to the real function unchanged and additionally reads the fd size withlseek(fd, 0, SEEK_END):iova % 4096 == offset % 4096holds, so this is not the page-offset rule; it is purely the size.The hardware and driver do support the wider export
Standalone probe using only the CUDA driver API and libibverbs (no Mooncake): reserve one VA range with
cuMemAddressReserve, map 8 separatecuMemCreatehandles into it contiguously, thenExporting a range that spans several mappings is therefore legal. Only the choice of range is wrong.
The same probe shows the other two combinations behave as expected on this setup:
cuMemAlloc+ibv_reg_mrsucceeds; VMM memory +ibv_reg_mr(theWITH_NVIDIA_PEERMEM=1path) fails withEFAULT, which is the other half of what users report.Enlarging the PyTorch granularity is not a viable workaround
large_segment_size_mbenlargesallocSize, but a buffer can start anywhere inside a segment, sooffset_within_segment + length <= segment_sizecannot hold for all buffers at any finite segment size. Measured on an 8-GPU prefill instance, KV buffers up to 1.57 GiB, 1944 registrations per side:large_segment_size_mbObserved extremes with 4 GiB segments: max offset 4,269,312,512 (right at the segment end), max
offset + length5,956,546,112. In addition, 4 GiB segments leave about 13.4 GiBreserved but unallocatedper GPU, which makes decode-side CUDA graph capture OOM (Tried to allocate 4.00 GiB) atmem_fraction_static0.979 and 0.95 alike.Verified fix
Exporting
[addr, addr + length)with a page-aligned base — instead of the reported allocation — makes registration succeed with the default 20 MiB granularity:expandable_segments:True, currentmainFailed to send kv chunkexpandable_segments:True+ corrected export rangeEnvironment: SGLang PD disaggregation with prefill and decode on separate 8-GPU hosts, DeepSeek-V4-Pro, ConnectX-8 RoCE (
mlx5_bond_0..7),mooncake-transfer-engine-cuda13 0.3.11.post1, torch 2.11.0+cu130,WITH_NVIDIA_PEERMEM=0,MC_GID_INDEX=3.Note on #2035 and #2523
#2035 introduced the
cuMemGetAddressRange()normalisation to handle caching-allocator sub-allocations, and #2523 restated the assumption as "cuMemGetAddressRangenormalised every export to the true allocation base". That assumption holds forcudaMalloc-backed memory but not for VMM-backed memory, which is where this bug lives. A fix should keep the existing behaviour for thecudaMalloccase and only change the range when the reported allocation demonstrably cannot cover the registration.A pull request follows.
@enternal111 commented on GitHub (Aug 20, 2026):
same error