fix(mooncake): serialize ibv_reg_mr to avoid nvidia-peermem segfault under concurrent registration#14
Open
DavidBellamy wants to merge 19 commits intomainfrom
Open
Conversation
…alistic perf and auto-discover ut (sgl-project#22086) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Baizhou Zhang <sobereddiezhang@gmail.com>
…gl-project#21649) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Baizhou Zhang <sobereddiezhang@gmail.com>
…under concurrent registration Add a process-wide threading lock around register_memory / batch_register_memory / engine init in MooncakeTransferEngine to defend against a race in nvidia-peermem's page-callback path that can segfault when multiple threads register GPU memory concurrently against multiple IB contexts. Under concurrent GPU memory registration from multiple IB contexts (common in SR-IOV VF environments where each HCA presents a separate ibv_context), nvidia-peermem's page-callback can race and segfault inside the kernel. Sequential registration across the same set of HCAs is fine; the race window only opens with concurrency. Reproducible with a stress harness that issues ibv_reg_mr from N threads against N contexts simultaneously. With a process-wide mutex around the offending call, the segfault disappears with no observed throughput cost on realistic workloads (registration runs at session setup, not per request).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a process-wide threading lock around `register_memory` / `batch_register_memory` / engine init in `MooncakeTransferEngine` to defend against a race in nvidia-peermem's page-callback path that can segfault when multiple threads register GPU memory concurrently against multiple IB contexts.
Why
Under concurrent GPU memory registration from multiple IB contexts (common in SR-IOV VF environments where each HCA presents a separate `ibv_context`), nvidia-peermem's page-callback can race and segfault inside the kernel. Sequential registration across the same set of HCAs is fine; the race window only opens with concurrency.
Reproducible with a stress harness that issues `ibv_reg_mr` from N threads against N contexts simultaneously. With a process-wide mutex around the offending call, the segfault disappears with no observed throughput cost on realistic workloads (registration runs at session setup, not per request).
Changes (`python/sglang/srt/distributed/device_communicators/mooncake_transfer_engine.py`)
Behavior
Provenance
One of five focused PRs that supersede #3.