[GH-ISSUE #4866] [Engine] HIP/Linux: kernel NUMA balancing evicts the GPU queues (watchdog stops on two-socket hosts) #2234

Open
opened 2026-11-04 01:57:46 +07:00 by bsakaguchi · 14 comments
Owner

Originally created by @vivienfanghuagood on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4866

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Source checkout (setup.sh --backend hip --build)

What happened

On a two-socket Linux host with kernel.numa_balancing=1, the HIP engine stops making progress at random points of a
request: in the prompt read (layer 0, layer 31, ...) and in decode. The #29 watchdog ends it with
no progress for 60 s during a request (reading the prompt (batched): ...), and the server restarts the engine. With
setup's own config, 7 of 20 fresh 1K-token requests stopped like that. Some stalls end by themselves after 43 s or
80 s, so this is not a deadlock: the GPU is paused for an unbounded time.

What a stuck engine looks like (rocgdb attached during a stall):

  • no dispatch active on the GPU, and every HSA queue empty (read index == write index);
  • the host thread in Prefill::run_impl, waiting inside the HIP runtime;
  • strata-issue yielding, waiting for a ring slot.

The driver's own counter /sys/class/kfd/kfd/proc/<pid>/stats_<gpu_id>/evicted_ms (how long it kept the process's
queues evicted) reaches 77 to 236 s per engine start. On the same host the kernel log shows
INFO: task kworker/...: blocked for more than 122 seconds in Workqueue: events_freezable amdgpu_amdkfd_restore_userptr_worker while the engine runs (9 times in 3 hours, one of 245 s).

Cause, as far as we can show it: the expert arena and the other ranges the GPU reads are registered with
hipHostRegister, so amdgpu keeps them as KFD userptr ranges. The NUMA-balancing scanner periodically marks the PTEs of
migratable ranges PROT_NONE to sample NUMA access. Each change is an MMU-notifier invalidation, and on a GPU without
XNACK, KFD evicts all of the process's queues until the range is validated again. This is the mechanism of #649 and
#3913, with a different trigger: it happens with plenty of free RAM, no swap and no reclaim.

Ruled out, each over the same 20 requests, counting watchdog stops:

Setting Watchdog stops (of 20)
default 7
HIP_HOST_COHERENT=1 7
STRATA_VERIFY_COHERENT=1 4
STRATA_PREFILL_ISSUER=0 6
HSA_ENABLE_SDMA=0 2
HSA_USERPTR_FOR_PAGED_MEM=0 5
the process on one node's CPUs, no memory policy stalls of 29 to 46 s

What stops it is an explicit memory policy for the engine process (no MPOL_F_NUMA_BALANCING). Then the scanner
skips its memory (vma_policy_mof() is false):

  • numactl --interleave=0,1: 0 stops, 0 ms evicted.
  • numactl --localalloc: 0 stops.
  • set_mempolicy(MPOL_LOCAL) at the top of main(): 0 stops, under 1 s evicted.

Decode is unchanged (62 tok/s median).

A standalone reproducer without Strata (below) shows the same: a 1-page GPU read every millisecond against a 16 GiB
hipHostRegistered buffer that 32 CPU threads read.

Policy Launches in 120 s Longest launch
default 81 to 947 122 to 232 s
MPOL_LOCAL set before any thread 108,549 / 113,362 2.6 s / 10.8 ms
MPOL_LOCAL set after the CPU threads started 55,528 / 73,851 44 to 46 s

The policy is per thread, and the scanner judges memory by the policy of the thread it interrupts, so it has to be
set before threads are created.

A PR with the MPOL_LOCAL change (default on when numa_balancing is on, STRATA_NUMA_BALANCING=keep to opt out)
follows as a draft. Since it changes a default, scope agreement is welcome: it can be made opt-in instead if you
prefer. Operators can also set kernel.numa_balancing=0 on the host or start the engine under
numactl --localalloc.

Smallest steps or command that reproduce it

  1. A two-socket Linux host with cat /proc/sys/kernel/numa_balancing = 1.
  2. ./setup.sh --backend hip --family qwen --model IQ3_S --build --yes --no-start, then serve with the generated config.
  3. Send fresh (no shared prefix) 1K-token chat requests one after another, 64 output tokens each.
  4. Within 20 requests, some stop with the watchdog line above. While the engine runs, evicted_ms under
    /sys/class/kfd/kfd/proc/*/stats_<gpu_id>/ grows by tens of seconds.

Standalone reproducer (hipcc -O2 --offload-arch=gfx1100 evict_probe.hip -o evict_probe -lpthread, then
./evict_probe 16 120 and ./evict_probe 16 120 local-first):

evict_probe.hip
// evict_probe: GPU queue evictions caused by NUMA balancing on hipHostRegister'ed (KFD userptr) memory.
//
// The pattern under test is Strata's expert arena: a large ordinary allocation, page-locked for the GPU with
// hipHostRegister (a KFD "userptr" range), read by CPU threads on both sockets and by the GPU.  With
// kernel.numa_balancing=1 the kernel's NUMA scanner periodically marks the range's PTEs PROT_NONE to sample access;
// every such change fires an MMU-notifier invalidation, and amdgpu/KFD answers it by evicting ALL of the process's
// GPU queues until the range is revalidated.  Work already submitted stops; nothing errors.
//
// The probe: register GIB GiB, start CPU readers on every CPU the process may use, and for SECONDS launch a tiny kernel
// that reads one page of the registered range every millisecond, timing each launch-to-completion on the host.
// Report the latency distribution and the number of launches that took > 100 ms.  Run it twice:
//
//   ./evict_probe 16 120                                   (default policy: stalls expected when numa_balancing=1)
//   numactl --interleave=0,1 ./evict_probe 16 120          (explicit policy: the scanner skips the range)
//   ./evict_probe 16 120 local-first   (MPOL_LOCAL set in main() before any thread: what the Strata fix does)
//   ./evict_probe 16 120 local-late    (the CPU readers start first, then main() sets MPOL_LOCAL: the policy is per
//                                       thread, the readers keep the default one, and the scanner runs as them)
//
//   hipcc -O2 --offload-arch=gfx1100 evict_probe.hip -o evict_probe -lpthread
#include <hip/hip_runtime.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sched.h>
#include <string>
#include <sys/syscall.h>
#include <unistd.h>
#include <thread>
#include <vector>

#define CK(x) do { hipError_t e_ = (x); if (e_ != hipSuccess) { std::fprintf(stderr, "%s: %s\n", #x, hipGetErrorString(e_)); std::exit(1); } } while (0)
using Clock = std::chrono::steady_clock;

__global__ void read_page(const volatile uint32_t* p, size_t words, uint32_t* out) {
    uint32_t acc = 0;
    for (size_t i = threadIdx.x; i < words; i += blockDim.x) acc += p[i];
    if (acc == 0xdeadbeef) out[0] = acc;
}

static void set_local(const char* when) {
    if (syscall(SYS_set_mempolicy, 4 /* MPOL_LOCAL */, nullptr, 0ul) != 0) { std::perror("set_mempolicy"); std::exit(1); }
    std::printf("MPOL_LOCAL set %s\n", when);
}

static long numa_balancing() {
    FILE* f = std::fopen("/proc/sys/kernel/numa_balancing", "r");
    long v = -1; if (f) { if (std::fscanf(f, "%ld", &v) != 1) v = -1; std::fclose(f); }
    return v;
}

int main(int argc, char** argv) {
    const size_t gib = argc > 1 ? std::strtoull(argv[1], nullptr, 10) : 16;
    const int seconds = argc > 2 ? std::atoi(argv[2]) : 120;
    const std::string mode = argc > 3 ? argv[3] : "none";
    if (mode == "local-first") set_local("in main() before any thread");
    const size_t bytes = gib << 30;
    uint8_t* host = (uint8_t*) std::aligned_alloc(1 << 21, bytes);
    if (!host) { std::perror("aligned_alloc"); return 1; }
    std::memset(host, 1, bytes);                                   // fault every page in (first touch)
    CK(hipHostRegister(host, bytes, hipHostRegisterMapped));        // KFD userptr, as Strata's arena
    uint8_t* dev_view; CK(hipHostGetDevicePointer((void**) &dev_view, host, 0));
    uint32_t* out; CK(hipMalloc(&out, 4));
    hipStream_t s; CK(hipStreamCreateWithFlags(&s, hipStreamNonBlocking));

    cpu_set_t cs; sched_getaffinity(0, sizeof(cs), &cs);
    std::vector<int> cpus; for (int c = 0; c < CPU_SETSIZE; ++c) if (CPU_ISSET(c, &cs)) cpus.push_back(c);
    const int nreaders = std::min<int>((int) cpus.size() / 2, 32);   // one reader per physical core, at most 32
    std::atomic<bool> stop{false};
    std::vector<std::thread> readers;
    for (int r = 0; r < nreaders; ++r)
        readers.emplace_back([&, r] {
            cpu_set_t one; CPU_ZERO(&one); CPU_SET(cpus[(size_t) r * cpus.size() / nreaders], &one);
            sched_setaffinity(0, sizeof(one), &one);
            const size_t chunk = bytes / nreaders;
            volatile uint64_t sink = 0;
            while (!stop.load(std::memory_order_relaxed))
                for (size_t i = r * chunk; i < (r + 1) * chunk && !stop.load(std::memory_order_relaxed); i += 4096)
                    sink += host[i];
        });

    if (mode == "local-late") set_local("in main() after the CPU readers started");
    std::printf("numa_balancing=%ld  registered %zu GiB  %d CPU readers on %zu allowed CPUs  %d s\n",
                numa_balancing(), gib, nreaders, cpus.size(), seconds);
    std::vector<double> lat_ms;
    const auto t_end = Clock::now() + std::chrono::seconds(seconds);
    size_t page = 0;
    while (Clock::now() < t_end) {
        const auto t0 = Clock::now();
        read_page<<<1, 256, 0, s>>>((const volatile uint32_t*) (dev_view + page * 4096), 1024, out);
        CK(hipStreamSynchronize(s));
        lat_ms.push_back(std::chrono::duration<double, std::milli>(Clock::now() - t0).count());
        page = (page + 7919) % (bytes / 4096);
        std::this_thread::sleep_until(t0 + std::chrono::milliseconds(1));
    }
    stop = true;
    for (auto& t : readers) t.join();
    std::vector<double> s_lat = lat_ms; std::sort(s_lat.begin(), s_lat.end());
    auto q = [&](double p) { return s_lat[std::min(s_lat.size() - 1, (size_t) (p * (s_lat.size() - 1)))]; };
    double stalled = 0; int over100 = 0;
    for (double v : lat_ms) if (v > 100) { ++over100; stalled += v; }
    std::printf("launches %zu  latency ms: p50 %.3f  p99 %.3f  p99.9 %.3f  max %.1f  | >100 ms: %d launches, %.1f s stalled\n",
                lat_ms.size(), q(0.5), q(0.99), q(0.999), s_lat.back(), over100, stalled / 1000.0);
    CK(hipHostUnregister(host));
    std::free(host);
    return 0;
}

Reproduction status

Reproduced locally

Strata version

0.2.9 (engine 0.1.55), source at c62d5e3a1

Graphics card, memory and system

Radeon PRO W7900D 48 GB (gfx1100), one card used, two-socket host with NUMA balancing on, Ubuntu 24.04, kernel 6.8, ROCm 7.2.1

Model, size and settings

Qwen3.8-Flash-Next GSQ-RCO IQ3_S, setup's config: --expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp ... --kv int8 --ple-io ram

Logs

strata serve: no progress for 60 s during a request (reading the prompt (batched): layer 0 of the prompt chunk from token 0) - stopping the engine so the server starts it again (issue #29)
  verify window (last window, not the current stage): 0 tokens at position 0, host at layer step 1; the GPU rang 0; flags: served 0, plan (A) 0, copies (B) 0
  threads waiting on the disk (state D): 0 of 42
strata serve: no progress for 60 s during a request (reading the prompt (batched): waiting for the GPU (attention, router) at layer 31 of the prompt chunk from token 0) - ...
kernel: INFO: task kworker/105:1:... blocked for more than 122 seconds.
kernel: Workqueue: events_freezable amdgpu_amdkfd_restore_userptr_worker [amdgpu]
Originally created by @vivienfanghuagood on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4866 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Source checkout (setup.sh --backend hip --build) ### What happened On a two-socket Linux host with `kernel.numa_balancing=1`, the HIP engine stops making progress at random points of a request: in the prompt read (layer 0, layer 31, ...) and in decode. The #29 watchdog ends it with `no progress for 60 s during a request (reading the prompt (batched): ...)`, and the server restarts the engine. With setup's own config, 7 of 20 fresh 1K-token requests stopped like that. Some stalls end by themselves after 43 s or 80 s, so this is not a deadlock: the GPU is paused for an unbounded time. What a stuck engine looks like (rocgdb attached during a stall): - no dispatch active on the GPU, and every HSA queue empty (read index == write index); - the host thread in `Prefill::run_impl`, waiting inside the HIP runtime; - `strata-issue` yielding, waiting for a ring slot. The driver's own counter `/sys/class/kfd/kfd/proc/<pid>/stats_<gpu_id>/evicted_ms` (how long it kept the process's queues evicted) reaches **77 to 236 s per engine start**. On the same host the kernel log shows `INFO: task kworker/...: blocked for more than 122 seconds` in `Workqueue: events_freezable amdgpu_amdkfd_restore_userptr_worker` while the engine runs (9 times in 3 hours, one of 245 s). Cause, as far as we can show it: the expert arena and the other ranges the GPU reads are registered with `hipHostRegister`, so amdgpu keeps them as KFD userptr ranges. The NUMA-balancing scanner periodically marks the PTEs of migratable ranges `PROT_NONE` to sample NUMA access. Each change is an MMU-notifier invalidation, and on a GPU without XNACK, KFD evicts all of the process's queues until the range is validated again. This is the mechanism of #649 and #3913, with a different trigger: it happens with plenty of free RAM, no swap and no reclaim. **Ruled out**, each over the same 20 requests, counting watchdog stops: | Setting | Watchdog stops (of 20) | | --- | ---: | | default | 7 | | `HIP_HOST_COHERENT=1` | 7 | | `STRATA_VERIFY_COHERENT=1` | 4 | | `STRATA_PREFILL_ISSUER=0` | 6 | | `HSA_ENABLE_SDMA=0` | 2 | | `HSA_USERPTR_FOR_PAGED_MEM=0` | 5 | | the process on one node's CPUs, no memory policy | stalls of 29 to 46 s | **What stops it** is an explicit memory policy for the engine process (no `MPOL_F_NUMA_BALANCING`). Then the scanner skips its memory (`vma_policy_mof()` is false): - `numactl --interleave=0,1`: 0 stops, 0 ms evicted. - `numactl --localalloc`: 0 stops. - `set_mempolicy(MPOL_LOCAL)` at the top of `main()`: 0 stops, under 1 s evicted. Decode is unchanged (62 tok/s median). A standalone reproducer without Strata (below) shows the same: a 1-page GPU read every millisecond against a 16 GiB `hipHostRegister`ed buffer that 32 CPU threads read. | Policy | Launches in 120 s | Longest launch | | --- | ---: | ---: | | default | 81 to 947 | 122 to 232 s | | MPOL_LOCAL set before any thread | 108,549 / 113,362 | 2.6 s / 10.8 ms | | MPOL_LOCAL set after the CPU threads started | 55,528 / 73,851 | 44 to 46 s | The policy is per thread, and the scanner judges memory by the policy of the thread it interrupts, so it has to be set before threads are created. A PR with the `MPOL_LOCAL` change (default on when `numa_balancing` is on, `STRATA_NUMA_BALANCING=keep` to opt out) follows as a draft. Since it changes a default, scope agreement is welcome: it can be made opt-in instead if you prefer. Operators can also set `kernel.numa_balancing=0` on the host or start the engine under `numactl --localalloc`. ### Smallest steps or command that reproduce it 1. A two-socket Linux host with `cat /proc/sys/kernel/numa_balancing` = 1. 2. `./setup.sh --backend hip --family qwen --model IQ3_S --build --yes --no-start`, then serve with the generated config. 3. Send fresh (no shared prefix) 1K-token chat requests one after another, 64 output tokens each. 4. Within 20 requests, some stop with the watchdog line above. While the engine runs, `evicted_ms` under `/sys/class/kfd/kfd/proc/*/stats_<gpu_id>/` grows by tens of seconds. Standalone reproducer (`hipcc -O2 --offload-arch=gfx1100 evict_probe.hip -o evict_probe -lpthread`, then `./evict_probe 16 120` and `./evict_probe 16 120 local-first`): <details><summary>evict_probe.hip</summary> ```cpp // evict_probe: GPU queue evictions caused by NUMA balancing on hipHostRegister'ed (KFD userptr) memory. // // The pattern under test is Strata's expert arena: a large ordinary allocation, page-locked for the GPU with // hipHostRegister (a KFD "userptr" range), read by CPU threads on both sockets and by the GPU. With // kernel.numa_balancing=1 the kernel's NUMA scanner periodically marks the range's PTEs PROT_NONE to sample access; // every such change fires an MMU-notifier invalidation, and amdgpu/KFD answers it by evicting ALL of the process's // GPU queues until the range is revalidated. Work already submitted stops; nothing errors. // // The probe: register GIB GiB, start CPU readers on every CPU the process may use, and for SECONDS launch a tiny kernel // that reads one page of the registered range every millisecond, timing each launch-to-completion on the host. // Report the latency distribution and the number of launches that took > 100 ms. Run it twice: // // ./evict_probe 16 120 (default policy: stalls expected when numa_balancing=1) // numactl --interleave=0,1 ./evict_probe 16 120 (explicit policy: the scanner skips the range) // ./evict_probe 16 120 local-first (MPOL_LOCAL set in main() before any thread: what the Strata fix does) // ./evict_probe 16 120 local-late (the CPU readers start first, then main() sets MPOL_LOCAL: the policy is per // thread, the readers keep the default one, and the scanner runs as them) // // hipcc -O2 --offload-arch=gfx1100 evict_probe.hip -o evict_probe -lpthread #include <hip/hip_runtime.h> #include <algorithm> #include <atomic> #include <chrono> #include <cstdio> #include <cstdlib> #include <cstring> #include <sched.h> #include <string> #include <sys/syscall.h> #include <unistd.h> #include <thread> #include <vector> #define CK(x) do { hipError_t e_ = (x); if (e_ != hipSuccess) { std::fprintf(stderr, "%s: %s\n", #x, hipGetErrorString(e_)); std::exit(1); } } while (0) using Clock = std::chrono::steady_clock; __global__ void read_page(const volatile uint32_t* p, size_t words, uint32_t* out) { uint32_t acc = 0; for (size_t i = threadIdx.x; i < words; i += blockDim.x) acc += p[i]; if (acc == 0xdeadbeef) out[0] = acc; } static void set_local(const char* when) { if (syscall(SYS_set_mempolicy, 4 /* MPOL_LOCAL */, nullptr, 0ul) != 0) { std::perror("set_mempolicy"); std::exit(1); } std::printf("MPOL_LOCAL set %s\n", when); } static long numa_balancing() { FILE* f = std::fopen("/proc/sys/kernel/numa_balancing", "r"); long v = -1; if (f) { if (std::fscanf(f, "%ld", &v) != 1) v = -1; std::fclose(f); } return v; } int main(int argc, char** argv) { const size_t gib = argc > 1 ? std::strtoull(argv[1], nullptr, 10) : 16; const int seconds = argc > 2 ? std::atoi(argv[2]) : 120; const std::string mode = argc > 3 ? argv[3] : "none"; if (mode == "local-first") set_local("in main() before any thread"); const size_t bytes = gib << 30; uint8_t* host = (uint8_t*) std::aligned_alloc(1 << 21, bytes); if (!host) { std::perror("aligned_alloc"); return 1; } std::memset(host, 1, bytes); // fault every page in (first touch) CK(hipHostRegister(host, bytes, hipHostRegisterMapped)); // KFD userptr, as Strata's arena uint8_t* dev_view; CK(hipHostGetDevicePointer((void**) &dev_view, host, 0)); uint32_t* out; CK(hipMalloc(&out, 4)); hipStream_t s; CK(hipStreamCreateWithFlags(&s, hipStreamNonBlocking)); cpu_set_t cs; sched_getaffinity(0, sizeof(cs), &cs); std::vector<int> cpus; for (int c = 0; c < CPU_SETSIZE; ++c) if (CPU_ISSET(c, &cs)) cpus.push_back(c); const int nreaders = std::min<int>((int) cpus.size() / 2, 32); // one reader per physical core, at most 32 std::atomic<bool> stop{false}; std::vector<std::thread> readers; for (int r = 0; r < nreaders; ++r) readers.emplace_back([&, r] { cpu_set_t one; CPU_ZERO(&one); CPU_SET(cpus[(size_t) r * cpus.size() / nreaders], &one); sched_setaffinity(0, sizeof(one), &one); const size_t chunk = bytes / nreaders; volatile uint64_t sink = 0; while (!stop.load(std::memory_order_relaxed)) for (size_t i = r * chunk; i < (r + 1) * chunk && !stop.load(std::memory_order_relaxed); i += 4096) sink += host[i]; }); if (mode == "local-late") set_local("in main() after the CPU readers started"); std::printf("numa_balancing=%ld registered %zu GiB %d CPU readers on %zu allowed CPUs %d s\n", numa_balancing(), gib, nreaders, cpus.size(), seconds); std::vector<double> lat_ms; const auto t_end = Clock::now() + std::chrono::seconds(seconds); size_t page = 0; while (Clock::now() < t_end) { const auto t0 = Clock::now(); read_page<<<1, 256, 0, s>>>((const volatile uint32_t*) (dev_view + page * 4096), 1024, out); CK(hipStreamSynchronize(s)); lat_ms.push_back(std::chrono::duration<double, std::milli>(Clock::now() - t0).count()); page = (page + 7919) % (bytes / 4096); std::this_thread::sleep_until(t0 + std::chrono::milliseconds(1)); } stop = true; for (auto& t : readers) t.join(); std::vector<double> s_lat = lat_ms; std::sort(s_lat.begin(), s_lat.end()); auto q = [&](double p) { return s_lat[std::min(s_lat.size() - 1, (size_t) (p * (s_lat.size() - 1)))]; }; double stalled = 0; int over100 = 0; for (double v : lat_ms) if (v > 100) { ++over100; stalled += v; } std::printf("launches %zu latency ms: p50 %.3f p99 %.3f p99.9 %.3f max %.1f | >100 ms: %d launches, %.1f s stalled\n", lat_ms.size(), q(0.5), q(0.99), q(0.999), s_lat.back(), over100, stalled / 1000.0); CK(hipHostUnregister(host)); std::free(host); return 0; } ``` </details> ### Reproduction status Reproduced locally ### Strata version 0.2.9 (engine 0.1.55), source at c62d5e3a1 ### Graphics card, memory and system Radeon PRO W7900D 48 GB (gfx1100), one card used, two-socket host with NUMA balancing on, Ubuntu 24.04, kernel 6.8, ROCm 7.2.1 ### Model, size and settings Qwen3.8-Flash-Next GSQ-RCO IQ3_S, setup's config: `--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp ... --kv int8 --ple-io ram` ### Logs ``` strata serve: no progress for 60 s during a request (reading the prompt (batched): layer 0 of the prompt chunk from token 0) - stopping the engine so the server starts it again (issue #29) verify window (last window, not the current stage): 0 tokens at position 0, host at layer step 1; the GPU rang 0; flags: served 0, plan (A) 0, copies (B) 0 threads waiting on the disk (state D): 0 of 42 strata serve: no progress for 60 s during a request (reading the prompt (batched): waiting for the GPU (attention, router) at layer 31 of the prompt chunk from token 0) - ... kernel: INFO: task kworker/105:1:... blocked for more than 122 seconds. kernel: Workqueue: events_freezable amdgpu_amdkfd_restore_userptr_worker [amdgpu] ```
Author
Owner

@vivienfanghuagood commented on GitHub (Nov 1, 2026):

Related, for anyone who finds this thread: ROCm/rocm-systems#12528 reports the same mechanism from another trigger. There, memory reclaim invalidates the pinned (userptr) ranges while clr page-locks pageable memory, and KFD keeps the process's queues evicted for most of the run. Here the trigger is the NUMA balancing scan. In both cases an MMU notifier invalidation of a userptr range makes KFD evict all of the process's queues until the range is validated again.

<!-- gh-comment-id:6564701442 --> @vivienfanghuagood commented on GitHub (Nov 1, 2026): Related, for anyone who finds this thread: ROCm/rocm-systems#12528 reports the same mechanism from another trigger. There, memory reclaim invalidates the pinned (userptr) ranges while clr page-locks pageable memory, and KFD keeps the process's queues evicted for most of the run. Here the trigger is the NUMA balancing scan. In both cases an MMU notifier invalidation of a userptr range makes KFD evict all of the process's queues until the range is validated again.
Author
Owner

@aurelbalteaux commented on GitHub (Nov 2, 2026):

Same mechanism here on a single-socket desktop with NUMA balancing off. On this box the trigger is ordinary
page reclaim and compaction, as in ROCm/rocm-systems#12528. Below is an ftrace of the KFD eviction path under a Strata
workload (it shows the SVM path is hit as well, not only userptr), plus A/B runs of the settings people usually try.

System

  • Strata 0.2.7 (build 0.1.53), engine 0.1.52-linux-x86_64-hip-rx9070, Fedora 44, kernel 7.2.13
  • Ryzen 7 7800X3D, 32 GB RAM (31 usable) + 8 GB zram swap, one NUMA node, kernel.numa_balancing=0
  • RX 9070 16 GB (gfx1201), single GPU, at stock clocks, voltage and power limit (an earlier memory OC/undervolt
    was reset and the baseline re-run; same result, see the table)
  • Qwen3.8-Flash-Next Gyro-S TQ1_0 (58.5 GB GGUF, pack 26 GB / 24 GiB experts), 256K context, --kv int8, MTP,
    --kv-resident 262144 --vram-reserve-mib 1536, resident RAM mode (~21 GiB of experts in RAM)
  • Memory while serving: VRAM ~15.8 of 16.3 GB; engine RSS 23–24 GB idle, ~25 GB during a prompt read,
    leaving ~3.5–4 GB for the desktop

Symptoms

Fresh 16K–40K-token prompts fail ~7 % of the time (7 of 104 across three soak runs) with all three known messages:
no progress for 60 s … reading the prompt (batched), verify: timed out at layer N … did not finish within 5 s (#267),
and waiting for the GPU (attention, router) at layer 32. A 30-turn conversation growing to 67K tokens with prefix
reuse never failed. dmesg is empty around all 23 failed/slow requests: no amdgpu/MES/reset messages. Note this
Fedora kernel is built without CONFIG_DETECT_HUNG_TASK, so a blocked restore_userptr_worker would not be
reported either; the silence doesn't rule that out.

evicted_ms grows in single restores of 45, 105, 110, 144 and 248 s right when requests stall; healthy runs still
show 3–8 evictions per minute of 0.5–2 s.

What triggers the evictions (ftrace)

Function tracer + func_stack_trace on kgd2kfd_quiesce_mm, svm_range_evict, amdgpu_hmm_invalidate_hsa,
amdkfd_fence_enable_signaling and the restore workers, during a 24-prompt soak (2 hangs). This run had
HSA_USERPTR_FOR_PAGED_MEM=0; all ranges showed up as SVM rather than userptr:

All 779 queue quiesces came from svm_range_evict ← svm_range_cpu_invalidate_pagetables ←
__mmu_notifier_invalidate_range_start. No eviction-fence/TTM path, no userptr path.

origin pages quiesces
reclaim (shrink_folio_list → try_to_unmap; kswapd 503, direct reclaim in strata/baloo/… ) anon 549 (71 %)
compaction (kcompactd → migrate_pages → try_to_migrate) anon 102 (13 %)
reclaim file (the mmapped model) 83 (11 %)
compaction file 34 (4 %)
munmap / THP split 10 (1 %)

Representative stack:

kgd2kfd_quiesce_mm
svm_range_evict.isra.0
svm_range_cpu_invalidate_pagetables
__mmu_notifier_invalidate_range_start
try_to_unmap_one
rmap_walk_anon            (or __rmap_walk_file)
try_to_unmap
shrink_folio_list
...
balance_pgdat / kswapd    (or try_to_free_pages, or compact_zone / kcompactd)

What I see during a stall:

  • Host threads poll in sched_yield, one HSA thread sits in kfd_wait_on_events, and the GPU is either idle or at
    100 %. In other stalls the engine's watchdog thread is in D state at lock_mm_and_find_vma, and reading
    /proc/<pid>/cmdline blocks for minutes. That looks like the restore holding mmap_lock while it faults the
    range back in.
  • The engine's own memory gets swapped out while its queues are evicted, 0 → 4.7 GB within seconds, which makes the
    restore slower still.
  • After the abort, ttm_bo_delayed_delete kworkers sit in dma_resv_wait_timeout.

The trigger on this box: during a prompt read the engine's RSS rises ~5 GB above idle, which on 32 GB forces reclaim.
Reclaim then hits the engine's GPU-registered pages.

What I tried (fresh-prompt soaks, 16K–40K)

change hangs evictions note
baseline (HSA_USERPTR_FOR_PAGED_MEM=0) 7 / 104 4.7–7.6/min, max 144 s
baseline again, GPU reset to stock clocks/voltage/power 3 / 16 + 1 slow 3.1/min, max 248 s stopped early; same signatures
STRATA_RESIDENT_PIN=1 still hangs — see below
--vram-reserve-mib 3072 (~2 GB VRAM free) 3 / 9 + 2 slow 4.3/min, max 54 s stopped early; decode 52 → 43 tok/s
HSA_USERPTR_FOR_PAGED_MEM=1 1 / 24 3.2/min, max 24 s best so far, decode 55.6 tok/s
=1 + STRATA_RESIDENT_HEADROOM_GIB=8 2 / 7 6.9/min, max 110 s stopped early; still spikes at prompt start

Samples are small, so treat the hang rates as rough.

STRATA_RESIDENT_PIN=1 does not mlock anything. With 20.95 GiB reported "page-locked", the engine shows
VmLck: 0 kB and VmPin: 0 kB, and system-wide Mlocked is 116 kB. That holds even with
RLIMIT_MEMLOCK=unlimited inherited from the server. So the "pinned" tier stays reclaimable and migratable, and
vm.compact_unevictable_allowed=0 cannot help it.

Suggestions

  1. The #267 verify timeout (5 s) and the 60 s watchdog fire on KFD eviction pauses. A growing evicted_ms could be
    reported as "GPU queues evicted by the kernel" instead of a hang. Waiting or retrying there would avoid restarts
    for the shorter pauses.
  2. Really mlock the registered resident tier when the memlock limit allows it, or say clearly that "page-locked"
    only means driver-registered. With a real mlock, reclaim stops and compact_unevictable_allowed=0 would stop
    compaction too, which together cover ~99 % of the quiesces above.
  3. A smaller RSS spike at the start of a prompt read would keep 32 GB hosts out of reclaim.

I can rerun with a build or env switch, or share the trace, stall reports and 1 Hz samples (meminfo/PSI, engine
RSS/VmSwap, GPU busy, evicted_ms).

Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.

<!-- gh-comment-id:6566450875 --> @aurelbalteaux commented on GitHub (Nov 2, 2026): Same mechanism here on a **single-socket desktop with NUMA balancing off**. On this box the trigger is ordinary page reclaim and compaction, as in ROCm/rocm-systems#12528. Below is an ftrace of the KFD eviction path under a Strata workload (it shows the SVM path is hit as well, not only userptr), plus A/B runs of the settings people usually try. ### System - Strata 0.2.7 (build 0.1.53), engine `0.1.52-linux-x86_64-hip-rx9070`, Fedora 44, kernel 7.2.13 - Ryzen 7 7800X3D, 32 GB RAM (31 usable) + 8 GB zram swap, **one NUMA node, `kernel.numa_balancing=0`** - RX 9070 16 GB (gfx1201), single GPU, at **stock clocks, voltage and power limit** (an earlier memory OC/undervolt was reset and the baseline re-run; same result, see the table) - Qwen3.8-Flash-Next Gyro-S `TQ1_0` (58.5 GB GGUF, pack 26 GB / 24 GiB experts), 256K context, `--kv int8`, MTP, `--kv-resident 262144 --vram-reserve-mib 1536`, resident RAM mode (~21 GiB of experts in RAM) - Memory while serving: VRAM ~15.8 of 16.3 GB; engine RSS 23–24 GB idle, ~25 GB during a prompt read, leaving ~3.5–4 GB for the desktop ### Symptoms Fresh 16K–40K-token prompts fail ~7 % of the time (7 of 104 across three soak runs) with all three known messages: `no progress for 60 s … reading the prompt (batched)`, `verify: timed out at layer N … did not finish within 5 s (#267)`, and `waiting for the GPU (attention, router) at layer 32`. A 30-turn conversation growing to 67K tokens with prefix reuse never failed. dmesg is empty around all 23 failed/slow requests: no amdgpu/MES/reset messages. Note this Fedora kernel is built without `CONFIG_DETECT_HUNG_TASK`, so a blocked `restore_userptr_worker` would not be reported either; the silence doesn't rule that out. `evicted_ms` grows in single restores of **45, 105, 110, 144 and 248 s** right when requests stall; healthy runs still show 3–8 evictions per minute of 0.5–2 s. ### What triggers the evictions (ftrace) Function tracer + `func_stack_trace` on `kgd2kfd_quiesce_mm`, `svm_range_evict`, `amdgpu_hmm_invalidate_hsa`, `amdkfd_fence_enable_signaling` and the restore workers, during a 24-prompt soak (2 hangs). This run had `HSA_USERPTR_FOR_PAGED_MEM=0`; all ranges showed up as SVM rather than userptr: **All 779 queue quiesces** came from `svm_range_evict` ← `svm_range_cpu_invalidate_pagetables` ← `__mmu_notifier_invalidate_range_start`. No eviction-fence/TTM path, no userptr path. | origin | pages | quiesces | |---|---|---| | reclaim (`shrink_folio_list` → `try_to_unmap`; kswapd 503, direct reclaim in strata/baloo/… ) | anon | 549 (71 %) | | compaction (`kcompactd` → `migrate_pages` → `try_to_migrate`) | anon | 102 (13 %) | | reclaim | file (the mmapped model) | 83 (11 %) | | compaction | file | 34 (4 %) | | munmap / THP split | | 10 (1 %) | Representative stack: ``` kgd2kfd_quiesce_mm svm_range_evict.isra.0 svm_range_cpu_invalidate_pagetables __mmu_notifier_invalidate_range_start try_to_unmap_one rmap_walk_anon (or __rmap_walk_file) try_to_unmap shrink_folio_list ... balance_pgdat / kswapd (or try_to_free_pages, or compact_zone / kcompactd) ``` What I see during a stall: - Host threads poll in `sched_yield`, one HSA thread sits in `kfd_wait_on_events`, and the GPU is either idle or at 100 %. In other stalls the engine's watchdog thread is in D state at `lock_mm_and_find_vma`, and reading `/proc/<pid>/cmdline` blocks for minutes. That looks like the restore holding `mmap_lock` while it faults the range back in. - The engine's own memory gets swapped out while its queues are evicted, 0 → 4.7 GB within seconds, which makes the restore slower still. - After the abort, `ttm_bo_delayed_delete` kworkers sit in `dma_resv_wait_timeout`. The trigger on this box: during a prompt read the engine's RSS rises ~5 GB above idle, which on 32 GB forces reclaim. Reclaim then hits the engine's GPU-registered pages. ### What I tried (fresh-prompt soaks, 16K–40K) | change | hangs | evictions | note | |---|---|---|---| | baseline (`HSA_USERPTR_FOR_PAGED_MEM=0`) | 7 / 104 | 4.7–7.6/min, max 144 s | | | baseline again, GPU reset to stock clocks/voltage/power | 3 / 16 + 1 slow | 3.1/min, max **248 s** | stopped early; same signatures | | `STRATA_RESIDENT_PIN=1` | still hangs | — | see below | | `--vram-reserve-mib 3072` (~2 GB VRAM free) | 3 / 9 + 2 slow | 4.3/min, max 54 s | stopped early; decode 52 → 43 tok/s | | `HSA_USERPTR_FOR_PAGED_MEM=1` | 1 / 24 | 3.2/min, max 24 s | best so far, decode 55.6 tok/s | | `=1` + `STRATA_RESIDENT_HEADROOM_GIB=8` | 2 / 7 | 6.9/min, max 110 s | stopped early; still spikes at prompt start | Samples are small, so treat the hang rates as rough. **`STRATA_RESIDENT_PIN=1` does not mlock anything.** With 20.95 GiB reported "page-locked", the engine shows `VmLck: 0 kB` and `VmPin: 0 kB`, and system-wide `Mlocked` is 116 kB. That holds even with `RLIMIT_MEMLOCK=unlimited` inherited from the server. So the "pinned" tier stays reclaimable and migratable, and `vm.compact_unevictable_allowed=0` cannot help it. ### Suggestions 1. The `#267` verify timeout (5 s) and the 60 s watchdog fire on KFD eviction pauses. A growing `evicted_ms` could be reported as "GPU queues evicted by the kernel" instead of a hang. Waiting or retrying there would avoid restarts for the shorter pauses. 2. Really `mlock` the registered resident tier when the memlock limit allows it, or say clearly that "page-locked" only means driver-registered. With a real mlock, reclaim stops and `compact_unevictable_allowed=0` would stop compaction too, which together cover ~99 % of the quiesces above. 3. A smaller RSS spike at the start of a prompt read would keep 32 GB hosts out of reclaim. I can rerun with a build or env switch, or share the trace, stall reports and 1 Hz samples (meminfo/PSI, engine RSS/VmSwap, GPU busy, `evicted_ms`). > Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.
Author
Owner

@vivienfanghuagood commented on GitHub (Nov 2, 2026):

Thank you, this is a very useful report. The ftrace answers what we could not see on our machine.

What #4867 covers. It removes one trigger: the NUMA balancing scanner, on multi-socket machines with
kernel.numa_balancing=1. It does nothing for reclaim, compaction or THP splits. Your trace shows the general case: on a
GPU without XNACK, any MMU-notifier invalidation of host memory registered with the GPU (a userptr or an SVM range)
evicts all of the process's queues until the range is valid again.

What we measured. We extended our probe to compare the ways the memory can be set up against several triggers.
Setup: Radeon PRO W7900D (gfx1100), 2x EPYC 9334, ROCm 7.2.1, kernel 6.8, no swap. An 8 GiB region, 32 CPU threads reading
it, and a small GPU kernel reading it every millisecond, for 60 s. The table gives the seconds of queue eviction that
KFD itself reports (evicted_ms), which match the GPU stalls:

NUMA balancing migration, 64 MiB/s migration, 64 MiB every 200 ms
hipHostRegister (as the resident tier is registered today) 19-35 s 21.8 s one 89 s stall
mlock + hipHostRegister 25.5 s 20.9 s never recovered within 90 s
hipHostMalloc 0 21.6 s 50.7 s

Migration here is move_pages() on the region itself, the same migrate_pages path compaction takes. Without a trigger
the longest launch was 0.3 ms.

  • mlock does not stop NUMA balancing or migration. hipHostMalloc avoids NUMA balancing, because its pages carry a
    node policy, but its pages are migrated like any other on ROCm 7.2.1.
  • When invalidations come fast enough, the restore never catches up, and the queues stay evicted for as long as it lasts.
    That looks like your 45-248 s single restores, and like ROCm/rocm-systems#12528.
  • We could not test anonymous reclaim, since this machine has no swap and we cannot change it. An mlocked page is not
    reclaimed, by the kernel's design. move_pages() also ignores vm.compact_unevictable_allowed, so we could not show
    the effect of that setting on compaction either.

So we agree with your suggestions 1 and 2. A real mlock of the registered resident tier stops reclaim, and with
vm.compact_unevictable_allowed=0 on the host, compaction leaves those pages alone too. By your counts that covers about
99% of the quiesces. Reading expert_source.cpp (we have not confirmed this on your setup), when RAM is short the
resident complement is registered in steps from ordinary memory: malloc, then cudaHostRegister. That path never calls
mlock, yet the log says "page-locked", which would explain VmLck: 0 kB on your machine.

What we would propose, as separate changes from #4867 once the maintainers agree on the scope:

  1. mlock the registered resident tier when RLIMIT_MEMLOCK allows it, say so plainly in the log when it does not, and
    document vm.compact_unevictable_allowed=0 as the matching host setting.
  2. Have the #267 verify timeout and the 60 s watchdog check whether the process's evicted_ms is growing, and treat
    that as an eviction pause rather than a hang.

If you can run a build with (1) on your 32 GB machine, that is the test we cannot do here. The probe behind the table is
the reproducer in the issue description (evict_probe.hip),
extended with the three memory setups and the migration and reclaim triggers. We can post that version if it helps.

<!-- gh-comment-id:6567870914 --> @vivienfanghuagood commented on GitHub (Nov 2, 2026): Thank you, this is a very useful report. The ftrace answers what we could not see on our machine. **What #4867 covers.** It removes one trigger: the NUMA balancing scanner, on multi-socket machines with `kernel.numa_balancing=1`. It does nothing for reclaim, compaction or THP splits. Your trace shows the general case: on a GPU without XNACK, any MMU-notifier invalidation of host memory registered with the GPU (a userptr or an SVM range) evicts all of the process's queues until the range is valid again. **What we measured.** We extended our probe to compare the ways the memory can be set up against several triggers. Setup: Radeon PRO W7900D (gfx1100), 2x EPYC 9334, ROCm 7.2.1, kernel 6.8, no swap. An 8 GiB region, 32 CPU threads reading it, and a small GPU kernel reading it every millisecond, for 60 s. The table gives the seconds of queue eviction that KFD itself reports (`evicted_ms`), which match the GPU stalls: | | NUMA balancing | migration, 64 MiB/s | migration, 64 MiB every 200 ms | |---|---:|---:|---:| | `hipHostRegister` (as the resident tier is registered today) | 19-35 s | 21.8 s | one 89 s stall | | `mlock` + `hipHostRegister` | 25.5 s | 20.9 s | never recovered within 90 s | | `hipHostMalloc` | 0 | 21.6 s | 50.7 s | Migration here is `move_pages()` on the region itself, the same `migrate_pages` path compaction takes. Without a trigger the longest launch was 0.3 ms. - `mlock` does not stop NUMA balancing or migration. `hipHostMalloc` avoids NUMA balancing, because its pages carry a node policy, but its pages are migrated like any other on ROCm 7.2.1. - When invalidations come fast enough, the restore never catches up, and the queues stay evicted for as long as it lasts. That looks like your 45-248 s single restores, and like ROCm/rocm-systems#12528. - We could not test anonymous reclaim, since this machine has no swap and we cannot change it. An mlocked page is not reclaimed, by the kernel's design. `move_pages()` also ignores `vm.compact_unevictable_allowed`, so we could not show the effect of that setting on compaction either. So we agree with your suggestions 1 and 2. A real `mlock` of the registered resident tier stops reclaim, and with `vm.compact_unevictable_allowed=0` on the host, compaction leaves those pages alone too. By your counts that covers about 99% of the quiesces. Reading `expert_source.cpp` (we have not confirmed this on your setup), when RAM is short the resident complement is registered in steps from ordinary memory: `malloc`, then `cudaHostRegister`. That path never calls `mlock`, yet the log says "page-locked", which would explain `VmLck: 0 kB` on your machine. What we would propose, as separate changes from #4867 once the maintainers agree on the scope: 1. mlock the registered resident tier when `RLIMIT_MEMLOCK` allows it, say so plainly in the log when it does not, and document `vm.compact_unevictable_allowed=0` as the matching host setting. 2. Have the `#267` verify timeout and the 60 s watchdog check whether the process's `evicted_ms` is growing, and treat that as an eviction pause rather than a hang. If you can run a build with (1) on your 32 GB machine, that is the test we cannot do here. The probe behind the table is the reproducer in [the issue description](https://github.com/Niko1221/Strata/issues/4866#issue-6141885573) (`evict_probe.hip`), extended with the three memory setups and the migration and reclaim triggers. We can post that version if it helps.
Author
Owner

@alexanderi96 commented on GitHub (Nov 2, 2026):

@vivienfanghuagood @aurelbalteaux your suggestion 1 (mlock the GPU-registered host memory when RLIMIT_MEMLOCK
allows it) is in #3913 as STRATA_HIP_MLOCK=1. It covers every cudaHostRegister / cudaHostAlloc /
cudaMallocHost of the HIP build, including the complement registered in steps that @aurelbalteaux found at
VmLck: 0. With vm.compact_unevictable_allowed=0 the watchdog stops ended here (about 80 starts, 0 stops, against
12 before). It does nothing for NUMA balancing; the PR's docs now point here for that.

mlock still left short evictions, 10-600 ms. A kprobe trace on amdgpu_hmm_invalidate_hsa /
svm_range_cpu_invalidate_pagetables over one 30K prompt put every hit on 82 shared /dev/zero mappings (233 MiB,
Locked: 0). These are host allocations ROCr makes for itself (fmm_allocate_host_gpu: MAP_SHARED|MAP_ANONYMOUS

  • userptr while HSA_USERPTR_FOR_PAGED_MEM is on), so the engine never sees them. 78% of the hits came from kswapd
    and 10% from kcompactd.

With HSA_USERPTR_FOR_PAGED_MEM=0 they become GTT, driver-pinned with no notifier, and the evictions go to 0. The
known catch, a much slower prompt read, comes from the complement being fine-grained GTT. #3913 now has an opt-in
coarse-grained complement (STRATA_HIP_ARENA_NONCOHERENT=1). With ttm.pages_limit raised so GTT holds it: same
speed as userptr + mlock, kfd_evicted_ms 0 through ten 30K prompts and 6 GB of pressure (table in the PR).

@aurelbalteaux on your 32 GB box with zram, the run worth doing is the fresh-prompt soak with

"env": {"HSA_USERPTR_FOR_PAGED_MEM": "0", "STRATA_HIP_ARENA_NONCOHERENT": "1"}
# kernel: ttm.pages_limit large enough for the resident budget + ~6 GiB (check mem_info_gtt_total)

with kfd_evicted_ms from /health before and after. On two sockets, NUMA balancing should not touch GTT pages
either (they are not on the LRU), but I cannot test that here.

<!-- gh-comment-id:6585825461 --> @alexanderi96 commented on GitHub (Nov 2, 2026): @vivienfanghuagood @aurelbalteaux your suggestion 1 (mlock the GPU-registered host memory when `RLIMIT_MEMLOCK` allows it) is in #3913 as `STRATA_HIP_MLOCK=1`. It covers every `cudaHostRegister` / `cudaHostAlloc` / `cudaMallocHost` of the HIP build, including the complement registered in steps that @aurelbalteaux found at `VmLck: 0`. With `vm.compact_unevictable_allowed=0` the watchdog stops ended here (about 80 starts, 0 stops, against 12 before). It does nothing for NUMA balancing; the PR's docs now point here for that. mlock still left short evictions, 10-600 ms. A kprobe trace on `amdgpu_hmm_invalidate_hsa` / `svm_range_cpu_invalidate_pagetables` over one 30K prompt put every hit on 82 shared `/dev/zero` mappings (233 MiB, `Locked: 0`). These are host allocations ROCr makes for itself (`fmm_allocate_host_gpu`: `MAP_SHARED|MAP_ANONYMOUS` + userptr while `HSA_USERPTR_FOR_PAGED_MEM` is on), so the engine never sees them. 78% of the hits came from kswapd and 10% from kcompactd. With `HSA_USERPTR_FOR_PAGED_MEM=0` they become GTT, driver-pinned with no notifier, and the evictions go to 0. The known catch, a much slower prompt read, comes from the complement being fine-grained GTT. #3913 now has an opt-in coarse-grained complement (`STRATA_HIP_ARENA_NONCOHERENT=1`). With `ttm.pages_limit` raised so GTT holds it: same speed as userptr + mlock, `kfd_evicted_ms` 0 through ten 30K prompts and 6 GB of pressure (table in the PR). @aurelbalteaux on your 32 GB box with zram, the run worth doing is the fresh-prompt soak with ``` "env": {"HSA_USERPTR_FOR_PAGED_MEM": "0", "STRATA_HIP_ARENA_NONCOHERENT": "1"} # kernel: ttm.pages_limit large enough for the resident budget + ~6 GiB (check mem_info_gtt_total) ``` with `kfd_evicted_ms` from `/health` before and after. On two sockets, NUMA balancing should not touch GTT pages either (they are not on the LRU), but I cannot test that here.
Author
Owner

@aurelbalteaux commented on GitHub (Nov 2, 2026):

@vivienfanghuagood @alexanderi96 Thanks both. Replies to each of you below, plus what I found since my first comment.

One correction to the expert_source.cpp reading, from current main (I run 0.1.52, but it matches what I see): the
resident tier does call mlock, through platform::lock_resident, but only from lock_off on. On the paced path,
lock_off = partial_pin. The registered prefix is skipped on purpose ("the registered prefix is page-locked by the driver
already - locking it twice made the next device allocation fail"; that comment refers to an RTX 5070 / WDDM). Here the whole
20.95 GiB got registered, so lock_off == bytes and nothing is locked, hence VmLck: 0 kB. #3913 (STRATA_HIP_MLOCK=1)
now covers exactly that.

What triggers the reclaim on this box

It depends on how large a resident tier the engine picks at start-up. The
prefill plan inputs: … GiB RAM copy (N lend slots kept) line tells. With all 3391 lend slots kept, prompts read no experts
from the GGUF, and nothing fails. With fewer, every prompt streams the missing experts from the mmapped model: 16–97 GB of
file-tier expert reads per soak, up to 5 M major faults, the page cache growing to 23 GB. That growth pushes the box into
reclaim, which hits the engine's GPU-registered pages, and the minute-long evictions follow.

To test this directly, I held a balloon only while the engine started and released it before the soak. Every engine then
came up with 20.5–20.8 GiB and 2240–2596 slots:

engine started with soaks failed requests
all 3391 lend slots (no file-tier reads) 8 earlier today + the post-restart part of the 6 below 0 / 266
2240–2596 lend slots, balloon at start only 6 6 / 70 (each soak failed after 8–17 requests)
< 3391 slots, all earlier soaks (Oct 31 – Nov 2) 11 19 / 217

Each failure restarted the engine. With the RAM free again it came back with all 3391 slots, and the rest of that soak
(74 requests) ran clean. The difference between the two modes is only ~0.65–1 GiB of free RAM at start-up, so on a 32 GB host
whether the engine works or stalls comes down to what else happens to be open when it starts.

Two mitigations tested under that trigger

Every engine started with the same start-up balloon, 24 prompts per soak, in the order baseline, A, B, B, A, baseline:

start-up tier failed longest evictions file-tier reads engine swapped PSI full max
baseline 2292 / 2330 slots 1, 1 92 s (+ one not over when the engine was killed) 45 GB 6 GB 38
A: STRATA_RESIDENT_HEADROOM_GIB=2 3391 / 3391 0, 0 none ≥ 5 s 0 0 3
B: engine in a cgroup with memory.swap.max=0 2380 / 2453 1, 1 104 s, 62 s 60 GB 0 18–21
  • A removes the trigger. At the same free RAM, the engine keeps the full tier and reads nothing from the GGUF. The desktop's
    margin doesn't shrink either: MemAvailable stays ~4 GB minimum, same as the baseline. It's now in my preset, and a
    follow-up check (16K–64K fresh prompts and a conversation grown to 66K with prefix reuse) shows the same prefill and decode
    speed as before.
  • B is close to what (1) would give for anonymous memory, since nothing of the engine's can be swapped out. It lowers the
    pressure but doesn't fix it. With the tier reduced, something still invalidates GPU-registered ranges under the
    streaming load, and evictions still last a minute or more. That could be compaction migrating them, or reclaim of
    file-backed or shared ranges, such as the ROCr /dev/zero buffers @alexanderi96 found. I didn't trace this run, so I
    can't say which.

So on a 32 GB host a full tier matters more than locking it, and two cheap changes would help next to (1) and (2):
3. The start-up warning is already there ("N of 3391 lendable slots … will read their experts from the pack during a
long prompt; expect a slower prompt read on 50K+ token prompts"), but it presents this as a speed cost. On a 32 GB
host it also means reclaim and queue-eviction stalls on 16K–40K prompts. Saying so, and pointing at
STRATA_RESIDENT_HEADROOM_GIB as the lever (AMD_HIP.md already does), would save people a lot of searching.
4. Grow the tier later, when the RAM becomes available (a watchdog restart already does this as a side effect), or give
a switch to wait for or require the full tier instead of starting reduced.

@vivienfanghuagood: on (2), eviction-aware timeouts

Useful, but evicted_ms won't work as the live signal. KFD adds an eviction's time only when the queues are restored, or
when the process is torn down. In 7 of my 10 failures in the runs above, the evicted time (62–104 s) only showed up when the
watchdog killed the engine. While the stall was going on, evicted_ms stayed flat, so a watchdog checking it would still
have fired. The per-process sysfs has no live queue state either (queues/* holds only gpuid, size, type). The KFD
SMI event interface should report queue eviction and restore as they happen (I haven't tried it), so that, or "GPU idle and
no progress" as a heuristic, would be the better trigger. Waiting would turn some failures into slow requests, not all:
earlier runs had stalls that recovered on their own after 73–83 s, but also a single 248 s eviction.

Please post the extended probe. This box has 8 GB zram swap and gets real anonymous reclaim, so it can fill the reclaim
column you couldn't test (gfx1201, hipHostRegister vs mlock + hipHostRegister vs hipHostMalloc).

@alexanderi96: #3913

That's the piece I was missing. The /dev/zero mappings also change how I read my own trace. In my first comment, ~15 % of
the quiesces came through the file rmap path, and I had attributed them to the mapped GGUF. Shared anonymous memory is
shmem and goes through that same path, so part of that share may be ROCr's own fmm_allocate_host_gpu buffers instead.

Given the above, the useful case for your PR on 32 GB is the reduced tier: does GTT keep the queues running while the box
is under streaming pressure? I'm happy to run it. Before I do:

  • My engine is 0.1.52 and has neither STRATA_HIP_MLOCK nor STRATA_HIP_ARENA_NONCOHERENT, so I'd build #3913 myself.
    Is packaging/build_hip_linux.sh against the TheRock 7.2 wheels the right way, with gfx1201 only?
  • ttm.pages_limit here is 4052118 pages (15.5 GiB, mem_info_gtt_total 16.6 GB). Resident budget + ~6 GiB would be
    ~28 GiB, close to all of the 31 GiB, and none of it reclaimable. On this box that may just move the pressure onto the
    desktop, or end in an OOM kill. Does the arena have to sit in GTT whole, or does a smaller resident budget (a larger
    headroom) work with STRATA_HIP_ARENA_NONCOHERENT=1, so I can keep GTT around 20–22 GiB?
  • Is setting /sys/module/ttm/parameters/pages_limit at runtime enough, or does it have to be on the kernel command line?

Planned runs, each reporting evicted_ms, failures, decode/prefill speed, and MemAvailable/PSI for the rest of the
system: the same 24-prompt soak, both with the full tier and with a reduced start (balloon held only while the engine
starts). Baseline =1 vs your =0 + STRATA_HIP_ARENA_NONCOHERENT=1, interleaved, two runs each.

Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.

<!-- gh-comment-id:6590326228 --> @aurelbalteaux commented on GitHub (Nov 2, 2026): @vivienfanghuagood @alexanderi96 Thanks both. Replies to each of you below, plus what I found since my first comment. One correction to the `expert_source.cpp` reading, from current `main` (I run 0.1.52, but it matches what I see): the resident tier does call `mlock`, through `platform::lock_resident`, but only from `lock_off` on. On the paced path, `lock_off = partial_pin`. The registered prefix is skipped on purpose ("the registered prefix is page-locked by the driver already - locking it twice made the next device allocation fail"; that comment refers to an RTX 5070 / WDDM). Here the whole 20.95 GiB got registered, so `lock_off == bytes` and nothing is locked, hence `VmLck: 0 kB`. #3913 (`STRATA_HIP_MLOCK=1`) now covers exactly that. ### What triggers the reclaim on this box It depends on how large a resident tier the engine picks at start-up. The `prefill plan inputs: … GiB RAM copy (N lend slots kept)` line tells. With all 3391 lend slots kept, prompts read no experts from the GGUF, and nothing fails. With fewer, every prompt streams the missing experts from the mmapped model: 16–97 GB of file-tier expert reads per soak, up to 5 M major faults, the page cache growing to 23 GB. That growth pushes the box into reclaim, which hits the engine's GPU-registered pages, and the minute-long evictions follow. To test this directly, I held a balloon only while the engine started and released it before the soak. Every engine then came up with 20.5–20.8 GiB and 2240–2596 slots: | engine started with | soaks | failed requests | |---|---|---| | all 3391 lend slots (no file-tier reads) | 8 earlier today + the post-restart part of the 6 below | 0 / 266 | | 2240–2596 lend slots, balloon at start only | 6 | 6 / 70 (each soak failed after 8–17 requests) | | < 3391 slots, all earlier soaks (Oct 31 – Nov 2) | 11 | 19 / 217 | Each failure restarted the engine. With the RAM free again it came back with all 3391 slots, and the rest of that soak (74 requests) ran clean. The difference between the two modes is only ~0.65–1 GiB of free RAM at start-up, so on a 32 GB host whether the engine works or stalls comes down to what else happens to be open when it starts. ### Two mitigations tested under that trigger Every engine started with the same start-up balloon, 24 prompts per soak, in the order baseline, A, B, B, A, baseline: | | start-up tier | failed | longest evictions | file-tier reads | engine swapped | PSI full max | |---|---|---|---|---|---|---| | baseline | 2292 / 2330 slots | 1, 1 | 92 s (+ one not over when the engine was killed) | 45 GB | 6 GB | 38 | | A: `STRATA_RESIDENT_HEADROOM_GIB=2` | 3391 / 3391 | **0, 0** | none ≥ 5 s | 0 | 0 | 3 | | B: engine in a cgroup with `memory.swap.max=0` | 2380 / 2453 | 1, 1 | 104 s, 62 s | 60 GB | 0 | 18–21 | - A removes the trigger. At the same free RAM, the engine keeps the full tier and reads nothing from the GGUF. The desktop's margin doesn't shrink either: MemAvailable stays ~4 GB minimum, same as the baseline. It's now in my preset, and a follow-up check (16K–64K fresh prompts and a conversation grown to 66K with prefix reuse) shows the same prefill and decode speed as before. - B is close to what (1) would give for anonymous memory, since nothing of the engine's can be swapped out. It lowers the pressure but doesn't fix it. With the tier reduced, something still invalidates GPU-registered ranges under the streaming load, and evictions still last a minute or more. That could be compaction migrating them, or reclaim of file-backed or shared ranges, such as the ROCr `/dev/zero` buffers @alexanderi96 found. I didn't trace this run, so I can't say which. So on a 32 GB host a full tier matters more than locking it, and two cheap changes would help next to (1) and (2): 3. The start-up warning is already there ("N of 3391 lendable slots … will read their experts from the pack during a long prompt; expect a slower prompt read on 50K+ token prompts"), but it presents this as a speed cost. On a 32 GB host it also means reclaim and queue-eviction stalls on 16K–40K prompts. Saying so, and pointing at `STRATA_RESIDENT_HEADROOM_GIB` as the lever (AMD_HIP.md already does), would save people a lot of searching. 4. Grow the tier later, when the RAM becomes available (a watchdog restart already does this as a side effect), or give a switch to wait for or require the full tier instead of starting reduced. ### @vivienfanghuagood: on (2), eviction-aware timeouts Useful, but `evicted_ms` won't work as the live signal. KFD adds an eviction's time only when the queues are restored, or when the process is torn down. In 7 of my 10 failures in the runs above, the evicted time (62–104 s) only showed up when the watchdog killed the engine. While the stall was going on, `evicted_ms` stayed flat, so a watchdog checking it would still have fired. The per-process sysfs has no live queue state either (`queues/*` holds only `gpuid`, `size`, `type`). The KFD SMI event interface should report queue eviction and restore as they happen (I haven't tried it), so that, or "GPU idle and no progress" as a heuristic, would be the better trigger. Waiting would turn some failures into slow requests, not all: earlier runs had stalls that recovered on their own after 73–83 s, but also a single 248 s eviction. Please post the extended probe. This box has 8 GB zram swap and gets real anonymous reclaim, so it can fill the reclaim column you couldn't test (gfx1201, `hipHostRegister` vs `mlock` + `hipHostRegister` vs `hipHostMalloc`). ### @alexanderi96: #3913 That's the piece I was missing. The `/dev/zero` mappings also change how I read my own trace. In my first comment, ~15 % of the quiesces came through the file rmap path, and I had attributed them to the mapped GGUF. Shared anonymous memory is shmem and goes through that same path, so part of that share may be ROCr's own `fmm_allocate_host_gpu` buffers instead. Given the above, the useful case for your PR on 32 GB is the reduced tier: does GTT keep the queues running while the box is under streaming pressure? I'm happy to run it. Before I do: - My engine is 0.1.52 and has neither `STRATA_HIP_MLOCK` nor `STRATA_HIP_ARENA_NONCOHERENT`, so I'd build #3913 myself. Is `packaging/build_hip_linux.sh` against the TheRock 7.2 wheels the right way, with gfx1201 only? - `ttm.pages_limit` here is 4052118 pages (15.5 GiB, `mem_info_gtt_total` 16.6 GB). Resident budget + ~6 GiB would be ~28 GiB, close to all of the 31 GiB, and none of it reclaimable. On this box that may just move the pressure onto the desktop, or end in an OOM kill. Does the arena have to sit in GTT whole, or does a smaller resident budget (a larger headroom) work with `STRATA_HIP_ARENA_NONCOHERENT=1`, so I can keep GTT around 20–22 GiB? - Is setting `/sys/module/ttm/parameters/pages_limit` at runtime enough, or does it have to be on the kernel command line? Planned runs, each reporting `evicted_ms`, failures, decode/prefill speed, and MemAvailable/PSI for the rest of the system: the same 24-prompt soak, both with the full tier and with a reduced start (balloon held only while the engine starts). Baseline `=1` vs your `=0` + `STRATA_HIP_ARENA_NONCOHERENT=1`, interleaved, two runs each. > Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.
Author
Owner

@vivienfanghuagood commented on GitHub (Nov 2, 2026):

Thanks, both. Two corrections to our last comment first.

  • @aurelbalteaux, you are right about expert_source.cpp, and our reading was wrong. The paced path does call
    platform::lock_resident, but only from lock_off = partial_pin, so when the whole tier gets registered nothing is
    locked. Thank you for checking it.
  • You are also right that evicted_ms cannot be the live signal for (2). KFD adds the time only when the queues come
    back. Our own runs show the same: the ones that never recovered within 90 s reported evicted_ms 0 while they were
    stuck.

@alexanderi96, thanks for #3913. It covers our (1), so we drop it as a separate proposal.

We ran #3913's two options through the same probe and machine as before (Radeon PRO W7900D, gfx1100, 2x EPYC 9334, ROCm
7.2.1, kernel 6.8, no swap; 8 GiB, 60 s). The table gives the seconds of queue eviction KFD reports:

NUMA balancing migration, 64 MiB/s migration, 64 MiB every 200 ms
hipHostRegister, then mlock (what STRATA_HIP_MLOCK=1 does) 48.3 s 34.3 s not run
hipHostMalloc, HSA_USERPTR_FOR_PAGED_MEM=0 0 0 0
hipHostMalloc with hipHostMallocNonCoherent, HSA_USERPTR_FOR_PAGED_MEM=0 (as STRATA_HIP_ARENA_NONCOHERENT=1) 0 0 0
  • With HSA_USERPTR_FOR_PAGED_MEM=0, move_pages() moved none of the hipHostMalloc pages, and NUMA balancing caused no
    eviction. So on this two-socket machine, NUMA balancing does not touch the GTT allocation, which was the open question
    in #3913.
  • mlock, before or after the registration, stops neither NUMA balancing nor migration. STRATA_HIP_MLOCK=1 addresses
    reclaim, and on multi-socket hosts with NUMA balancing on, the memory policy fix in #4867 is still needed.
  • In every GTT run the longest launch was 3-4 ms, also without a trigger, against 0.3 ms for registered memory. The probe
    reads one page per launch, so this says nothing about prompt speed.
  • We still cannot test reclaim here, since there is no swap.

@aurelbalteaux, here is the extended probe for the reclaim column. GIB SECONDS ALLOC TRIGGER; ALLOC is one of
register, mlock (before the registration), register-mlock-after, hostmalloc, hostmalloc-nc, file,
file-mlock (with EVICT_FILE=<path>). TRIGGER is one of none, numa, migrate (EVICT_MIGRATE_MS, default 50),
reclaim. Every trigger except numa sets MPOL_LOCAL first. Set HSA_USERPTR_FOR_PAGED_MEM in the environment for the GTT
arms. migrate needs two NUMA nodes, so on your box reclaim and none are the useful ones. Under real pressure, the
register / register-mlock-after / hostmalloc (with =0) comparison with TRIGGER=none is the column we are
missing.

evict_probe2.hip
// evict_probe2: which host-memory setup keeps KFD from evicting a process's GPU queues, under which trigger.
//
// Every MMU-notifier invalidation of GPU-registered host memory (a userptr or SVM range) makes KFD evict ALL of the
// process's queues on a GPU without XNACK, until the range is valid again; submitted work stops and nothing errors.
// evict_probe showed one trigger (NUMA balancing).  This one compares the memory setups against three:
//
//   GIB SECONDS ALLOC TRIGGER
//   ALLOC    register    anonymous memory + hipHostRegister (Strata's expert arena)
//            mlock       the same, mlock()ed before it is registered (RLIMIT_MEMLOCK raised; needs the privilege)
//            register-mlock-after  hipHostRegister, then mlock (the order of Strata's STRATA_HIP_MLOCK=1)
//            hostmalloc  hipHostMalloc (a userptr range under ROCr's default HSA_USERPTR_FOR_PAGED_MEM; GTT with =0)
//            hostmalloc-nc  hipHostMalloc with hipHostMallocNonCoherent (Strata's STRATA_HIP_ARENA_NONCOHERENT=1)
//            file, file-mlock   a MAP_SHARED file (EVICT_FILE) + hipHostRegister, without / with mlock
//   TRIGGER  numa        NUMA balancing (kernel.numa_balancing=1; no memory policy set)
//            migrate     MPOL_LOCAL set first (the scanner skips), and a thread moves 64 MiB of the range to the other
//                        NUMA node every 50 ms with move_pages() - the migration compaction does
//            reclaim     MPOL_LOCAL, and a thread reclaims 64 MiB of the range every 200 ms with madvise(MADV_PAGEOUT):
//                        the page-reclaim path (shrink_folio_list -> try_to_unmap).  File pages only on a host
//                        without swap (anonymous pages cannot be paged out there); mlocked pages are skipped
//            none        MPOL_LOCAL, nothing else
//
// The probe: CPU readers touch the region; a tiny kernel reads one page of it every millisecond, timed launch to
// completion on the host.  It also reads its own KFD evicted_ms (found by a 77 MiB marker allocation) before / after.
//
//   hipcc -O2 --offload-arch=gfx1100 evict_probe2.hip -o evict_probe2 -lpthread
#include <hip/hip_runtime.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <dirent.h>
#include <fcntl.h>
#include <fstream>
#include <sched.h>
#include <string>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <thread>
#include <unistd.h>
#include <vector>

#define CK(x) do { hipError_t e_ = (x); if (e_ != hipSuccess) { std::fprintf(stderr, "%s: %s\n", #x, hipGetErrorString(e_)); std::exit(1); } } while (0)
using Clock = std::chrono::steady_clock;
static constexpr size_t kMarker = 77ull << 20;

__global__ void read_page(const volatile uint32_t* p, size_t words, uint32_t* out) {
    uint32_t acc = 0;
    for (size_t i = threadIdx.x; i < words; i += blockDim.x) acc += p[i];
    if (acc == 0xdeadbeef) out[0] = acc;
}

static std::string slurp(const std::string& p) { std::ifstream f(p); std::string s; std::getline(f, s, '\0'); return s; }

// every (KFD process, GPU) VRAM total: this process is the one that grows by the marker allocation
#include <map>
static std::map<std::string, unsigned long long> kfd_vram() {
    std::map<std::string, unsigned long long> m;
    DIR* d = opendir("/sys/class/kfd/kfd/proc");
    if (!d) return m;
    while (dirent* e = readdir(d)) {
        if (e->d_name[0] == '.') continue;
        const std::string base = std::string("/sys/class/kfd/kfd/proc/") + e->d_name;
        DIR* p = opendir(base.c_str());
        if (!p) continue;
        while (dirent* f = readdir(p)) {
            const std::string n = f->d_name;
            if (n.rfind("vram_", 0) == 0) m[base + "/stats_" + n.substr(5)] = std::strtoull(slurp(base + "/" + n).c_str(), nullptr, 10);
        }
        closedir(p);
    }
    closedir(d);
    return m;
}
static long evicted(const std::string& stats) {
    return stats.empty() ? -1 : std::strtol(slurp(stats + "/evicted_ms").c_str(), nullptr, 10);
}

int main(int argc, char** argv) {
    if (argc < 5) { std::fprintf(stderr, "usage: evict_probe2 GIB SECONDS ALLOC TRIGGER\n"); return 2; }
    const size_t bytes = std::strtoull(argv[1], nullptr, 10) << 30;
    const int seconds = std::atoi(argv[2]);
    const std::string alloc = argv[3], trigger = argv[4];
    if (trigger != "numa") {
        if (syscall(SYS_set_mempolicy, 4 /* MPOL_LOCAL */, nullptr, 0ul) != 0) { std::perror("set_mempolicy"); return 1; }
    }
    // mlock before the registration (mlock, file-mlock), or after it as Strata's STRATA_HIP_MLOCK=1 (#3913) does
    const bool lock_after = alloc == "register-mlock-after" || alloc == "hostmalloc-mlock-after";
    const bool lock = alloc == "mlock" || alloc == "file-mlock" || lock_after;
    if (lock) {
        rlimit r{RLIM_INFINITY, RLIM_INFINITY};
        if (setrlimit(RLIMIT_MEMLOCK, &r) != 0) { std::perror("setrlimit(RLIMIT_MEMLOCK)"); return 1; }
    }
    uint8_t* host = nullptr;
    const bool hm = alloc == "hostmalloc" || alloc == "hostmalloc-mlock-after" || alloc == "hostmalloc-nc";
    if (hm) {
        // hostmalloc-nc: coarse-grained, as Strata's STRATA_HIP_ARENA_NONCOHERENT=1 (#3913) allocates the complement
        CK(hipHostMalloc((void**) &host, bytes,
                         hipHostMallocMapped | (alloc == "hostmalloc-nc" ? hipHostMallocNonCoherent : 0u)));
    } else if (alloc == "file" || alloc == "file-mlock") {
        const char* path = std::getenv("EVICT_FILE");
        if (!path) { std::fprintf(stderr, "EVICT_FILE not set\n"); return 2; }
        const int fd = open(path, O_RDWR | O_CREAT, 0600);
        if (fd < 0 || ftruncate(fd, (off_t) bytes) != 0) { std::perror("open/ftruncate EVICT_FILE"); return 1; }
        host = (uint8_t*) mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
        if (host == MAP_FAILED) { std::perror("mmap"); return 1; }
        close(fd);
    } else {
        host = (uint8_t*) std::aligned_alloc(1 << 21, bytes);
    }
    if (!host) { std::perror("alloc"); return 1; }
    std::memset(host, 1, bytes);
    if (lock && !lock_after && mlock(host, bytes) != 0) { std::perror("mlock"); return 1; }
    if (!hm) CK(hipHostRegister(host, bytes, hipHostRegisterMapped));
    if (lock_after && mlock(host, bytes) != 0) { std::perror("mlock (after)"); return 1; }
    uint8_t* dev_view; CK(hipHostGetDevicePointer((void**) &dev_view, host, 0));
    const auto before = kfd_vram();
    void* marker; CK(hipMalloc(&marker, kMarker));
    std::string stats;
    for (const auto& [k, v] : kfd_vram()) {
        const auto it = before.find(k);
        const unsigned long long was = it == before.end() ? 0 : it->second;
        if (v >= was + kMarker && v < was + kMarker + (4ull << 20)) stats = k;
    }
    uint32_t* out; CK(hipMalloc(&out, 4));
    hipStream_t s; CK(hipStreamCreateWithFlags(&s, hipStreamNonBlocking));
    read_page<<<1, 256, 0, s>>>((const volatile uint32_t*) dev_view, 1024, out);
    CK(hipStreamSynchronize(s));
    const long ev0 = evicted(stats);
    const std::string st = slurp("/proc/self/status");
    const size_t vl = st.find("VmLck:");

    cpu_set_t cs; sched_getaffinity(0, sizeof(cs), &cs);
    std::vector<int> cpus; for (int c = 0; c < CPU_SETSIZE; ++c) if (CPU_ISSET(c, &cs)) cpus.push_back(c);
    const int nreaders = std::min<int>((int) cpus.size() / 2, 32);
    std::atomic<bool> stop{false};
    std::vector<std::thread> threads;
    for (int r = 0; r < nreaders; ++r)
        threads.emplace_back([&, r] {
            cpu_set_t one; CPU_ZERO(&one); CPU_SET(cpus[(size_t) r * cpus.size() / nreaders], &one);
            sched_setaffinity(0, sizeof(one), &one);
            const size_t chunk = bytes / nreaders;
            volatile uint64_t sink = 0;
            while (!stop.load(std::memory_order_relaxed))
                for (size_t i = r * chunk; i < (r + 1) * chunk && !stop.load(std::memory_order_relaxed); i += 4096)
                    sink += host[i];
        });
    std::atomic<long> moved{0}, move_calls{0};
    const int migrate_ms = std::getenv("EVICT_MIGRATE_MS") ? std::atoi(std::getenv("EVICT_MIGRATE_MS")) : 50;
    if (trigger == "migrate")
        threads.emplace_back([&] {
            const size_t per = (64u << 20) / 4096;
            std::vector<void*> pages(per); std::vector<int> nodes(per), status(per);
            std::vector<int> where(per);
            size_t off = 0;
            while (!stop.load()) {
                // each page to the node it is NOT on (asked first: a move to its own node does nothing)
                for (size_t i = 0; i < per; ++i) pages[i] = host + off + i * 4096;
                if (syscall(SYS_move_pages, 0, per, pages.data(), nullptr, where.data(), 0) >= 0) {
                    for (size_t i = 0; i < per; ++i) nodes[i] = where[i] == 0 ? 1 : 0;
                    if (syscall(SYS_move_pages, 0, per, pages.data(), nodes.data(), status.data(), 2 /* MPOL_MF_MOVE */) >= 0) {
                        long ok = 0; for (size_t i = 0; i < per; ++i) ok += status[i] == nodes[i] && where[i] != nodes[i];
                        moved += ok;
                    }
                }
                ++move_calls;
                off = (off + (64u << 20)) % bytes;
                std::this_thread::sleep_for(std::chrono::milliseconds(migrate_ms));
            }
        });
    std::atomic<long> paged{0};
    if (trigger == "reclaim")
        threads.emplace_back([&] {
            size_t off = 0;
            while (!stop.load()) {
                if (madvise(host + off, 64u << 20, MADV_PAGEOUT) == 0) ++paged;
                off = (off + (64u << 20)) % bytes;
                std::this_thread::sleep_for(std::chrono::milliseconds(200));
            }
        });
    const char* up = std::getenv("HSA_USERPTR_FOR_PAGED_MEM");
    std::printf("alloc %s trigger %s | HSA_USERPTR_FOR_PAGED_MEM=%s | %zu GiB | numa_balancing %s | %s | %d readers | %d s | migrate every %d ms\n",
                alloc.c_str(), trigger.c_str(), up ? up : "(unset)", bytes >> 30, slurp("/proc/sys/kernel/numa_balancing").substr(0, 1).c_str(),
                vl == std::string::npos ? "VmLck ?" : st.substr(vl, st.find('\n', vl) - vl).c_str(), nreaders, seconds, migrate_ms);
    std::vector<double> lat;
    const auto t_end = Clock::now() + std::chrono::seconds(seconds);
    size_t page = 0;
    while (Clock::now() < t_end) {
        const auto t0 = Clock::now();
        read_page<<<1, 256, 0, s>>>((const volatile uint32_t*) (dev_view + page * 4096), 1024, out);
        hipError_t q;
        while ((q = hipStreamQuery(s)) == hipErrorNotReady) {
            if (Clock::now() > t_end + std::chrono::seconds(30)) break;
            std::this_thread::sleep_for(std::chrono::microseconds(20));
        }
        lat.push_back(std::chrono::duration<double, std::milli>(Clock::now() - t0).count());
        if (q == hipErrorNotReady) {   // starved: the queues never came back within the run + 30 s
            stop = true;
            std::printf("RESULT alloc %s trigger %s | STUCK: a launch had not finished after %.1f s (the run is %d s) | "
                        "launches %zu | KFD evicted_ms %ld (%s) | pages moved %ld in %ld calls | %ld pageouts\n",
                        alloc.c_str(), trigger.c_str(), lat.back() / 1000, seconds, lat.size(),
                        evicted(stats) >= 0 && ev0 >= 0 ? evicted(stats) - ev0 : -1, stats.empty() ? "not found" : "found",
                        moved.load(), move_calls.load(), paged.load());
            std::fflush(stdout);
            _exit(3);
        }
        if (q != hipSuccess) { std::fprintf(stderr, "kernel: %s\n", hipGetErrorString(q)); _exit(1); }
        page = (page + 7919) % (bytes / 4096);
        std::this_thread::sleep_until(t0 + std::chrono::milliseconds(1));
    }
    stop = true;
    for (auto& t : threads) t.join();
    const long ev1 = evicted(stats);
    std::vector<double> sl = lat; std::sort(sl.begin(), sl.end());
    auto q = [&](double p) { return sl[std::min(sl.size() - 1, (size_t) (p * (sl.size() - 1)))]; };
    int o10 = 0, o100 = 0; double stalled = 0;
    for (double v : lat) { if (v > 10) ++o10; if (v > 100) { ++o100; stalled += v; } }
    std::printf("RESULT alloc %s trigger %s | launches %zu | latency ms p50 %.3f p99 %.3f p99.9 %.3f max %.1f | >10 ms %d, "
                ">100 ms %d (%.1f s) | KFD evicted_ms %ld (%s) | pages moved %ld in %ld calls | %ld pageouts\n",
                alloc.c_str(), trigger.c_str(), lat.size(), q(0.5), q(0.99), q(0.999), sl.back(), o10, o100, stalled / 1000,
                ev1 >= 0 && ev0 >= 0 ? ev1 - ev0 : -1, stats.empty() ? "not found" : "found", moved.load(), move_calls.load(), paged.load());
    return 0;
}
<!-- gh-comment-id:6591002663 --> @vivienfanghuagood commented on GitHub (Nov 2, 2026): Thanks, both. Two corrections to our last comment first. - @aurelbalteaux, you are right about `expert_source.cpp`, and our reading was wrong. The paced path does call `platform::lock_resident`, but only from `lock_off = partial_pin`, so when the whole tier gets registered nothing is locked. Thank you for checking it. - You are also right that `evicted_ms` cannot be the live signal for (2). KFD adds the time only when the queues come back. Our own runs show the same: the ones that never recovered within 90 s reported `evicted_ms` 0 while they were stuck. @alexanderi96, thanks for #3913. It covers our (1), so we drop it as a separate proposal. We ran #3913's two options through the same probe and machine as before (Radeon PRO W7900D, gfx1100, 2x EPYC 9334, ROCm 7.2.1, kernel 6.8, no swap; 8 GiB, 60 s). The table gives the seconds of queue eviction KFD reports: | | NUMA balancing | migration, 64 MiB/s | migration, 64 MiB every 200 ms | |---|---:|---:|---:| | `hipHostRegister`, then `mlock` (what `STRATA_HIP_MLOCK=1` does) | 48.3 s | 34.3 s | not run | | `hipHostMalloc`, `HSA_USERPTR_FOR_PAGED_MEM=0` | 0 | 0 | 0 | | `hipHostMalloc` with `hipHostMallocNonCoherent`, `HSA_USERPTR_FOR_PAGED_MEM=0` (as `STRATA_HIP_ARENA_NONCOHERENT=1`) | 0 | 0 | 0 | - With `HSA_USERPTR_FOR_PAGED_MEM=0`, `move_pages()` moved none of the `hipHostMalloc` pages, and NUMA balancing caused no eviction. So on this two-socket machine, NUMA balancing does not touch the GTT allocation, which was the open question in #3913. - `mlock`, before or after the registration, stops neither NUMA balancing nor migration. `STRATA_HIP_MLOCK=1` addresses reclaim, and on multi-socket hosts with NUMA balancing on, the memory policy fix in #4867 is still needed. - In every GTT run the longest launch was 3-4 ms, also without a trigger, against 0.3 ms for registered memory. The probe reads one page per launch, so this says nothing about prompt speed. - We still cannot test reclaim here, since there is no swap. @aurelbalteaux, here is the extended probe for the reclaim column. `GIB SECONDS ALLOC TRIGGER`; ALLOC is one of `register`, `mlock` (before the registration), `register-mlock-after`, `hostmalloc`, `hostmalloc-nc`, `file`, `file-mlock` (with `EVICT_FILE=<path>`). TRIGGER is one of `none`, `numa`, `migrate` (`EVICT_MIGRATE_MS`, default 50), `reclaim`. Every trigger except `numa` sets `MPOL_LOCAL` first. Set `HSA_USERPTR_FOR_PAGED_MEM` in the environment for the GTT arms. `migrate` needs two NUMA nodes, so on your box `reclaim` and `none` are the useful ones. Under real pressure, the `register` / `register-mlock-after` / `hostmalloc` (with `=0`) comparison with `TRIGGER=none` is the column we are missing. <details><summary>evict_probe2.hip</summary> ```cpp // evict_probe2: which host-memory setup keeps KFD from evicting a process's GPU queues, under which trigger. // // Every MMU-notifier invalidation of GPU-registered host memory (a userptr or SVM range) makes KFD evict ALL of the // process's queues on a GPU without XNACK, until the range is valid again; submitted work stops and nothing errors. // evict_probe showed one trigger (NUMA balancing). This one compares the memory setups against three: // // GIB SECONDS ALLOC TRIGGER // ALLOC register anonymous memory + hipHostRegister (Strata's expert arena) // mlock the same, mlock()ed before it is registered (RLIMIT_MEMLOCK raised; needs the privilege) // register-mlock-after hipHostRegister, then mlock (the order of Strata's STRATA_HIP_MLOCK=1) // hostmalloc hipHostMalloc (a userptr range under ROCr's default HSA_USERPTR_FOR_PAGED_MEM; GTT with =0) // hostmalloc-nc hipHostMalloc with hipHostMallocNonCoherent (Strata's STRATA_HIP_ARENA_NONCOHERENT=1) // file, file-mlock a MAP_SHARED file (EVICT_FILE) + hipHostRegister, without / with mlock // TRIGGER numa NUMA balancing (kernel.numa_balancing=1; no memory policy set) // migrate MPOL_LOCAL set first (the scanner skips), and a thread moves 64 MiB of the range to the other // NUMA node every 50 ms with move_pages() - the migration compaction does // reclaim MPOL_LOCAL, and a thread reclaims 64 MiB of the range every 200 ms with madvise(MADV_PAGEOUT): // the page-reclaim path (shrink_folio_list -> try_to_unmap). File pages only on a host // without swap (anonymous pages cannot be paged out there); mlocked pages are skipped // none MPOL_LOCAL, nothing else // // The probe: CPU readers touch the region; a tiny kernel reads one page of it every millisecond, timed launch to // completion on the host. It also reads its own KFD evicted_ms (found by a 77 MiB marker allocation) before / after. // // hipcc -O2 --offload-arch=gfx1100 evict_probe2.hip -o evict_probe2 -lpthread #include <hip/hip_runtime.h> #include <algorithm> #include <atomic> #include <chrono> #include <cstdio> #include <cstdlib> #include <cstring> #include <dirent.h> #include <fcntl.h> #include <fstream> #include <sched.h> #include <string> #include <sys/mman.h> #include <sys/resource.h> #include <sys/syscall.h> #include <thread> #include <unistd.h> #include <vector> #define CK(x) do { hipError_t e_ = (x); if (e_ != hipSuccess) { std::fprintf(stderr, "%s: %s\n", #x, hipGetErrorString(e_)); std::exit(1); } } while (0) using Clock = std::chrono::steady_clock; static constexpr size_t kMarker = 77ull << 20; __global__ void read_page(const volatile uint32_t* p, size_t words, uint32_t* out) { uint32_t acc = 0; for (size_t i = threadIdx.x; i < words; i += blockDim.x) acc += p[i]; if (acc == 0xdeadbeef) out[0] = acc; } static std::string slurp(const std::string& p) { std::ifstream f(p); std::string s; std::getline(f, s, '\0'); return s; } // every (KFD process, GPU) VRAM total: this process is the one that grows by the marker allocation #include <map> static std::map<std::string, unsigned long long> kfd_vram() { std::map<std::string, unsigned long long> m; DIR* d = opendir("/sys/class/kfd/kfd/proc"); if (!d) return m; while (dirent* e = readdir(d)) { if (e->d_name[0] == '.') continue; const std::string base = std::string("/sys/class/kfd/kfd/proc/") + e->d_name; DIR* p = opendir(base.c_str()); if (!p) continue; while (dirent* f = readdir(p)) { const std::string n = f->d_name; if (n.rfind("vram_", 0) == 0) m[base + "/stats_" + n.substr(5)] = std::strtoull(slurp(base + "/" + n).c_str(), nullptr, 10); } closedir(p); } closedir(d); return m; } static long evicted(const std::string& stats) { return stats.empty() ? -1 : std::strtol(slurp(stats + "/evicted_ms").c_str(), nullptr, 10); } int main(int argc, char** argv) { if (argc < 5) { std::fprintf(stderr, "usage: evict_probe2 GIB SECONDS ALLOC TRIGGER\n"); return 2; } const size_t bytes = std::strtoull(argv[1], nullptr, 10) << 30; const int seconds = std::atoi(argv[2]); const std::string alloc = argv[3], trigger = argv[4]; if (trigger != "numa") { if (syscall(SYS_set_mempolicy, 4 /* MPOL_LOCAL */, nullptr, 0ul) != 0) { std::perror("set_mempolicy"); return 1; } } // mlock before the registration (mlock, file-mlock), or after it as Strata's STRATA_HIP_MLOCK=1 (#3913) does const bool lock_after = alloc == "register-mlock-after" || alloc == "hostmalloc-mlock-after"; const bool lock = alloc == "mlock" || alloc == "file-mlock" || lock_after; if (lock) { rlimit r{RLIM_INFINITY, RLIM_INFINITY}; if (setrlimit(RLIMIT_MEMLOCK, &r) != 0) { std::perror("setrlimit(RLIMIT_MEMLOCK)"); return 1; } } uint8_t* host = nullptr; const bool hm = alloc == "hostmalloc" || alloc == "hostmalloc-mlock-after" || alloc == "hostmalloc-nc"; if (hm) { // hostmalloc-nc: coarse-grained, as Strata's STRATA_HIP_ARENA_NONCOHERENT=1 (#3913) allocates the complement CK(hipHostMalloc((void**) &host, bytes, hipHostMallocMapped | (alloc == "hostmalloc-nc" ? hipHostMallocNonCoherent : 0u))); } else if (alloc == "file" || alloc == "file-mlock") { const char* path = std::getenv("EVICT_FILE"); if (!path) { std::fprintf(stderr, "EVICT_FILE not set\n"); return 2; } const int fd = open(path, O_RDWR | O_CREAT, 0600); if (fd < 0 || ftruncate(fd, (off_t) bytes) != 0) { std::perror("open/ftruncate EVICT_FILE"); return 1; } host = (uint8_t*) mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (host == MAP_FAILED) { std::perror("mmap"); return 1; } close(fd); } else { host = (uint8_t*) std::aligned_alloc(1 << 21, bytes); } if (!host) { std::perror("alloc"); return 1; } std::memset(host, 1, bytes); if (lock && !lock_after && mlock(host, bytes) != 0) { std::perror("mlock"); return 1; } if (!hm) CK(hipHostRegister(host, bytes, hipHostRegisterMapped)); if (lock_after && mlock(host, bytes) != 0) { std::perror("mlock (after)"); return 1; } uint8_t* dev_view; CK(hipHostGetDevicePointer((void**) &dev_view, host, 0)); const auto before = kfd_vram(); void* marker; CK(hipMalloc(&marker, kMarker)); std::string stats; for (const auto& [k, v] : kfd_vram()) { const auto it = before.find(k); const unsigned long long was = it == before.end() ? 0 : it->second; if (v >= was + kMarker && v < was + kMarker + (4ull << 20)) stats = k; } uint32_t* out; CK(hipMalloc(&out, 4)); hipStream_t s; CK(hipStreamCreateWithFlags(&s, hipStreamNonBlocking)); read_page<<<1, 256, 0, s>>>((const volatile uint32_t*) dev_view, 1024, out); CK(hipStreamSynchronize(s)); const long ev0 = evicted(stats); const std::string st = slurp("/proc/self/status"); const size_t vl = st.find("VmLck:"); cpu_set_t cs; sched_getaffinity(0, sizeof(cs), &cs); std::vector<int> cpus; for (int c = 0; c < CPU_SETSIZE; ++c) if (CPU_ISSET(c, &cs)) cpus.push_back(c); const int nreaders = std::min<int>((int) cpus.size() / 2, 32); std::atomic<bool> stop{false}; std::vector<std::thread> threads; for (int r = 0; r < nreaders; ++r) threads.emplace_back([&, r] { cpu_set_t one; CPU_ZERO(&one); CPU_SET(cpus[(size_t) r * cpus.size() / nreaders], &one); sched_setaffinity(0, sizeof(one), &one); const size_t chunk = bytes / nreaders; volatile uint64_t sink = 0; while (!stop.load(std::memory_order_relaxed)) for (size_t i = r * chunk; i < (r + 1) * chunk && !stop.load(std::memory_order_relaxed); i += 4096) sink += host[i]; }); std::atomic<long> moved{0}, move_calls{0}; const int migrate_ms = std::getenv("EVICT_MIGRATE_MS") ? std::atoi(std::getenv("EVICT_MIGRATE_MS")) : 50; if (trigger == "migrate") threads.emplace_back([&] { const size_t per = (64u << 20) / 4096; std::vector<void*> pages(per); std::vector<int> nodes(per), status(per); std::vector<int> where(per); size_t off = 0; while (!stop.load()) { // each page to the node it is NOT on (asked first: a move to its own node does nothing) for (size_t i = 0; i < per; ++i) pages[i] = host + off + i * 4096; if (syscall(SYS_move_pages, 0, per, pages.data(), nullptr, where.data(), 0) >= 0) { for (size_t i = 0; i < per; ++i) nodes[i] = where[i] == 0 ? 1 : 0; if (syscall(SYS_move_pages, 0, per, pages.data(), nodes.data(), status.data(), 2 /* MPOL_MF_MOVE */) >= 0) { long ok = 0; for (size_t i = 0; i < per; ++i) ok += status[i] == nodes[i] && where[i] != nodes[i]; moved += ok; } } ++move_calls; off = (off + (64u << 20)) % bytes; std::this_thread::sleep_for(std::chrono::milliseconds(migrate_ms)); } }); std::atomic<long> paged{0}; if (trigger == "reclaim") threads.emplace_back([&] { size_t off = 0; while (!stop.load()) { if (madvise(host + off, 64u << 20, MADV_PAGEOUT) == 0) ++paged; off = (off + (64u << 20)) % bytes; std::this_thread::sleep_for(std::chrono::milliseconds(200)); } }); const char* up = std::getenv("HSA_USERPTR_FOR_PAGED_MEM"); std::printf("alloc %s trigger %s | HSA_USERPTR_FOR_PAGED_MEM=%s | %zu GiB | numa_balancing %s | %s | %d readers | %d s | migrate every %d ms\n", alloc.c_str(), trigger.c_str(), up ? up : "(unset)", bytes >> 30, slurp("/proc/sys/kernel/numa_balancing").substr(0, 1).c_str(), vl == std::string::npos ? "VmLck ?" : st.substr(vl, st.find('\n', vl) - vl).c_str(), nreaders, seconds, migrate_ms); std::vector<double> lat; const auto t_end = Clock::now() + std::chrono::seconds(seconds); size_t page = 0; while (Clock::now() < t_end) { const auto t0 = Clock::now(); read_page<<<1, 256, 0, s>>>((const volatile uint32_t*) (dev_view + page * 4096), 1024, out); hipError_t q; while ((q = hipStreamQuery(s)) == hipErrorNotReady) { if (Clock::now() > t_end + std::chrono::seconds(30)) break; std::this_thread::sleep_for(std::chrono::microseconds(20)); } lat.push_back(std::chrono::duration<double, std::milli>(Clock::now() - t0).count()); if (q == hipErrorNotReady) { // starved: the queues never came back within the run + 30 s stop = true; std::printf("RESULT alloc %s trigger %s | STUCK: a launch had not finished after %.1f s (the run is %d s) | " "launches %zu | KFD evicted_ms %ld (%s) | pages moved %ld in %ld calls | %ld pageouts\n", alloc.c_str(), trigger.c_str(), lat.back() / 1000, seconds, lat.size(), evicted(stats) >= 0 && ev0 >= 0 ? evicted(stats) - ev0 : -1, stats.empty() ? "not found" : "found", moved.load(), move_calls.load(), paged.load()); std::fflush(stdout); _exit(3); } if (q != hipSuccess) { std::fprintf(stderr, "kernel: %s\n", hipGetErrorString(q)); _exit(1); } page = (page + 7919) % (bytes / 4096); std::this_thread::sleep_until(t0 + std::chrono::milliseconds(1)); } stop = true; for (auto& t : threads) t.join(); const long ev1 = evicted(stats); std::vector<double> sl = lat; std::sort(sl.begin(), sl.end()); auto q = [&](double p) { return sl[std::min(sl.size() - 1, (size_t) (p * (sl.size() - 1)))]; }; int o10 = 0, o100 = 0; double stalled = 0; for (double v : lat) { if (v > 10) ++o10; if (v > 100) { ++o100; stalled += v; } } std::printf("RESULT alloc %s trigger %s | launches %zu | latency ms p50 %.3f p99 %.3f p99.9 %.3f max %.1f | >10 ms %d, " ">100 ms %d (%.1f s) | KFD evicted_ms %ld (%s) | pages moved %ld in %ld calls | %ld pageouts\n", alloc.c_str(), trigger.c_str(), lat.size(), q(0.5), q(0.99), q(0.999), sl.back(), o10, o100, stalled / 1000, ev1 >= 0 && ev0 >= 0 ? ev1 - ev0 : -1, stats.empty() ? "not found" : "found", moved.load(), move_calls.load(), paged.load()); return 0; } ``` </details>
Author
Owner

@alexanderi96 commented on GitHub (Nov 3, 2026):

@aurelbalteaux thanks, the start-up tier result is a good find. On a 64 GB host I see the same mechanism, but without the stalls: here only 976 of 5199 lend slots are covered at a 32K chunk, but the experts read for the uncovered ones come from the page cache (about 25 GB of expert reads per 63K-token prompt, 0.1-0.4 GB of it from the disk). On 32 GB the page cache cannot hold them, which fits what you measured.

1. Build. No packaging is needed for this test. Check out the PR branch (gh pr checkout 3913, branch alexanderi96:pr-hip-mlock, two commits on v0.2.9) and build it as any source checkout: ./setup.sh --backend hip builds for the detected card (gfx1201 takes the gfx120X-all wheels), or the cmake build in AMD_HIP.md, Build with -DCMAKE_HIP_ARCHITECTURES=gfx1201. packaging/build_hip_linux.sh also works, but it builds a whole engine package.

2. Does the arena have to sit in GTT whole? No. With HSA_USERPTR_FOR_PAGED_MEM=0, GTT has to hold the complement (the resident experts in RAM, which STRATA_HIP_ARENA_NONCOHERENT=1 allocates), the KV copies, and ROCr's own buffers. A smaller --resident-budget-gib, or a larger STRATA_RESIDENT_HEADROOM_GIB, lowers it by the same amount. The start log shows which path the complement took:

  • mapped pinned cache complement ready: ... page-locked and mapped: the GTT allocation went through. mem_info_gtt_used grows by about the budget.
  • page-locking refused (...); trying pageable memory: it did not fit under the GTT limit.
  • page-locking the complement in steps: free RAM at start was below the complement plus a reserve, and the engine took the paced path. That path never makes the GTT allocation; it registers the memory in steps. With your start-up balloon this is the likely case on 32 GB.

I have not measured the last two with =0, so I cannot tell you how they behave there; kfd_evicted_ms and those log lines will show it. Note that GTT pages cannot be reclaimed either: on 32 GB whatever goes into GTT is taken away from the desktop, the same as with mlock.

3. ttm.pages_limit at runtime? It has to be set at boot. In the 6.18 source, amdgpu sizes its GTT once at init from ttm_tt_pages_limit() (amdgpu_ttm.c), and the KFD limit for these allocations is read once too (max_ttm_mem_limit in amdgpu_amdkfd_gpuvm.c). A later write to /sys/module/ttm/parameters/pages_limit changes neither. The default is half the RAM, which is your 15.5 GiB. The KFD limit is also one for the whole system (all GPUs, all processes), and an allocation over it fails with -ENOMEM. Use the kernel command line (ttm.pages_limit=<4 KiB pages>), or options ttm pages_limit=... in modprobe.d as long as it is in the initramfs before amdgpu loads, then check /sys/class/drm/card*/device/mem_info_gtt_total. My host is NixOS (boot.kernelParams), so the exact steps on Ubuntu (GRUB, update-initramfs) may differ.

<!-- gh-comment-id:6591926819 --> @alexanderi96 commented on GitHub (Nov 3, 2026): @aurelbalteaux thanks, the start-up tier result is a good find. On a 64 GB host I see the same mechanism, but without the stalls: here only 976 of 5199 lend slots are covered at a 32K chunk, but the experts read for the uncovered ones come from the page cache (about 25 GB of expert reads per 63K-token prompt, 0.1-0.4 GB of it from the disk). On 32 GB the page cache cannot hold them, which fits what you measured. **1. Build.** No packaging is needed for this test. Check out the PR branch (`gh pr checkout 3913`, branch `alexanderi96:pr-hip-mlock`, two commits on v0.2.9) and build it as any source checkout: `./setup.sh --backend hip` builds for the detected card (gfx1201 takes the `gfx120X-all` wheels), or the cmake build in [AMD_HIP.md, Build](https://github.com/Niko1221/Strata/blob/main/docs/AMD_HIP.md#build) with `-DCMAKE_HIP_ARCHITECTURES=gfx1201`. `packaging/build_hip_linux.sh` also works, but it builds a whole engine package. **2. Does the arena have to sit in GTT whole?** No. With `HSA_USERPTR_FOR_PAGED_MEM=0`, GTT has to hold the complement (the resident experts in RAM, which `STRATA_HIP_ARENA_NONCOHERENT=1` allocates), the KV copies, and ROCr's own buffers. A smaller `--resident-budget-gib`, or a larger `STRATA_RESIDENT_HEADROOM_GIB`, lowers it by the same amount. The start log shows which path the complement took: - `mapped pinned cache complement ready: ... page-locked and mapped`: the GTT allocation went through. `mem_info_gtt_used` grows by about the budget. - `page-locking refused (...); trying pageable memory`: it did not fit under the GTT limit. - `page-locking the complement in steps`: free RAM at start was below the complement plus a reserve, and the engine took the paced path. That path never makes the GTT allocation; it registers the memory in steps. With your start-up balloon this is the likely case on 32 GB. I have not measured the last two with `=0`, so I cannot tell you how they behave there; `kfd_evicted_ms` and those log lines will show it. Note that GTT pages cannot be reclaimed either: on 32 GB whatever goes into GTT is taken away from the desktop, the same as with mlock. **3. `ttm.pages_limit` at runtime?** It has to be set at boot. In the 6.18 source, amdgpu sizes its GTT once at init from `ttm_tt_pages_limit()` (`amdgpu_ttm.c`), and the KFD limit for these allocations is read once too (`max_ttm_mem_limit` in `amdgpu_amdkfd_gpuvm.c`). A later write to `/sys/module/ttm/parameters/pages_limit` changes neither. The default is half the RAM, which is your 15.5 GiB. The KFD limit is also one for the whole system (all GPUs, all processes), and an allocation over it fails with `-ENOMEM`. Use the kernel command line (`ttm.pages_limit=<4 KiB pages>`), or `options ttm pages_limit=...` in modprobe.d as long as it is in the initramfs before amdgpu loads, then check `/sys/class/drm/card*/device/mem_info_gtt_total`. My host is NixOS (`boot.kernelParams`), so the exact steps on Ubuntu (GRUB, `update-initramfs`) may differ.
Author
Owner

@aurelbalteaux commented on GitHub (Nov 3, 2026):

@vivienfanghuagood Thanks for the probe. Here's the reclaim column from this box.

Setup: RX 9070 (gfx1201), Ryzen 7 7800X3D (one NUMA node, numa_balancing 0), 32 GB RAM, 8 GB zram swap, kernel 7.2.
The probe was built with --offload-arch=gfx1201 and run against Strata 0.1.52's bundled runtime (ROCm 7.2.0, via
LD_LIBRARY_PATH), 8 GiB, 90 s per run. For "pressure" I filled RAM with an incompressible balloon down to 2.5 GB
available once the probe had registered its memory, and streamed the 58 GB Gyro-S GGUF through the page cache in a loop,
roughly what a reduced-tier soak does. I didn't run the mlock arms: the hard RLIMIT_MEMLOCK here is 8 MiB.

alloc HSA_USERPTR_FOR_PAGED_MEM trigger KFD evicted launches > 100 ms longest launch
register 1 none, no pressure 0 0 1.1 ms
register 1 none, pressure 17.4 s 36 (15.5 s) 2.8 s
register 0 none, pressure 0.75 s 1 0.52 s
hostmalloc 0 none, pressure 0 0 3.0 ms
hostmalloc-nc 0 none, pressure 0 0 3.0 ms
register 1 reclaim 27.0 s 28 (342 > 10 ms) 157 ms
hostmalloc 0 reclaim 0 0 0.9 ms
  • Under pressure, VmSwap of the probe stayed 0 throughout (the readers keep its pages hot), yet the =1 registration
    lost 17 s of queue time. So something other than swap-out of the registered pages invalidates the range, likely
    compaction or THP migration; I didn't trace it. That fits what I saw with the engine in a memory.swap.max=0 cgroup.
  • =0 takes the SVM path for hipHostRegister and was evicted far less here (0.75 s), but not never.
  • GTT (hostmalloc, either variant) was never evicted. Under reclaim, madvise(MADV_PAGEOUT) failed on every call
    for those pages, so that row is 0 by construction.
  • Launch latency did not show your GTT penalty on this card: median 0.15 ms for every arm, max 3 ms for GTT.
  • PSI full peaked around 1 in the pressure runs: short on RAM, not thrashing.

One more result from the engine itself, on @hartmark's suggestion in ROCm/rocm-systems#12528: with the reduced start-up
tier, GPU_PINNED_MIN_XFER_SIZE=100000 (clr stages pageable copies instead of pinning them) took the soak from 1 failure
and a 91–104 s eviction per run to 0 failures and no eviction over 1.1 s, two runs each. With plenty of RAM it cost no
measurable speed. So on this box most of the long evictions seem to come from clr pinning the source of pageable copies,
not from the arena registration. If the streamed experts go through a pageable hipMemcpy, staging them through a pinned
buffer of the engine's own (or setting that variable) may be a cheap fix on the Strata side.

@alexanderi96 Thanks for the answers. The probe supports the GTT direction of #3913 for the resident tier. For the
reduced-start case, which takes the paced path and never makes the GTT allocation as you said, the staging result above
matters more on this box. I haven't built #3913 yet.

Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.

<!-- gh-comment-id:6595779339 --> @aurelbalteaux commented on GitHub (Nov 3, 2026): @vivienfanghuagood Thanks for the probe. Here's the reclaim column from this box. Setup: RX 9070 (gfx1201), Ryzen 7 7800X3D (one NUMA node, `numa_balancing` 0), 32 GB RAM, 8 GB zram swap, kernel 7.2. The probe was built with `--offload-arch=gfx1201` and run against Strata 0.1.52's bundled runtime (ROCm 7.2.0, via `LD_LIBRARY_PATH`), 8 GiB, 90 s per run. For "pressure" I filled RAM with an incompressible balloon down to 2.5 GB available once the probe had registered its memory, and streamed the 58 GB Gyro-S GGUF through the page cache in a loop, roughly what a reduced-tier soak does. I didn't run the `mlock` arms: the hard `RLIMIT_MEMLOCK` here is 8 MiB. | alloc | `HSA_USERPTR_FOR_PAGED_MEM` | trigger | KFD evicted | launches > 100 ms | longest launch | |---|---|---|---|---|---| | `register` | 1 | `none`, no pressure | 0 | 0 | 1.1 ms | | `register` | 1 | `none`, pressure | **17.4 s** | 36 (15.5 s) | 2.8 s | | `register` | 0 | `none`, pressure | 0.75 s | 1 | 0.52 s | | `hostmalloc` | 0 | `none`, pressure | 0 | 0 | 3.0 ms | | `hostmalloc-nc` | 0 | `none`, pressure | 0 | 0 | 3.0 ms | | `register` | 1 | `reclaim` | **27.0 s** | 28 (342 > 10 ms) | 157 ms | | `hostmalloc` | 0 | `reclaim` | 0 | 0 | 0.9 ms | - Under pressure, `VmSwap` of the probe stayed 0 throughout (the readers keep its pages hot), yet the `=1` registration lost 17 s of queue time. So something other than swap-out of the registered pages invalidates the range, likely compaction or THP migration; I didn't trace it. That fits what I saw with the engine in a `memory.swap.max=0` cgroup. - `=0` takes the SVM path for `hipHostRegister` and was evicted far less here (0.75 s), but not never. - GTT (`hostmalloc`, either variant) was never evicted. Under `reclaim`, `madvise(MADV_PAGEOUT)` failed on every call for those pages, so that row is 0 by construction. - Launch latency did not show your GTT penalty on this card: median 0.15 ms for every arm, max 3 ms for GTT. - PSI `full` peaked around 1 in the pressure runs: short on RAM, not thrashing. One more result from the engine itself, on @hartmark's suggestion in ROCm/rocm-systems#12528: with the reduced start-up tier, `GPU_PINNED_MIN_XFER_SIZE=100000` (clr stages pageable copies instead of pinning them) took the soak from 1 failure and a 91–104 s eviction per run to 0 failures and no eviction over 1.1 s, two runs each. With plenty of RAM it cost no measurable speed. So on this box most of the long evictions seem to come from clr pinning the source of pageable copies, not from the arena registration. If the streamed experts go through a pageable `hipMemcpy`, staging them through a pinned buffer of the engine's own (or setting that variable) may be a cheap fix on the Strata side. @alexanderi96 Thanks for the answers. The probe supports the GTT direction of #3913 for the resident tier. For the reduced-start case, which takes the paced path and never makes the GTT allocation as you said, the staging result above matters more on this box. I haven't built #3913 yet. > Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.
Author
Owner

@alexanderi96 commented on GitHub (Nov 3, 2026):

@aurelbalteaux thanks, the reclaim column and the GPU_PINNED_MIN_XFER_SIZE result are both useful. A follow-up on the two start-up paths I said I had not measured with HSA_USERPTR_FOR_PAGED_MEM=0. I ran them on my host (64 GB, RX 7900 XTX; it says nothing about your box, only about what the PR does), same build, budget 32 GiB, GTT limit 44 GiB, two fresh 24K-token prompts, then 14 GiB taken by another process with the engine idle and again during a prompt:

start-up path GTT used kfd_evicted_ms after load / at the end 24K prompt read (idle / under pressure)
page-locked and mapped 38.2 GiB 0 / 0 2,513 / 895 tok/s
paced (page-locked after taking the pages in steps, forced with STRATA_PIN_GUARD=2) 5.5 GiB 19,807 / 131,117 ms 775-1,238 / 349 tok/s

Both arms already had GPU_PINNED_MIN_XFER_SIZE=1048576 set (my production config carries it), so clr was staging the pageable copies in both. The paced arm still lost minutes of queue time: here, on the paced path, the evictions come from the complement's own registration (it is a userptr whatever HSA_USERPTR_FOR_PAGED_MEM says), not from copy pinning. That fits your probe (register evicted, hostmalloc with =0 never). Your staging result and this one look complementary: the variable removes the copy-pinning evictions, the GTT route removes the registration ones, and only the first start-up path gets the second.

For your runs, if the start log shows the paced line, the engine started with less free RAM than the complement plus a reserve, and that start is not a test of the GTT route. A smaller budget or a larger STRATA_RESIDENT_HEADROOM_GIB that keeps it on the first path is.

One more thing to watch for: the rest of the engine's host allocations also go to GTT, about 5.7 GiB on top of the complement here (256K context, int8 KV). With a 40 GiB budget under the 44 GiB limit the complement fitted, the start log then said "--adapt-async 1 is off (the exchange buffers could not be page-locked)", and the engine crashed during start-up. So keep the GTT limit a few GiB above the budget.

I am adding both to the PR's docs and description.

<!-- gh-comment-id:6598545803 --> @alexanderi96 commented on GitHub (Nov 3, 2026): @aurelbalteaux thanks, the reclaim column and the `GPU_PINNED_MIN_XFER_SIZE` result are both useful. A follow-up on the two start-up paths I said I had not measured with `HSA_USERPTR_FOR_PAGED_MEM=0`. I ran them on my host (64 GB, RX 7900 XTX; it says nothing about your box, only about what the PR does), same build, budget 32 GiB, GTT limit 44 GiB, two fresh 24K-token prompts, then 14 GiB taken by another process with the engine idle and again during a prompt: | start-up path | GTT used | `kfd_evicted_ms` after load / at the end | 24K prompt read (idle / under pressure) | | --- | --- | --- | --- | | `page-locked and mapped` | 38.2 GiB | 0 / 0 | 2,513 / 895 tok/s | | paced (`page-locked after taking the pages in steps`, forced with `STRATA_PIN_GUARD=2`) | 5.5 GiB | 19,807 / 131,117 ms | 775-1,238 / 349 tok/s | Both arms already had `GPU_PINNED_MIN_XFER_SIZE=1048576` set (my production config carries it), so clr was staging the pageable copies in both. The paced arm still lost minutes of queue time: here, on the paced path, the evictions come from the complement's own registration (it is a userptr whatever `HSA_USERPTR_FOR_PAGED_MEM` says), not from copy pinning. That fits your probe (`register` evicted, `hostmalloc` with `=0` never). Your staging result and this one look complementary: the variable removes the copy-pinning evictions, the GTT route removes the registration ones, and only the first start-up path gets the second. For your runs, if the start log shows the paced line, the engine started with less free RAM than the complement plus a reserve, and that start is not a test of the GTT route. A smaller budget or a larger `STRATA_RESIDENT_HEADROOM_GIB` that keeps it on the first path is. One more thing to watch for: the rest of the engine's host allocations also go to GTT, about 5.7 GiB on top of the complement here (256K context, int8 KV). With a 40 GiB budget under the 44 GiB limit the complement fitted, the start log then said "--adapt-async 1 is off (the exchange buffers could not be page-locked)", and the engine crashed during start-up. So keep the GTT limit a few GiB above the budget. I am adding both to the PR's docs and description.
Author
Owner

@vivienfanghuagood commented on GitHub (Nov 3, 2026):

@aurelbalteaux thank you, this fills the column we could not run. How we read it:

  • register, =1, pressure only: 17.4 s with VmSwap 0. The registered pages were not swapped out, so the
    invalidations came from something else. Compaction or THP migration of those pages is the likely candidate. That
    matches our migration rows: move_pages() on registered memory evicted for 21-34 s per minute, and GTT was never touched
    (our runs, including #3913's two options).
    We have not attributed it, though. It could also be reclaim of other pages in the same ranges, or a THP split.
  • register, =0: 0.75 s. With =0, hipHostRegister takes the SVM path, which is still a notifier range, so it
    is not immune. Why it recovered so much faster than the userptr range under the same pressure, we do not know.
  • GTT never evicted, under pressure and under reclaim. Together with our NUMA balancing and migration rows, GTT is
    the only setup that held under every trigger either of us has tried.
  • GPU_PINNED_MIN_XFER_SIZE. In clr a value you set is in MiB, and the default threshold is 64 KiB. So 100000 (and
    the 1048576 documented in #920) means pageable copies are staged and never page-locked. Our reading of your result: in
    the reduced tier, the streamed copies' sources are page-locked for each copy, those short-lived ranges get invalidated
    under reclaim, and each one evicts the queues. That is the same mechanism as ROCm/rocm-systems#12528. @alexanderi96's
    paced-path run then shows the other half, evictions from the complement's own registration. We measured this
    variable earlier on our W7900D for another reason (it also stops the init_user_pages kernel-log lines from the
    read-only model mapping): the profile fill took 3.5 s either way, and TTFT and TPOT were unchanged within 0.1 s /
    0.0 ms.

What we will check next, with no date: how many page-locked copies Strata's expert streaming makes during a long prompt
in a reduced tier, with and without the variable. We will count hsa_amd_memory_lock* calls with an LD_PRELOAD
tracer, on our host. That would confirm which copy path your stalls go through.

One set of numbers from you would settle the 17.4 s. For the register =1 "pressure" run and the hostmalloc =0
"pressure" run, the change in these /proc/vmstat counters over the run: compact_migrate_scanned, compact_success,
pgmigrate_success, thp_split_page, thp_migration_success, pgsteal_kswapd, pgsteal_direct. If compaction or THP
migration moved the registered pages, the first arm should show it and the GTT arm should not. A
cat /proc/vmstat > before; <run>; cat /proc/vmstat > after around each run is enough. No ftrace is needed.

<!-- gh-comment-id:6599858524 --> @vivienfanghuagood commented on GitHub (Nov 3, 2026): @aurelbalteaux thank you, this fills the column we could not run. How we read it: - **`register`, `=1`, pressure only: 17.4 s with `VmSwap` 0.** The registered pages were not swapped out, so the invalidations came from something else. Compaction or THP migration of those pages is the likely candidate. That matches our migration rows: `move_pages()` on registered memory evicted for 21-34 s per minute, and GTT was never touched ([our runs, including #3913's two options](https://github.com/Niko1221/Strata/issues/4866#issuecomment-6591002663)). We have not attributed it, though. It could also be reclaim of other pages in the same ranges, or a THP split. - **`register`, `=0`: 0.75 s.** With `=0`, `hipHostRegister` takes the SVM path, which is still a notifier range, so it is not immune. Why it recovered so much faster than the userptr range under the same pressure, we do not know. - **GTT never evicted**, under pressure and under `reclaim`. Together with our NUMA balancing and migration rows, GTT is the only setup that held under every trigger either of us has tried. - **`GPU_PINNED_MIN_XFER_SIZE`.** In clr a value you set is in MiB, and the default threshold is 64 KiB. So 100000 (and the 1048576 documented in #920) means pageable copies are staged and never page-locked. Our reading of your result: in the reduced tier, the streamed copies' sources are page-locked for each copy, those short-lived ranges get invalidated under reclaim, and each one evicts the queues. That is the same mechanism as ROCm/rocm-systems#12528. @alexanderi96's paced-path run then shows the other half, evictions from the complement's own registration. We measured this variable earlier on our W7900D for another reason (it also stops the `init_user_pages` kernel-log lines from the read-only model mapping): the profile fill took 3.5 s either way, and TTFT and TPOT were unchanged within 0.1 s / 0.0 ms. What we will check next, with no date: how many page-locked copies Strata's expert streaming makes during a long prompt in a reduced tier, with and without the variable. We will count `hsa_amd_memory_lock*` calls with an `LD_PRELOAD` tracer, on our host. That would confirm which copy path your stalls go through. One set of numbers from you would settle the 17.4 s. For the `register` `=1` "pressure" run and the `hostmalloc` `=0` "pressure" run, the change in these `/proc/vmstat` counters over the run: `compact_migrate_scanned`, `compact_success`, `pgmigrate_success`, `thp_split_page`, `thp_migration_success`, `pgsteal_kswapd`, `pgsteal_direct`. If compaction or THP migration moved the registered pages, the first arm should show it and the GTT arm should not. A `cat /proc/vmstat > before; <run>; cat /proc/vmstat > after` around each run is enough. No ftrace is needed.
Author
Owner

@aurelbalteaux commented on GitHub (Nov 3, 2026):

@vivienfanghuagood Here are the counters, plus a trace that attributes the invalidations, since the counters alone can't.

Same setup as before (RX 9070, one NUMA node, numa_balancing 0, bundled ROCm 7.2.0, 8 GiB, 90 s, balloon to 2.5 GB
available + the GGUF streamed through the page cache). /proc/vmstat deltas from the moment the probe had registered its
memory to the end of the run. These are machine-wide, not per process:

control: register =1, no pressure register =1, pressure hostmalloc =0, pressure
KFD evicted 0 11.9 s (18 launches > 100 ms) 0 (max launch 2.2 ms)
compact_migrate_scanned 0 2,783,683 25,500,660
compact_success 0 3,302 5,185
pgmigrate_success 0 700,245 1,261,021
thp_split_page 0 0 0
thp_migration_success 0 0 0
pgsteal_kswapd 0 106,143,280 99,067,485
pgsteal_direct 0 565,174 2,439,523

Both pressure arms compact and reclaim heavily, and the GTT arm even more so. So the counters can't separate the arms:
GTT pages just aren't candidates, so no amount of compaction touches them. The one clear result is that THP is out
(no splits, no THP migrations).

To attribute it, I reran the register =1 pressure arm with function tracing and kernel stacks on the KFD eviction entry
points (amdgpu_hmm_invalidate_hsa, amdgpu_amdkfd_evict_userptr, kgd2kfd_quiesce_mm, the restore workers). The Strata
engine was stopped, so the probe was the only KFD process. This run lost 13.8 s (18 launches > 100 ms, longest 2.6 s).

what count cause, from the stack
userptr notifier calls (amdgpu_hmm_invalidate_hsa) 1,293 969 reclaim (shrink_folio_list → try_to_unmap: 669 direct, 300 kswapd), 318 compaction (compact_zone → migrate_pages → try_to_migrate, all kcompactd), 6 exit
queue stops (kgd2kfd_quiesce_mm) from the userptr path 9 7 kcompactd, 1 direct reclaim, 1 exit
queue stops from svm_range_evict 120 62 kcompactd, 55 direct compaction (__alloc_pages_direct_compact, from dd's readahead), 3 kswapd
amdgpu_amdkfd_restore_userptr_worker 11 –

How I read it:

  • Compaction starts the evictions: 124 of the 129 queue stops come from compact_zone. Reclaim starts almost none.
  • Reclaim causes most of the invalidations of the registered range: 75 % of the notifier calls are try_to_unmap
    from reclaim. Most of them arrive while the process is already evicted (only 9 of 1,293 stop the queues), so they
    probably keep the userptr restore retrying rather than start new evictions. I didn't trace resume, so I can't split the
    13.8 s between the two causes.
  • A correction to my last comment: reclaim does unmap the registered pages. VmSwap peaked at 0.9 MB and 10 MB in
    this round's two register runs (it was 0 last time). So "not swap-out" was too strong. It's mostly compaction plus
    reclaim, not THP.
  • One thing I can't explain: most queue stops (120) went through svm_range_evict, even with =1, and the first
    userptr restore only came 53 s after the first queue stop. Besides the registered buffer, evict_probe2 allocates
    only hipMalloc (VRAM), so these SVM ranges must belong to the runtime (ROCr/clr 7.2.0's own host allocations?), and
    compaction hits them too. I haven't identified them. Do you see svm_range_evict stops on your side with =1?

Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.

<!-- gh-comment-id:6611574800 --> @aurelbalteaux commented on GitHub (Nov 3, 2026): @vivienfanghuagood Here are the counters, plus a trace that attributes the invalidations, since the counters alone can't. Same setup as before (RX 9070, one NUMA node, `numa_balancing` 0, bundled ROCm 7.2.0, 8 GiB, 90 s, balloon to 2.5 GB available + the GGUF streamed through the page cache). `/proc/vmstat` deltas from the moment the probe had registered its memory to the end of the run. **These are machine-wide**, not per process: | | control: `register` `=1`, no pressure | `register` `=1`, pressure | `hostmalloc` `=0`, pressure | |---|---|---|---| | KFD evicted | 0 | **11.9 s** (18 launches > 100 ms) | **0** (max launch 2.2 ms) | | `compact_migrate_scanned` | 0 | 2,783,683 | 25,500,660 | | `compact_success` | 0 | 3,302 | 5,185 | | `pgmigrate_success` | 0 | 700,245 | 1,261,021 | | `thp_split_page` | 0 | 0 | 0 | | `thp_migration_success` | 0 | 0 | 0 | | `pgsteal_kswapd` | 0 | 106,143,280 | 99,067,485 | | `pgsteal_direct` | 0 | 565,174 | 2,439,523 | Both pressure arms compact and reclaim heavily, and the GTT arm even more so. So the counters can't separate the arms: GTT pages just aren't candidates, so no amount of compaction touches them. The one clear result is that THP is out (no splits, no THP migrations). To attribute it, I reran the `register` `=1` pressure arm with function tracing and kernel stacks on the KFD eviction entry points (`amdgpu_hmm_invalidate_hsa`, `amdgpu_amdkfd_evict_userptr`, `kgd2kfd_quiesce_mm`, the restore workers). The Strata engine was stopped, so the probe was the only KFD process. This run lost 13.8 s (18 launches > 100 ms, longest 2.6 s). | what | count | cause, from the stack | |---|---|---| | userptr notifier calls (`amdgpu_hmm_invalidate_hsa`) | 1,293 | 969 reclaim (`shrink_folio_list` → `try_to_unmap`: 669 direct, 300 kswapd), 318 compaction (`compact_zone` → `migrate_pages` → `try_to_migrate`, all `kcompactd`), 6 exit | | queue stops (`kgd2kfd_quiesce_mm`) from the userptr path | 9 | 7 kcompactd, 1 direct reclaim, 1 exit | | queue stops from `svm_range_evict` | 120 | 62 kcompactd, 55 direct compaction (`__alloc_pages_direct_compact`, from `dd`'s readahead), 3 kswapd | | `amdgpu_amdkfd_restore_userptr_worker` | 11 | – | How I read it: - **Compaction starts the evictions:** 124 of the 129 queue stops come from `compact_zone`. Reclaim starts almost none. - **Reclaim causes most of the invalidations of the registered range:** 75 % of the notifier calls are `try_to_unmap` from reclaim. Most of them arrive while the process is already evicted (only 9 of 1,293 stop the queues), so they probably keep the userptr restore retrying rather than start new evictions. I didn't trace resume, so I can't split the 13.8 s between the two causes. - **A correction to my last comment:** reclaim does unmap the registered pages. `VmSwap` peaked at 0.9 MB and 10 MB in this round's two `register` runs (it was 0 last time). So "not swap-out" was too strong. It's mostly compaction plus reclaim, not THP. - **One thing I can't explain:** most queue stops (120) went through `svm_range_evict`, even with `=1`, and the first userptr restore only came 53 s after the first queue stop. Besides the registered buffer, `evict_probe2` allocates only `hipMalloc` (VRAM), so these SVM ranges must belong to the runtime (ROCr/clr 7.2.0's own host allocations?), and compaction hits them too. I haven't identified them. Do you see `svm_range_evict` stops on your side with `=1`? > Investigation and tooling done with Claude (AI, via Claude Code); I reviewed the results.
Author
Owner

@vivienfanghuagood commented on GitHub (Nov 3, 2026):

@aurelbalteaux thanks. That rules out THP and shows compaction starting the stops.

On svm_range_evict stops with =1: we have not traced on our side. The ROCm 7.2.0 source points to an answer, though,
and it assigns the two paths the other way round from your table:

  • hipHostRegister reaches libhsakmt's hsakmt_fmm_register_memory() (through hsa_amd_memory_lock). In rocm-7.2.0
    (projects/rocr-runtime/libhsakmt/src/fmm.c, around line 3910), that function registers new host memory through the
    SVM API whenever KFD reports SVMAPISupported. It falls back to a userptr BO only if that fails.
    HSA_USERPTR_FOR_PAGED_MEM is not consulted there. So the probe's registered buffer would be an SVM range with =1
    as well, and its invalidations would show up as svm_range_evict.
  • HSA_USERPTR_FOR_PAGED_MEM (read around line 2813) applies to the runtime's own paged host allocations
    (fmm_allocate_host_gpu). With it non-zero, those become userptr BOs: the shared /dev/zero mappings @alexanderi96
    traced. Those would be your amdgpu_hmm_invalidate_hsa calls and the restore_userptr_worker runs.

That fits what you saw. Most queue stops are SVM, the 1,293 userptr notifier calls mostly land while the queues are
already stopped, and the first userptr restore comes late. It would also explain your earlier register =0 run losing
only 0.75 s: with =0 the runtime's own allocations become GTT, and only the SVM range is left to invalidate. This is
from reading the source, not from a trace. Logging the probe's region address and comparing it with the range in an
svm_range_evict stack would confirm or refute it.

It also corrects our own wording earlier in this thread. We called the registered arena a userptr, which is only true
where the SVM API is not available. On ROCm 7.2 with SVM support it is an SVM range. The eviction mechanism is the same.

<!-- gh-comment-id:6611672452 --> @vivienfanghuagood commented on GitHub (Nov 3, 2026): @aurelbalteaux thanks. That rules out THP and shows compaction starting the stops. On `svm_range_evict` stops with `=1`: we have not traced on our side. The ROCm 7.2.0 source points to an answer, though, and it assigns the two paths the other way round from your table: - `hipHostRegister` reaches libhsakmt's `hsakmt_fmm_register_memory()` (through `hsa_amd_memory_lock`). In `rocm-7.2.0` (`projects/rocr-runtime/libhsakmt/src/fmm.c`, around line 3910), that function registers new host memory through the SVM API whenever KFD reports `SVMAPISupported`. It falls back to a userptr BO only if that fails. `HSA_USERPTR_FOR_PAGED_MEM` is not consulted there. So the probe's registered buffer would be an SVM range with `=1` as well, and its invalidations would show up as `svm_range_evict`. - `HSA_USERPTR_FOR_PAGED_MEM` (read around line 2813) applies to the runtime's own paged host allocations (`fmm_allocate_host_gpu`). With it non-zero, those become userptr BOs: the shared `/dev/zero` mappings @alexanderi96 traced. Those would be your `amdgpu_hmm_invalidate_hsa` calls and the `restore_userptr_worker` runs. That fits what you saw. Most queue stops are SVM, the 1,293 userptr notifier calls mostly land while the queues are already stopped, and the first userptr restore comes late. It would also explain your earlier `register` `=0` run losing only 0.75 s: with `=0` the runtime's own allocations become GTT, and only the SVM range is left to invalidate. This is from reading the source, not from a trace. Logging the probe's region address and comparing it with the range in an `svm_range_evict` stack would confirm or refute it. It also corrects our own wording earlier in this thread. We called the registered arena a userptr, which is only true where the SVM API is not available. On ROCm 7.2 with SVM support it is an SVM range. The eviction mechanism is the same.
Author
Owner

@vivienfanghuagood commented on GitHub (Nov 3, 2026):

We counted the page-locked copies, as promised in our last comment. Setup: Radeon PRO W7900D (gfx1100), ROCm 7.2.1,
Qwen3.8-Flash-Next IQ3_S native pack, engine at c62d5e3, one 32K-token prompt per engine start. An LD_PRELOAD shim logs
every hsa_amd_memory_lock* / hipHostRegister call with the mapping it lands in. We split the log into what happens
at start-up and what happens during the prompt read:

config GPU_PINNED_MIN_XFER_SIZE page-locks during the 32K prompt at start-up
default (no RAM budget; the GGUF is the file tier) runtime default (64 KiB) 12 succeeded, 337 MiB, anonymous memory 2,358 attempts on the read-only GGUF mapping, all refused (30.8 GB)
default 1048576 0 0 (only the arena's own registration)
--resident-budget-gib 8 runtime default 1,884 succeeded, 3.7 GiB, [heap] + the same 12 the same 2,358 refused
--resident-budget-gib 8 1048576 0 0

With a RAM budget, almost every expert the prompt streams from the file tier goes through a heap buffer, and clr
page-locks that buffer for the copy. Those are the short-lived registered ranges that reclaim and compaction can
invalidate, so we read this as the source of @aurelbalteaux's long evictions in the reduced tier, and of why
GPU_PINNED_MIN_XFER_SIZE=100000 removed them. With the variable set, nothing is page-locked during the prompt. Without a
budget, as here, the start-up attempts all fail on the read-only mapping. Each failure is the
init_user_pages: Failed to get user pages line in the kernel log, about 2,400 per start. They are harmless, but the
variable removes them as well.

Speed: TTFT 23.20 s against 23.22 s without a budget, and 33.3 s against 34.5 s with the 8 GiB budget. These are single
runs in separate processes, within the spread we see between engine starts on this card, so they do not measure a
cost. An earlier two-round alternating A/B on the default config showed TTFT within 0.1 s and the same TPOT.

A question for @Niko1221 before anyone opens a PR: would you take GPU_PINNED_MIN_XFER_SIZE as an engine default on
HIP, set before the first HIP call when the user has not set it? It would keep any value the user sets and have an
opt-out. #920 already documents the variable for the gfx1030 stalls; the question is whether it should be on without
the user knowing about it. Things to decide:

  • which value: anything above the largest copy works; #920 uses 1048576 (MiB);
  • whether only on Linux (we have not tested Windows), and whether for every HIP build or only when a file tier or a RAM
    budget is in use;
  • whether the speed check above is enough, or you want a specific benchmark on the reduced tier first.

We have a local change that does this. We will open it as a PR only if you want the default.

<!-- gh-comment-id:6612604854 --> @vivienfanghuagood commented on GitHub (Nov 3, 2026): We counted the page-locked copies, as promised in our last comment. Setup: Radeon PRO W7900D (gfx1100), ROCm 7.2.1, Qwen3.8-Flash-Next IQ3_S native pack, engine at c62d5e3, one 32K-token prompt per engine start. An `LD_PRELOAD` shim logs every `hsa_amd_memory_lock*` / `hipHostRegister` call with the mapping it lands in. We split the log into what happens at start-up and what happens during the prompt read: | config | `GPU_PINNED_MIN_XFER_SIZE` | page-locks during the 32K prompt | at start-up | |---|---|---|---| | default (no RAM budget; the GGUF is the file tier) | runtime default (64 KiB) | 12 succeeded, 337 MiB, anonymous memory | 2,358 attempts on the read-only GGUF mapping, all refused (30.8 GB) | | default | 1048576 | 0 | 0 (only the arena's own registration) | | `--resident-budget-gib 8` | runtime default | **1,884 succeeded, 3.7 GiB, `[heap]`** + the same 12 | the same 2,358 refused | | `--resident-budget-gib 8` | 1048576 | **0** | 0 | With a RAM budget, almost every expert the prompt streams from the file tier goes through a heap buffer, and clr page-locks that buffer for the copy. Those are the short-lived registered ranges that reclaim and compaction can invalidate, so we read this as the source of @aurelbalteaux's long evictions in the reduced tier, and of why `GPU_PINNED_MIN_XFER_SIZE=100000` removed them. With the variable set, nothing is page-locked during the prompt. Without a budget, as here, the start-up attempts all fail on the read-only mapping. Each failure is the `init_user_pages: Failed to get user pages` line in the kernel log, about 2,400 per start. They are harmless, but the variable removes them as well. Speed: TTFT 23.20 s against 23.22 s without a budget, and 33.3 s against 34.5 s with the 8 GiB budget. These are single runs in separate processes, within the spread we see between engine starts on this card, so they do not measure a cost. An earlier two-round alternating A/B on the default config showed TTFT within 0.1 s and the same TPOT. A question for @Niko1221 before anyone opens a PR: would you take `GPU_PINNED_MIN_XFER_SIZE` as an engine default on HIP, set before the first HIP call when the user has not set it? It would keep any value the user sets and have an opt-out. #920 already documents the variable for the gfx1030 stalls; the question is whether it should be on without the user knowing about it. Things to decide: - which value: anything above the largest copy works; #920 uses 1048576 (MiB); - whether only on Linux (we have not tested Windows), and whether for every HIP build or only when a file tier or a RAM budget is in use; - whether the speed check above is enough, or you want a specific benchmark on the reduced tier first. We have a local change that does this. We will open it as a PR only if you want the default.
Author
Owner

@alexanderi96 commented on GitHub (Nov 4, 2026):

Follow-up from #3913, two things this thread asked about.

  • @aurelbalteaux, the reduced start you described ("the paced path when free RAM is short"): #3913 now has a commit for it. With STRATA_HIP_ARENA_NONCOHERENT=1 the start decides on the RAM available instead of the RAM free, and when that covers the budget plus the reserve the complement goes to GTT in one go. amdgpu's GTT allocation reclaims the file cache itself (__GFP_RETRY_MAYFAIL), and a refused allocation still paces. On a 32 GB host it depends on how much is reclaimable at start: the start log says GTT mode: ... one GTT allocation when it worked. Here, with the cache of other files filling 64 GB, it went from 59,960 ms of queue eviction to 0.
  • @vivienfanghuagood, thanks for the correction about registrations going through SVM when KFD supports it. The docs and comments now say "an MMU-notifier range (SVM or userptr)" instead of "a userptr". Related, from ROCm 10.2 (TheRock nightlies) even hipHostMalloc goes to SVM unless HSA_SVM_FOR_PAGED_MEM=0 is set next to HSA_USERPTR_FOR_PAGED_MEM=0. And TTM's page pool keeps a stopped engine's GTT pages outside MemAvailable (ttm.page_pool_size bounds it). Details in the PR.
<!-- gh-comment-id:6629802129 --> @alexanderi96 commented on GitHub (Nov 4, 2026): Follow-up from #3913, two things this thread asked about. - @aurelbalteaux, the reduced start you described ("the paced path when free RAM is short"): #3913 now has a commit for it. With `STRATA_HIP_ARENA_NONCOHERENT=1` the start decides on the RAM available instead of the RAM free, and when that covers the budget plus the reserve the complement goes to GTT in one go. amdgpu's GTT allocation reclaims the file cache itself (`__GFP_RETRY_MAYFAIL`), and a refused allocation still paces. On a 32 GB host it depends on how much is reclaimable at start: the start log says `GTT mode: ... one GTT allocation` when it worked. Here, with the cache of other files filling 64 GB, it went from 59,960 ms of queue eviction to 0. - @vivienfanghuagood, thanks for the correction about registrations going through SVM when KFD supports it. The docs and comments now say "an MMU-notifier range (SVM or userptr)" instead of "a userptr". Related, from ROCm 10.2 (TheRock nightlies) even `hipHostMalloc` goes to SVM unless `HSA_SVM_FOR_PAGED_MEM=0` is set next to `HSA_USERPTR_FOR_PAGED_MEM=0`. And TTM's page pool keeps a stopped engine's GTT pages outside `MemAvailable` (`ttm.page_pool_size` bounds it). Details in the PR.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2234
No description provided.