Repository navigation
Conversation
|
Thanks for working on HugeTLB sub-view support. I had a few questions about the registration and cleanup behavior and wanted to check my understanding:
Do you think any of these cases would benefit from changes? I’d appreciate your perspective, particularly if there are assumptions or guarantees I’ve overlooked. |
Thanks @Icedcoco review, these are all fair, and the first one is a real bug.
We'll split the state: pending_dereg_ keeps its meaning (metadata gone, MR may still be live, retry must do the MR cleanup), and a separate pending_republish_ records the
|
Icedcoco
left a comment
There was a problem hiding this comment.
The proposed pending_republish_ split sounds like the right direction: once MR cleanup is confirmed, a metadata-only retry should never reach MR lookup again. Would you be open to adding a regression test for the sequence we discussed—cleanup of A, publication failure, registration of a disjoint view B in the same hugepage, then retrying A—and checking that B remains registered? Coverage across the single-buffer, chunked, and batch paths would help establish the intended behavior.
On the widened access range, documenting the trust assumption would help. One detail I would still like to clarify is that padding can contain other application data even when it has no separate registration. The overlap check prevents another registration there, but does not establish that those bytes belong exclusively to the requested view. Would it make sense to state explicitly that callers using the widening path must be comfortable exposing the entire widened range to peers holding the key?
For compatibility, I would lean toward trying the original range first and using widening as a fallback, subject to the cleanup and ownership details. That would preserve the original hardware bounds wherever registration already works. A small terminology clarification: RDMAV_HUGEPAGES_SAFE enables hugepage-aware fork handling rather than disabling fork protection, while IBV_FORK_UNNEEDED is a status returned by ibv_is_fork_initialized().
For the fallback, could we limit it to known HugeTLB host sub-views and preserve the original failure reason, since EINVAL alone is not specific to this issue? It would also be helpful to ensure that any successful registrations on other NICs are fully rolled back before retrying, and that range reservations remain consistent across both attempts.
Would this approach fit what you have in mind?
hi @Icedcoco Thanks! all three land, and your terminology correction is right on both 1. Retry after a failed publication. Confirmed, and it is not only the single-buffer path. 2. Widened access range. Agreed, and your addition is the part that matters: the overlap check proves no second registration lives in the padding, but says nothing about bytes of the same mapping that were never registered at all — in our motivating case the two halves of one ShmHelper segment are exactly that. So we'll state it as an explicit caller contract rather than an internal invariant: using the widening path means accepting that the entire widened range is reachable by any peer holding the published key. We won't try to preserve the original hardware bounds — access rights are per-MR and the MR has to cover whole huge pages — but the published BufferDesc keeps the caller's range, so a correctly-behaving peer only ever computes addresses inside the caller's own view. 3. Compatibility. You're right, and our earlier framing was wrong; thanks for catching it. On the fallback. We'll take it: attempt the caller's range first and widen only on EINVAL, gated on the existing hugetlb detection (host-registration dmabuf export, plus
On the regression test. Happy to add that sequence, with one constraint worth knowing up front: One thing we won't silently claim to restore: unregister still madvises MADV_DOFORK over the MR's exact range, so for a narrow registration inside a hugepage that call fails with EINVAL — the same kernel restriction, which libibverbs works around by widening its own range and retrying per page. That is pre-existing and orthogonal, but it means "exactly the previous behaviour" leaves each such huge page DOFORK-blocked after unregister. We can widen that range too if you think it belongs in this PR; otherwise we'll file it separately. I plan to make the above fixes in this PR and iterate until we reach the expected outcome. Once the implementation is complete, I'd appreciate it if you could review it again. Please let me know if there are any other issues you'd like me to address. |
hi @Icedcoco Thanks for the review! I've pushed changes for all three points: split pending_dereg_ / pending_republish_ so the republish path never does an MR lookup, documented the padding exposure as a caller contract on registerLocalMemory, and made registration narrow-first with widening only on EINVAL. Also added state-machine and HugeTLB tests plus extended the hardware hugepage test. Would appreciate another look when you have a moment, thanks! |
Icedcoco
left a comment
There was a problem hiding this comment.
Static review of head d5814f7: the retry-state split, narrow-first EINVAL fallback, rollback handling, and caller contract address the review concerns. I found no code-level blocker under the documented trusted-peer assumption. This branch currently conflicts with main; before merging, resolve the conflicts while preserving main's RDMA metadata ownership filtering and libibverbs-based deregistration behavior. This was a static-only review; no build or tests were run.
ibv_fork_init() makes ibv_reg_mr() run MADV_DONTFORK over the range it is handed, and the kernel refuses to split a hugetlb VMA at a boundary that falls inside a huge page. A caller that registers a view of a larger hugepage-backed mapping rather than the mapping itself therefore failed with EINVAL below libibverbs, which surfaced as a generic registration error and left such callers unable to use RDMA at all. Widen such a registration outward to the enclosing huge pages before ibv_reg_mr is called, and deregister through that widened base. Both widened ends are hugepage boundaries and a hugetlb VMA is a whole number of those, so a request that lies inside its mapping stays inside it after widening. The published BufferDesc keeps the caller's addr/length so peers cannot reach the alignment padding, and the metadata entry stays at the caller's address. A registration that would be both widened and chunked is refused: chunking would have to publish the padded chunks and make the padding addressable by peers. Such a request failed with EINVAL before the widening existed. Track the range of every live hugetlb-backed MR, not only the widened ones, and refuse a registration whose range overlaps one. Overlap, not a shared base, is the criterion: RdmaContext's MR map silently drops an MR registered at a duplicate key, and unregisterMemoryRegion() madvises MADV_DOFORK over the whole MR range (issue kvcache-ai#3639), which must not be re-opened while a second MR still covers part of it. The check and the claim are one atomic step, because a batch registration runs one worker per buffer. A claim is released only once no MR of that registration is left. A rollback whose ibv_dereg_mr fails keeps the claim of the MR that survived and records the bookkeeping unregisterLocalMemory() needs to finish that cleanup, so a failed registration cannot strand those huge pages for the life of the process. Add rdma_hugetlb_subview_test covering a misaligned sub-view, an already aligned registration, and both orders of a same-hugepage collision. Tighten the store's interior-sub-range test to require the registration to succeed, since the transport now handles it rather than leaving it to fail. Signed-off-by: tan changzhi <544463199@qq.com>
d5814f7 to
db58510
Compare
|
hi @Icedcoco I've rebased onto current main (7a34af8) and force-pushed — head is now db58510, Would you mind taking another look when you get a chance? Thanks! The conflicts were in rdma_transport.h, rdma_transport.cpp and rdma_context.cpp. How they were resolved:
Because the branch now defers to libibverbs rather than madvising, three comments still described MADV_DOFORK at unregister time. They now give the reasons that still hold: I checked the rebase against both parents — no line present in both main and the previous head is missing from the result. |
db58510 to
fb9edfd
Compare
…r state Try the caller's range first and widen to the enclosing huge pages only when ibv_reg_mr reports EINVAL. This restores registrability of disjoint sub-views of one huge page (which worked under RDMAV_HUGEPAGES_SAFE=1) and avoids exposing padding unless the hardware forces the widening. Surface EINVAL from the context layer as an internal error code and translate it back to ERR_CONTEXT before any public return. Split the pending unregister state into pending_dereg_ (the MR may still be live, so a retry must re-enter the per-context MR cleanup) and pending_republish_ (every MR is confirmed gone and only the final updateLocalSegmentDesc() is outstanding, so a retry must never perform an MR lookup). Previously a retry could deregister a newer registration's live MR through the range lookup. A chunked orphan bookkeeping record now supersedes any stale republish entry at the same address, keeping surviving MRs reachable from the caller address. Also publish a chunked unregistration's removals even when a chunk's deregistration failed: the local desc no longer lists them either way, and a stale advertisement keeps peers targeting MRs that are gone on some contexts. Document the caller contract: the widened MR and its published keys cover whole huge pages, so a peer can address padding that may hold application data never registered; callers unwilling to expose it must register hugepage- aligned mappings themselves. Tests: device-free unregister state-machine tests (fake verbs, armable storage plugin publish failures), HugeTLB tests with fake MRs emulating ibv_fork_init, and an extended hardware hugepage test. Signed-off-by: tan changzhi <544463199@qq.com>
fb9edfd to
c8c8b7f
Compare
Description
ibv_fork_init() makes ibv_reg_mr() run MADV_DONTFORK over the range it is handed, and the kernel refuses to split a hugetlb VMA at a boundary that falls inside a huge page. A caller that registers a view of a larger hugepage-backed mapping rather than the mapping itself therefore failed with EINVAL below libibverbs, which surfaced as a generic registration error and left such callers unable to use RDMA at all.
Widen such a registration outward to the enclosing huge pages before ibv_reg_mr is called, and deregister through that widened base. Both widened ends are hugepage boundaries and a hugetlb VMA is a whole number of those, so a request that lies inside its mapping stays inside it after widening. The published BufferDesc keeps the caller's addr/length so peers cannot reach the alignment padding, and the metadata entry stays at the caller's address.
A registration that would be both widened and chunked is refused: chunking would have to publish the padded chunks and make the padding addressable by peers. Such a request failed with EINVAL before the widening existed.
Track the range of every live hugetlb-backed MR, not only the widened ones, and refuse a registration whose range overlaps one. Overlap, not a shared base, is the criterion: RdmaContext's MR map silently drops an MR registered at a duplicate key, and unregisterMemoryRegion() madvises MADV_DOFORK over the whole MR range (issue #3639), which must not be re-opened while a second MR still covers part of it. The check and the claim are one atomic step, because a batch registration runs one worker per buffer.
A claim is released only once no MR of that registration is left. A rollback whose ibv_dereg_mr fails keeps the claim of the MR that survived and records the bookkeeping unregisterLocalMemory() needs to finish that cleanup, so a failed registration cannot strand those huge pages for the life of the process.
Add rdma_hugetlb_subview_test covering a misaligned sub-view, an already aligned registration, and both orders of a same-hugepage collision. Tighten the store's interior-sub-range test to require the registration to succeed, since the transport now handles it rather than leaving it to fail.
Suggested Merge Priority
Module
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
How Has This Been Tested?
Test commands:
# Example: bash scripts/run_ci_test.shTest results:
Checklist
Signed-off-bytrailer certifying the DCO./scripts/code_format.shAI Assistance Disclosure