Skip to content

feat: Add strict_local_numa to hard-exclude cross-NUMA RDMA rails - #3468

Merged
staryxchen merged 4 commits into
kvcache-ai:mainfrom
XiaokunDing:mr_strict_numa
Sep 1, 2026
Merged

staryxchen merged 4 commits into
kvcache-ai:mainfrom
XiaokunDing:mr_strict_numa

Conversation

@XiaokunDing

@XiaokunDing XiaokunDing commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Background

On dual-socket / multi-NUMA machines, selecting an RDMA NIC from a remote NUMA node for GPU buffer transfers can introduce unnecessary cross-socket traffic and unstable performance. In some deployments, it may also increase the chance of RDMA failures such as LOC_PROT or QP transition errors.

The existing numa_penalties setting only provides a soft preference. A remote NUMA NIC can still be selected when its score is better due to EWMA bandwidth, inflight bytes, or probe / round-robin sampling. This is not strict enough for environments where GPU traffic must stay on the local NUMA node.

Change

This MR adds a strict_local_numa switch for RDMA device selection.

When enabled, the RDMA scheduler excludes the cross-NUMA tier from the normal candidate list, so weighted selection, probe mode, and round-robin selection will not actively pick a remote NUMA NIC. If no same-NUMA candidate is available, the existing fallback still retries all tiers to avoid making the node unusable.

The CUDA topology discovery path is also adjusted so GPU Tier-0 devices are limited to same-NUMA NICs. PCIe distance is now used only as a secondary ranking within the same NUMA node.

Example Configuration

{
  "topology": {
    "rdma_whitelist": [
      "mlx5_bond_1",
      "mlx5_bond_4",
      "mlx5_bond_3",
      "mlx5_bond_2",
      "mlx5_bond_7",
      "mlx5_bond_6",
      "mlx5_bond_8",
      "mlx5_bond_5"
    ]
  },
  "transports": {
    "rdma": {
      "enable": true,
      "numa_penalties": [1.0, 5.0, 100000.0],
      "strict_local_numa": true
    }
  }
}

Compatibility

strict_local_numa is disabled by default, so existing soft NUMA penalty behavior is preserved unless explicitly enabled.

Description

Module

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

Type of Change

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

How Has This Been Tested?

Test commands:

# Example: bash scripts/run_ci_test.sh

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

@alogfans alogfans 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.

strict_local_numa still does not provide hard exclusion semantics in the current implementation.

There are three remaining paths where a cross-NUMA NIC can still be selected:

  1. Baseline mode bypasses the flag entirely
    In quota.cpp, the !smart_selection_enabled_ path iterates ranks until it finds the first non-empty one, but it does not apply any strict_local_numa filtering. If all local ranks are empty, it will still pick the cross-NUMA tier.

  2. Smart-mode fallback re-adds cross-NUMA devices
    In buildCandidates(), the first pass skips the last rank when strict_local_numa is enabled, but if the filtered candidate set becomes empty, the fallback path rebuilds candidates from all ranks. That means remote NUMA NICs are still reintroduced under strict mode.

  3. CUDA topology can hide cross-NUMA NICs inside rank 0
    In cuda_probe.cpp, when no same-NUMA NIC exists, the fallback path places the closest remote NICs into device_list[0]. After that, the selector can no longer distinguish them from true local-NUMA devices, so rank-based filtering is no longer sufficient.

I think the intended strict-mode semantics should be:

  • when strict_local_numa == true, cross-NUMA NICs must never enter the eligible set;
  • if no same-NUMA NIC exists for the location, return DeviceNotFound instead of falling back to a remote NIC;
  • baseline mode, smart selection, and fallback should all share the same rank-filtering rule.

In other words, this change currently implements a strong preference against cross-NUMA NICs, but not a true hard exclusion yet.

@XiaokunDing

Copy link
Copy Markdown
Contributor Author

strict_local_numa still does not provide hard exclusion semantics in the current implementation.

There are three remaining paths where a cross-NUMA NIC can still be selected:

  1. Baseline mode bypasses the flag entirely
    In quota.cpp, the !smart_selection_enabled_ path iterates ranks until it finds the first non-empty one, but it does not apply any strict_local_numa filtering. If all local ranks are empty, it will still pick the cross-NUMA tier.
  2. Smart-mode fallback re-adds cross-NUMA devices
    In buildCandidates(), the first pass skips the last rank when strict_local_numa is enabled, but if the filtered candidate set becomes empty, the fallback path rebuilds candidates from all ranks. That means remote NUMA NICs are still reintroduced under strict mode.
  3. CUDA topology can hide cross-NUMA NICs inside rank 0
    In cuda_probe.cpp, when no same-NUMA NIC exists, the fallback path places the closest remote NICs into device_list[0]. After that, the selector can no longer distinguish them from true local-NUMA devices, so rank-based filtering is no longer sufficient.

I think the intended strict-mode semantics should be:

  • when strict_local_numa == true, cross-NUMA NICs must never enter the eligible set;
  • if no same-NUMA NIC exists for the location, return DeviceNotFound instead of falling back to a remote NIC;
  • baseline mode, smart selection, and fallback should all share the same rank-filtering rule.

In other words, this change currently implements a strong preference against cross-NUMA NICs, but not a true hard exclusion yet.

Thanks for the careful review — you're right that the original change was only a strong preference, not a hard exclusion. I've reworked it so strict_local_numa now enforces true hard-exclusion semantics across all three paths.

shawnding added 2 commits August 31, 2026 11:15
Conflicts:
	mooncake-transfer-engine/tent/include/tent/transport/rdma/quota.h
	mooncake-transfer-engine/tent/src/transport/rdma/quota.cpp

@staryxchen staryxchen 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.

Hard exclusion is incomplete in a few places outside DeviceSelector. Inline comments cover unknown NUMA/wildcard, the worker retry path, the unconditional CUDA rank-0 change, and the env-var bool parsing.

One item that cannot be attached to this diff: ROCm / MemoryProber still promote the closest-PCIe NIC into rank 0 even when it is remote (rocm_probe.cpp, memory_prober.cpp). On those paths a cross-NUMA NIC never reaches rank 2, so strict_local_numa does not exclude it. Please apply the same same-NUMA-only rank-0 rule used in cuda_probe.cpp, or the flag is CUDA-only.

Comment on lines +213 to +217
int dist =
getPciDistance(device.pci_bus_id.c_str(), pci_bus_id);
distance_map[dist].push_back(nic_id);
min_distance = std::min(min_distance, dist);
}

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.

Hard exclusion currently treats “NUMA/location unknown” the same as “cross-NUMA”, so allocations that should still pick a NIC fail with DeviceNotFound.

isNumaRankEligible() drops the last rank whenever the flag is on. That is only correct when rank 2 means “known remote”. Two discovery paths put every NIC in that rank when information is missing:

  1. numa_node == -1 here: rank 0/1 are filled only when GPU and NIC NUMA are known and equal. If sysfs returns -1 (VMs, some GPUs, often mlx5_bond_*), all NICs land in rank 2.
  2. Wildcard * from insertFallbackMemEntry(): every NIC is placed in device_list[2]. Workers also fall back to * when location cannot be resolved.

Please apply hard exclusion only when both the memory location and the NIC have a known NUMA id and they differ. If either side is unknown, keep the old soft-penalty path. A test for numa_node == -1 and one for allocate against * would cover this.

Comment on lines +114 to +115
params.strict_local_numa =
conf->get("transports/rdma/strict_local_numa", false);

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.

strict_local_numa is not applied on the worker retry path, so a cross-NUMA NIC can still be posted after the first attempt fails.

Comment on lines +204 to +208
// collapse (ties / realpath failure) and would otherwise pick a remote
// NIC. Cross-NUMA NICs are never promoted here: when no same-NUMA NIC
// exists rank 0 stays empty and all NICs fall into the cross-NUMA rank,
// so strict_local_numa selection can hard-exclude them.
int min_distance = INT_MAX;

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 CUDA rank-0 rewrite is not gated on strict_local_numa. A remote NIC that previously sat in rank 0 (closest PCIe / collapsed distance) now always sits in rank 2 and takes the default 10× numa_penalties hit even with the flag off. That may be desirable, but it contradicts the compatibility note that soft-penalty behavior is unchanged unless the flag is enabled. Please either gate the topology change on the flag, or document it as an intentional default ranking change.

Comment on lines +170 to +171
setConfig(config, "MC_STRICT_LOCAL_NUMA",
"transports/rdma/strict_local_numa");

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.

MC_STRICT_LOCAL_NUMA=1 will not turn the feature on. setFromString stores "1" as an integer; get(..., false) then fails the JSON bool conversion and returns the default false. Only "true"/"false" work. Please accept 1/0, or document that the env var must be true.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 1, 2026
@catyans

catyans commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks—the source-side selector, unknown-NUMA handling, and env parsing concerns are addressed. One target-side escape remains in the production worker path.

selectOptimalDevice() selects from the first non-empty target rank and only prefers a same-NUMA NIC within that rank; if none exists, it keeps the cross-NUMA choice instead of scanning later ranks or failing. selectFallbackDevice() filters cross-NUMA sdev, but never filters tdev. A remote topology with a cross-NUMA NIC in rank 0 and a local NIC in rank 1 can therefore still post on the remote target rail, both initially and on retry, while strict_local_numa=true.

The new tests cover DeviceSelector, not these Workers paths. Could the same topology-aware eligibility rule be applied to every target candidate, with a worker-path regression test proving that initial selection and retry return DeviceNotFound rather than choosing a known cross-NUMA target?

@staryxchen staryxchen 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

@staryxchen
staryxchen merged commit 0f66684 into kvcache-ai:main Sep 1, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation run-ci Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants