Skip to content

[Store] auto-enable MC_STORE_MEMCPY in TCP-only environments - #1936

Merged
alogfans merged 1 commit into
kvcache-ai:mainfrom
openanolis:yingyu/tcp
Apr 21, 2026
Merged

[Store] auto-enable MC_STORE_MEMCPY in TCP-only environments#1936
alogfans merged 1 commit into
kvcache-ai:mainfrom
openanolis:yingyu/tcp

Conversation

@dtcccc

@dtcccc dtcccc commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Description

Background

#577 disabled MC_STORE_MEMCPY by default (false) for better RDMA performance stability — RDMA transfers are more stable and resource-efficient than memcpy operations. This was the correct decision for RDMA deployments.

However, in TCP-only environments (where no RDMA hardware is available), disabling memcpy forces same-host transfers to go through TCP loopback, which is significantly less efficient than a direct memcpy.

What this PR does

This PR makes the MC_STORE_MEMCPY default transport-aware without conflicting with #577's intent:

  • When MC_STORE_MEMCPY is not explicitly set, the system auto-detects installed transports via the new TransferEngine::isTcpOnly() API and enables memcpy only when TCP is the sole transport.
  • When MC_STORE_MEMCPY is explicitly set by the user (to 0 or 1), the user's choice is always respected.
  • RDMA environments are completely unaffected — the default remains false, exactly as Disable memcpy by default and improve stress workload test #577 intended.
Scenario Before After
Not set, RDMA available false false (unchanged, per #577)
Not set, TCP-only false true (auto-enabled)
MC_STORE_MEMCPY=0 (explicit) false false (user respected)
MC_STORE_MEMCPY=1 (explicit) true true (user respected)

Implementation

Added TransferEngine::isTcpOnly() that queries MultiTransport::transport_map_ to check whether TCP is the only installed transport (size() == 1 && count("tcp") == 1). This is future-proof: any new transport protocol registered via installTransport() is automatically accounted for — no protocol whitelist/blacklist to maintain.

The TENT path returns false unconditionally since TENT already rejects TCP loopback transfers when MC_STORE_MEMCPY is disabled.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • PyTorch Backend (mooncake-pg)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Other

How Has This Been Tested?

Checklist

  • I have performed a self-review of my own code.
  • I have formatted my own code using ./scripts/code_format.sh before submitting.
  • I have updated the documentation.
  • I have added tests to prove my changes are effective.

When MC_STORE_MEMCPY is not explicitly set, auto-detect based on
installed transports: enable memcpy only when TCP is the sole
transport (no RDMA, NVLink, etc.), since TCP loopback is less
efficient than direct memcpy for same-host transfers. In RDMA
environments the default remains disabled, as RDMA is more
resource-efficient.

Add TransferEngine::isTcpOnly() API that checks whether TCP is the
only installed transport via MultiTransport::transport_map_. This
is future-proof: any new transport registered via installTransport()
is automatically accounted for without maintaining a protocol list.

TENT path returns false unconditionally since TENT already rejects
TCP loopback without MC_STORE_MEMCPY.

Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an auto-detection mechanism for the MC_STORE_MEMCPY setting. When the environment variable is not explicitly set, the system now checks if the environment is TCP-only. If so, memcpy is enabled to optimize performance by avoiding TCP loopback overhead; otherwise, it remains disabled for more efficient transports like RDMA. This logic is implemented across TransferSubmitter, TransferEngine, and MultiTransport classes. I have no feedback to provide.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@alogfans
alogfans merged commit 38c3975 into kvcache-ai:main Apr 21, 2026
17 checks passed
stmatengss added a commit that referenced this pull request May 16, 2026
…PY auto-enables (#2001)

* [Store] fix: require same-process endpoint for LOCAL_MEMCPY strategy

isLocalTransfer compared only the IP of handle.transport_endpoint_ to
the local endpoint, so two processes on the same host (same IP, different
ports) were treated as LOCAL_MEMCPY-eligible. The memcpy worker then
dereferenced handle.buffer_address_, which is a virtual address only valid
in the owning process, and segfaulted inside __memcpy_avx512_unaligned_erms.

This was latent before #1936 (MC_STORE_MEMCPY defaulted to off). The
TCP-only auto-enable exposed it on multi-process workloads such as the
TorchSpec inference/trainer pipeline.

Compare the full transport endpoint instead, matching the check already
used by Client::IsReplicaOnLocalMemory. Cross-process same-host transfers
now correctly fall through to TRANSFER_ENGINE; same-process transfers
still take the memcpy fast path.

Fixes the crash reported with MC_STORE_MEMCPY auto-enabled on TCP-only hosts.

---------

Co-authored-by: Teng Ma <teng-ma@linux.alibaba.com>
A-Liuhao pushed a commit to A-Liuhao/Mooncake that referenced this pull request Jun 25, 2026
…-ai#1936)

When MC_STORE_MEMCPY is not explicitly set, auto-detect based on
installed transports: enable memcpy only when TCP is the sole
transport (no RDMA, NVLink, etc.), since TCP loopback is less
efficient than direct memcpy for same-host transfers. In RDMA
environments the default remains disabled, as RDMA is more
resource-efficient.

Add TransferEngine::isTcpOnly() API that checks whether TCP is the
only installed transport via MultiTransport::transport_map_. This
is future-proof: any new transport registered via installTransport()
is automatically accounted for without maintaining a protocol list.

TENT path returns false unconditionally since TENT already rejects
TCP loopback without MC_STORE_MEMCPY.

Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
A-Liuhao pushed a commit to A-Liuhao/Mooncake that referenced this pull request Jun 25, 2026
…PY auto-enables (kvcache-ai#2001)

* [Store] fix: require same-process endpoint for LOCAL_MEMCPY strategy

isLocalTransfer compared only the IP of handle.transport_endpoint_ to
the local endpoint, so two processes on the same host (same IP, different
ports) were treated as LOCAL_MEMCPY-eligible. The memcpy worker then
dereferenced handle.buffer_address_, which is a virtual address only valid
in the owning process, and segfaulted inside __memcpy_avx512_unaligned_erms.

This was latent before kvcache-ai#1936 (MC_STORE_MEMCPY defaulted to off). The
TCP-only auto-enable exposed it on multi-process workloads such as the
TorchSpec inference/trainer pipeline.

Compare the full transport endpoint instead, matching the check already
used by Client::IsReplicaOnLocalMemory. Cross-process same-host transfers
now correctly fall through to TRANSFER_ENGINE; same-process transfers
still take the memcpy fast path.

Fixes the crash reported with MC_STORE_MEMCPY auto-enabled on TCP-only hosts.

---------

Co-authored-by: Teng Ma <teng-ma@linux.alibaba.com>
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.

3 participants