Files
Strata/engine/tests/platform/numa_balancing_test.cpp
T
Niko1221 87c9821bb1 HIP Linux: keep the kernel's NUMA balancing off the engine's memory (#4866, from PR #4867)
With kernel.numa_balancing=1 the NUMA scanner marks the PTEs of the expert arena (registered with hipHostRegister, a KFD userptr range) PROT_NONE
to sample which node touches it; each change invalidates the range and KFD evicts all of the process's GPU queues until it is validated again.
On a two-socket host that was 77-236 s of eviction per engine start and the "no progress for 60 s" stops (7 of 20 fresh 1K prompts), with free
RAM and no swap. The engine now sets MPOL_LOCAL (the same first-touch placement, but the scanner skips the memory) at the top of main(), before
any thread is made, when numa_balancing is on and no policy was set by the user (numactl keeps its own). STRATA_NUMA_BALANCING=keep leaves the
default policy. HIP builds on Linux only; the reporter's PR also changed the CUDA engine, which this commit does not.

Ported from PR #4867 by vivienfanghuagood (header, test, main() call; the hunks moved under engine/ and gated on HIP). The author line of the
original commit is not kept here: the commit is made as the repository owner, the PR author's work is named in this message. Test: numa_balancing_test (the decision, header-only).
2026-11-19 10:56:23 +01:00

30 lines
1.2 KiB
C++

// The NUMA-balancing opt-out's decision (include/strata/platform/numa_balancing.hpp): no GPU, no NUMA box needed.
#include <cstdio>
#include "strata/platform/numa_balancing.hpp"
using namespace strata::platform::numa_balancing;
static int failed = 0;
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
int main() {
// balancing on (1, or 2 = memory tiering mode) and the default policy: set MPOL_LOCAL
CHECK(want_local(1, kMpolDefault, false));
CHECK(want_local(2, kMpolDefault, false));
// balancing off, or unreadable (no /proc, not Linux): nothing to do
CHECK(!want_local(0, kMpolDefault, false));
CHECK(!want_local(-1, kMpolDefault, false));
// a policy the user chose (numactl: 1 = preferred, 2 = bind, 3 = interleave; or MPOL_LOCAL already) is kept
CHECK(!want_local(1, 1, false));
CHECK(!want_local(1, 2, false));
CHECK(!want_local(1, 3, false));
CHECK(!want_local(1, kMpolLocal, false));
CHECK(!want_local(1, -1, false)); // the policy could not be read
// STRATA_NUMA_BALANCING=keep
CHECK(!want_local(1, kMpolDefault, true));
if (failed) return 1;
std::printf("numa_balancing_test: ok\n");
return 0;
}