Skip to content

[2/3] [Store] Add EGM-backed Store pool over NVLink - #3335

Merged
Aionw merged 3 commits into
kvcache-ai:mainfrom
neverhook:codex/egm-store-pool-pr2966
Oct 15, 2026
Merged

Aionw merged 3 commits into
kvcache-ai:mainfrom
neverhook:codex/egm-store-pool-pr2966

Conversation

@neverhook

@neverhook neverhook commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a default-off, Provider-owned EGM Store pool for RFC #2914. HOST_NUMA
allocations are mounted as ordinary NVLink Store segments; the Master schema,
placement policy and Consumer Put/Get API are unchanged.

This is [2/3]: #2966 supplies the merged Transfer Engine prerequisite,
this PR adds the Store pool, and #3431 enables direct remote GPU reads. This
branch is based on main; #3431 remains its child.

Implementation

  • enable_egm_store_pool enables the pool; egm_numa_nodes selects auto or
    a comma-separated NUMA list. EGM requires protocol=nvlink, nonzero global
    capacity and local_buffer_size=0. The parsed config is passed explicitly
    through a private setup overload; auto-discovery is a named mode, not an empty
    node-list sentinel. Positional setup keeps EGM disabled.
  • The normal Client initialization path can now install nvlink with
    discovery disabled. An EGM Provider checks the actual engine before allocating:
    it must be classic Transfer Engine with NVLink installed, not TENT or a
    different transport selected by discovery.
  • The existing global-segment loop allocates and mounts EGM before local
    services start. RealClient directly owns the native HOST_NUMA allocations.
    Capacity is rounded down to the largest Store/CUDA alignment, divided across
    the selected nodes and balanced into chunks using the existing helper.
    max_mr_size applies only to the EGM branch, not all NVLink registrations.
  • Cleanup is terminal. After callers quiesce in-flight requests, close stops
    local services and EGM offload workers, unmounts EGM segments, then
    releases backing memory. A failed unmount or CUDA release retains the affected
    allocation until process exit and logs the error; other cleanup continues.
    close() reports failure but clears the Python client's native references.
    Calling it again does not retry resource recovery.
  • Failed or throwing mounts go through the same teardown. If there is a Client
    record, cleanup can unmount and release the allocation; a missing record or
    failed unmount retains it. The outer setup catch also covers later exceptions
    such as FileStorage construction, then rethrows. This does not promise
    synchronous removal of an uncertain remote record.

The earlier factory/hooks, caller-supplied UUID transaction, retry state machine
and global Python setup guard have been removed. Generic mount/MR failure cleanup
stays with #2336; the Python repeated-setup contract is tracked in #4294.

Configuration

Use MC_MS_AUTO_DISC=0 on both Provider and Consumer for explicit NVLink setup.
If discovery is enabled, MC_FORCE_MNNVL=1 selects MNNVL on hosts with RDMA
HCAs; the EGM Provider still checks what was actually installed. Full
Provider/Consumer examples are in the updated Python API and supported-protocols
documentation.

Scope and review size

One logical Store commit, 15 files, +790/-52 lines (before the simplification:
+2,257/-61). No Master, TransferMetadata, RDMA/TENT, wire-schema or public C++
signature changes. The GB200 harness is separate from this production branch.

How Has This Been Tested?

  • clang-format 20 on changed C++ lines and git diff --check.
  • All applicable PR-scoped hooks, including CMake formatting.
  • Configuration/capacity: 13 cases in each build; CUDA-on VMM: 2 CTest entries.
  • CUDA-on/off Store regressions: 6 CTest entries each; real Client/TCP/chunking/caller-engine/backend-selection regressions: 11/11 and 12/12.
  • CUDA-off Transfer Engine, Store, Master and Python binding build.
  • CPU/TCP tensor snapshot: 3/3 with no skips; probe exports and close/fresh-setup smoke.
  • New-head strict Sphinx documentation build.
  • New-head complete CTest sweep (232/232) and GitHub Actions CI Gate.

Local validation uses the composed stack at #3431, on Linux ARM64 with CUDA
driver stubs where needed. It does not replace either PR's full CI matrix or
MNNVL hardware validation. The previous revision's results are not reused.

The earlier upstream CMake formatting issue is fixed in the new base, so no
hook exception is needed. Repository-wide formatting is not a gate. Local
Sphinx validation was blocked by a dependency download; the strict Sphinx
build, complete CTest sweep and CI Gate have passed in GitHub Actions for this
revision.

No GB200 rerun was performed for this review update. Real MNNVL allocation,
transfer and terminal cleanup still need hardware evidence; earlier GB200
results are historical support, not validation of this implementation.

Module

  • Mooncake Store (mooncake-store)
  • Integration (mooncake-integration)
  • Docs

Type of Change

  • New feature
  • Documentation update

Checklist

AI Assistance Disclosure

  • AI tools were used

Codex assisted with the implementation, independent code review, tests and PR
preparation. The human submitter remains responsible for reviewing and defending
every changed line.

@neverhook

Copy link
Copy Markdown
Contributor Author

Current Store head is a94583d4, with #2966 (3c850601) as its only prerequisite. The production increment is default-off Provider EGM capacity, aligned NUMA/chunk planning, ordinary nvlink segment publication, and retryable reverse cleanup; local_buffer_size=0 remains intentional. Local CUDA-on/off focused tests, Python binding, clang-format 20, diff/YAML checks, and strict Sphinx build pass. The separate GB200 branch records HBM→EGM Put and EGM→HBM Get latency/bandwidth plus correctness and teardown evidence; results are pending hardware execution.

@bhaktatejas922

Copy link
Copy Markdown

Very interested in this on GB300 NVL72. We run PD-disaggregated serving there with MNNVL/IMEX and fabric-handle KV transfer already in production, and a store pool reachable over NVLink instead of RDMA would be a major win for cross-engine prefix restore at long context. Happy to run the provider/consumer validation flow on real GB300 hardware and report results here if useful.

@neverhook

Copy link
Copy Markdown
Contributor Author

Very interested in this on GB300 NVL72. We run PD-disaggregated serving there with MNNVL/IMEX and fabric-handle KV transfer already in production, and a store pool reachable over NVLink instead of RDMA would be a major win for cross-engine prefix restore at long context. Happy to run the provider/consumer validation flow on real GB300 hardware and report results here if useful.

Thanks a lot for offering to help with the validation — this would be extremely valuable.

A real GB300 NVL72 environment with MNNVL/IMEX already in production is especially interesting for this PR. The current validation branch was prepared around the Provider/Consumer flow on GB200/NVL72, so having the same path exercised independently on GB300 would give us very useful additional coverage.

Please feel free to run the validation flow and report the results here. Correctness and teardown behavior are the most important parts, and any transfer latency/bandwidth numbers would also be very helpful.

Really appreciate you volunteering the hardware and time for this.

@neverhook
neverhook force-pushed the codex/egm-store-pool-pr2966 branch from a94583d to 687b9b1 Compare August 13, 2026 14:09
@neverhook
neverhook force-pushed the codex/egm-store-pool-pr2966 branch from 687b9b1 to 74c6145 Compare August 13, 2026 16:22
@neverhook

Copy link
Copy Markdown
Contributor Author

Scope update: the remote GPU-read no-staging change has been removed from this Store pool commit and submitted independently as #3431. This PR is again Store-only (74c61458, +1,104/-28 relative to #2966); the separate GB200 validation branch will compose both changes for EGM-to-HBM testing.

@neverhook

Copy link
Copy Markdown
Contributor Author

Rebased onto the updated #2966. No changes to the EGM pool patch; the SSD-test fix in #3870 now comes from the base. Fresh CI has been triggered.

@neverhook
neverhook force-pushed the codex/egm-store-pool-pr2966 branch from 0d8d0be to 7933975 Compare September 10, 2026 10:42
@neverhook

Copy link
Copy Markdown
Contributor Author

Rebased this on the refreshed prerequisite and kept main’s new Store sources and shared allocation header. The EGM code did not need any further changes.

@neverhook
neverhook force-pushed the codex/egm-store-pool-pr2966 branch 3 times, most recently from d2e25b4 to 1a9a6c8 Compare September 23, 2026 07:00
@neverhook

Copy link
Copy Markdown
Contributor Author

Rebased onto main now that #2966 is merged, so this is back to a Store-only diff. Cleanup-pending mounts are no longer eligible for heartbeat remount, and an overlap rejection won't unregister an existing buffer. I also serialized close/retry and changed final-failure retention to keep only unsafe allocations, so the Client can shut down. The added failure-path tests pass in CUDA-on and CUDA-off builds; fresh CI has been triggered.

@Aionw Aionw left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The EGM ownership model still makes sense. However, most of the Store-side complexity in this revision is there so that each step can be injected in unit tests; production does not need it. Two facts already in the tree make most of it unnecessary:

  1. NvlinkTransport recognizes HOST_NUMA ranges by exact address (FindExactOwnedRange), so an EGM chunk can be mounted through the ordinary Client::MountSegment(ptr, size, "nvlink").
  2. The existing global-segment path already has a teardown order: ~Client unmounts every entry in mounted_segments_, and RealClient frees the backing memory afterwards. NvlinkHostNumaAllocation is already an RAII owner whose destructor calls Release().

Suggested shape:

  • Add an nvlink case to Client::InitTransferEngine, next to ascend/ubshmem/sunrise_link, and drop the manual TE factory.
  • Allocate EGM chunks as one more branch of the existing allocation loop in setup_internal. Hold them in std::vector<std::unique_ptr<NvlinkHostNumaAllocation>>, mount them through the same MountSegment call, and release them after client_.reset().
  • On release failure, leak and log, as setup_segment_memory_must_leak_ already does.

With that, the following can be deleted: client_internal.h, the SegmentMountOperations seams, the EgmStorePoolHooks/allocation interface, the retryable Setup/Rollback/Teardown state machine, the cleanup-pending setup guard, and most of egm_store_pool_test.cpp. The Store part should shrink substantially. Details inline.

This partly revisits my earlier comments. Injecting a pre-built TE and sharing a caller-supplied-ID mount transaction ended up needing more seams than they save; a transport case in InitTransferEngine plus the existing MountSegment is simpler.

Comment thread mooncake-store/src/real_client.cpp Resolved
Comment thread mooncake-store/include/real_client.h Resolved
Comment thread mooncake-store/src/client_internal.h Resolved
Comment thread mooncake-store/src/client_service.cpp Resolved
Comment thread mooncake-store/src/client_service.cpp Resolved
Comment thread mooncake-store/src/egm_store_pool.cpp Resolved
Comment thread mooncake-store/src/real_client.cpp Resolved
Comment thread mooncake-store/src/real_client.cpp Outdated
// The underlying Client is already initialized even if the pool
// rolled back completely. Retain the pool marker so another setup is
// rejected until close() tears down that Client.
egm_store_pool_ = std::move(pool);

@Aionw Aionw Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The whole cleanup-pending lifecycle follows from letting Teardown fail partway and making it retryable:

  • the pool is kept as a marker after a failed setup (here);
  • re-setup is rejected (L1505);
  • the destructor calls RetainAllocationsForProcessLifetime;
  • close() and ensure_can_setup change in store_py.cpp;
  • test_store_setup_lifecycle.py is added to cover it.

The existing segment path handles a release failure by leaking and logging (setup_segment_memory_must_leak_). Could EGM do the same? Then none of the above is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The retry machinery and global setup guard are gone. Close is now terminal: it reports a cleanup error, clears both Python native references and continues closing other resources. Repeated setup semantics are tracked separately in #4294.

I kept an explicit EGM-only unmount before releasing each owner. Client destruction logs unmount failures but cannot report them back, so relying on destruction alone could free memory after an unconfirmed Master cleanup. Failed or ambiguous mounts and failed unmounts retain their allocation until process exit; CUDA release failures do the same. FileStorage workers are stopped first, since they hold a Client reference and may access those segments. There is no retry queue or background recovery.

Leaving this open for your review of those local safety checks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed on the explicit unmount: ~Client can't report failures back, so it isn't enough to decide whether the memory is safe to free.

One simplification: the unmount loop and the release loop could be merged. Release() only requires the transport unregister to be complete, and UnmountSegment already does that (Master unmount + TE unregister), so each owner can be released right after its unmount succeeds rather than waiting for client_.reset(). That drops the if (!owner) continue in both loops and the duplicated first-error bookkeeping:

for (auto it = egm_segment_ptrs_.rbegin(); it != egm_segment_ptrs_.rend(); ++it) {
    auto &owner = *it;
    auto unmounted = client_->UnmountSegment(owner->base(), owner->length());
    if (!unmounted) {
        // Failed mounts may have no Client record; retain the memory.
        LOG(ERROR) << ...;
        record_error(unmounted.error());
        (void)owner.release();
        continue;
    }
    if (auto released = owner->Release(); !released.ok()) {
        LOG(ERROR) << ...;
        record_error(ErrorCode::INTERNAL_ERROR);
        (void)owner.release();
    }
}
egm_segment_ptrs_.clear();

Unless something between the unmount and client_.reset() can still touch those ranges, which I couldn't find. If there is something, a comment saying why the two phases are separate would help.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed the first three suggestions. I kept the two-phase cleanup because Client’s background replica copy/move workers may still hold local source slices after UnmountSegment. Unmount removes registration but does not wait for those workers. Added a comment explaining why backing memory stays alive through Client teardown, without claiming this is a GPU completion barrier.

Comment thread mooncake-store/tests/CMakeLists.txt Resolved
@neverhook

Copy link
Copy Markdown
Contributor Author

@Aionw, I've reworked this around the existing Store path. The earlier version had grown a separate lifecycle around EGM, with interfaces used mainly by the tests. I agree that was too much machinery for adding another kind of segment backing.

NVLink now uses normal transport initialization. EGM allocation and mounting run in the existing segment loop, before the IPC/HTTP servers start, and RealClient owns the native HOST_NUMA allocations directly. The factory, allocation adapter, hooks, caller-supplied UUID transaction and retryable-close state machine are gone.

I kept the max_mr_size cap local to EGM. Moving it into the generic NVLink path would also change ordinary registration and dynamic mounts, which this pool doesn't need.

Close still checks each EGM unmount result: Client destruction only logs failures, so it cannot tell the allocation owner whether Master cleanup succeeded. FileStorage workers stop first because they can still access those segments. A failed or uncertain mount/unmount retains the allocation until process exit; a CUDA release failure retains whatever resources remain. Close reports the error and finishes without keeping a client for another cleanup attempt. This trades reclamation after an error for a simpler lifecycle. It still requires callers to quiesce in-flight requests before close and does not promise immediate remote cleanup.

Generic mount/MR rollback remains outside this PR; related work is in the separate, still-open #2336. The Python repeated-setup guard is also removed, with that API decision tracked in #4294. Tests now focus on config/capacity rules and real Client initialization.

CI is green, including the full CTest sweep and docs build. This revision has not been rerun on GB200; the earlier hardware results aren't validation of the new cleanup behavior.

Could you take another look, particularly at the EGM-only cap and explicit unmount checks? I've left those two inline discussions open for your confirmation.

Comment thread mooncake-store/src/real_client.cpp Resolved
Comment thread mooncake-store/src/real_client.cpp Outdated
auto mount_result =
client_->MountSegment(ptr, mount_size, protocol, seg_location);
tl::expected<void, ErrorCode> mount_result;
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this try/catch here because only the EGM path needs to handle a throw? For non-EGM segments it just rethrows. The EGM handling in the catch also looks redundant to me:

  • MountSegmentAndGetId inserts into mounted_segments_ only after the Master mount succeeds. If the mount fails or throws before that point, the Client has no record for this range.
  • On failure, the ConfigDict path calls tearDownAll_internal(). There, UnmountSegment(base, len) fails because the record is missing, and teardown already responds by releasing the owner so the memory is retained until the process exits. That is the same outcome as this catch block.
  • The one case where the outcomes differ is when the record was already inserted and EnsureStorageControlPlaneStarted() then throws. Teardown could unmount and free that memory safely, but this catch leaks it.

Could we drop this try/catch, along with the EGM-specific release/pop in the !mount_result branch below, and rely on teardown's existing rule that a failed unmount retains the allocation? A short comment in teardown noting that failed mounts have no Client record would make the leak path explicit. The catch (...) { tearDownAll_internal(); throw; } in the ConfigDict overload (L1535) could go too, keeping only the !result teardown.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the inner catch and the early release()/pop_back() on mount failure. The owner stays in the cleanup list, so teardown can reclaim it when a Client record exists. A missing record or failed unmount still retains the allocation; there's a short comment at that point.

I kept the outer ConfigDict catch. FileStorage construction can throw after EGM segments have been mounted, while the Python wrapper still owns the native client. That catch runs the same terminal teardown and rethrows; without it, those resources stay live until the caller closes or destroys the wrapper. This keeps exception cleanup immediate without adding retry state. Does that boundary look reasonable to you?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, that boundary makes sense. FileStorage construction can throw after the EGM segments are mounted, and the inner cleanup is gone now, so keeping only the outer ConfigDict catch is fine.

@neverhook
neverhook force-pushed the codex/egm-store-pool-pr2966 branch from 85e41ff to 3cb69f9 Compare October 1, 2026 13:12
Install torch 2.14.0 in the PG CPU test environment so the loader selects a backend included in the wheel. Keep all PG tests and their runner condition unchanged.

Copy link
Copy Markdown
Contributor Author

@ykwd @stmatengss Could you review this PR? CI is green, and #3431 depends on it.

Comment thread mooncake-store/src/real_client.cpp Outdated
ptr, AscendSegmentDeleter{this->protocol});
}
} else if (this->protocol == "sunrise_link") {
if (!egm_config.enabled) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: wrapping the whole deleter dispatch in if (!egm_config.enabled) { ... } re-indents ~40 lines of unrelated ascend/sunrise/ub/hugepage/vram code. Could EGM just be the first branch of the existing chain instead? The behavior is the same and the diff gets a lot smaller:

if (egm_config.enabled) {
    // Owned by egm_segment_ptrs_.
} else if (this->protocol == "ascend" || this->protocol == "ubshmem") {
    ...

Comment thread mooncake-store/src/real_client.cpp Outdated

if (!seg_numa_nodes.empty()) {
if (egm_config.enabled) {
// Adopt even a partial Create result before handling failure.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The partial owner is pushed into egm_segment_ptrs_ and then popped on every failure path: it is either released here or release()d to leak, so it never stays in the list. A local owner that is pushed only on success would avoid the emplace/pop pair and this comment:

std::unique_ptr<NvlinkHostNumaAllocation> owner;
auto status = NvlinkHostNumaAllocation::Create(
    egm_numa_nodes[egm_node_index], segment_size, alignment, owner);
if (!status.ok()) {
    LOG(ERROR) << "EGM allocation failed: " << status;
    if (owner && !owner->Release().ok()) {
        LOG(ERROR) << "EGM partial allocation cleanup failed; "
                      "retaining until process exit";
        (void)owner.release();
    }
    return tl::unexpected(ErrorCode::INTERNAL_ERROR);
}
ptr = owner->base();
mapped_size = owner->length();
egm_segment_ptrs_.push_back(std::move(owner));

Comment thread mooncake-store/include/client_service.h Outdated
uint64_t quota_bytes = 0);

private:
friend class RealClient;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This friendship is back, and as far as I can see its only use is the TENT/NVLink check at real_client.cpp:1091 reading client_->transfer_engine_. Making RealClient a friend opens up all of Client's private state for a single read. Could Client expose a narrow const query for this instead, for example one that reports whether the classic engine has a given transport installed?

@Aionw Aionw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@ykwd

ykwd commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Let's wait CI to pass

Copy link
Copy Markdown
Contributor Author

@ykwd Could you rerun the failed CI jobs? The Python 3.12 wheel build was interrupted by a runner shutdown (exit 137). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants