[PR #3913] [Engine] HIP/Linux: keep the GPU's host memory out of reclaim: coarse-grained GTT complement, or mlock (both opt-in) #4832

Open
opened 2026-11-07 15:39:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3913
Author: @alexanderi96
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: pr-hip-mlock


📝 Commits (5)

  • 984f2fb HIP/Linux: mlock host memory registered or allocated for the GPU (opt-in: STRATA_HIP_MLOCK=1)
  • 15bc034 HIP/Linux: allocate the expert complement coarse-grained (opt-in: STRATA_HIP_ARENA_NONCOHERENT=1)
  • ef6a766 docs (AMD_HIP): the GTT route's sizing, the start-up paths it does and does not cover, measured
  • 67b8859 HIP/Linux: in GTT mode (STRATA_HIP_ARENA_NONCOHERENT=1) allocate the complement in one go when the RAM available covers it
  • 237d2cb docs (AMD_HIP): GTT route on ROCm 10.2+ (HSA_SVM_FOR_PAGED_MEM=0), the TTM page pool, the one-go start when file cache fills the RAM

📊 Changes

12 files changed (+391 additions, -18 deletions)

View changed files

📝 CMakeLists.txt (+10 -0)
📝 docs/AMD_HIP.md (+107 -0)
📝 docs/TROUBLESHOOTING.md (+5 -1)
📝 include/strata/hip_compat/cuda_runtime.h (+6 -9)
📝 include/strata/platform/hip_compat/strata_hip.h (+6 -5)
➕ include/strata/platform/hip_host_lock.hpp (+109 -0)
📝 serve/server.py (+27 -1)
📝 serve/test_server.py (+17 -0)
📝 src/core/expert_source.cpp (+44 -0)
➕ src/core/hip_host_lock_test.cpp (+53 -0)
📝 src/core/verify.cpp (+3 -2)
📝 tests/core/file_expert_source_test.cpp (+4 -0)

📄 Description

Problem and result

On Linux, ROCm maps host memory for the GPU through a KFD userptr (HMM) and does not pin the pages: hipHostRegister,
and hipHostMalloc under ROCr's default HSA_USERPTR_FOR_PAGED_MEM, leave them pageable. On a GPU without XNACK (every
RDNA card) any invalidation of such a page (reclaim, swap, compaction, NUMA balancing) evicts all of the process's GPU
queues until amdgpu validates the range again. Under memory pressure that lasts seconds to minutes, and the engine
reports no progress for 60 s ... 0 layers served or verify: timed out (#649, #1705, #4862, #4866). The usual
workaround, HSA_USERPTR_FOR_PAGED_MEM=0 alone, makes the expert complement fine-grained GTT and reads prompts about
2.4x slower on an RX 7900 XTX.

This PR adds two opt-in ways to keep that memory out of reclaim. Both are off by default; with neither set nothing
changes.

Route A: GTT (where the GTT limit can be raised) Route B: mlock
Switches HSA_USERPTR_FOR_PAGED_MEM=0 + STRATA_HIP_ARENA_NONCOHERENT=1 (+ HSA_SVM_FOR_PAGED_MEM=0 on ROCm 10.2 and later; GPU_PINNED_MIN_XFER_SIZE=1048576 recommended) STRATA_HIP_MLOCK=1
What it does ROCr backs every host allocation for the GPU with GTT (pinned by amdgpu, no MMU notifier), ROCr's own buffers included. The new switch allocates the expert complement coarse-grained, so prompt speed stays as with page-locked memory Every cudaHostRegister / cudaHostAlloc / cudaMallocHost of the HIP build also mlocks its range
Host requirements ttm.pages_limit set at boot so GTT holds the complement, the KV copies and ROCr's buffers Unlimited memlock limit; vm.compact_unevictable_allowed=0
Covers Reclaim, swap, compaction, page migration, NUMA balancing (the last two measured by @vivienfanghuagood, #4866) Reclaim and swap. Not migration or NUMA balancing, and not ROCr's own shared /dev/zero mappings (short evictions remain: 10-600 ms here)

Measured on one RX 7900 XTX (below): queue eviction 0 ms with route A against 10-600 ms with route B, and a stall
within two minutes with neither; prompt and decode speed the same for A and B.

Refs #649 (the mechanism), #1705 (closed with the HSA_USERPTR_FOR_PAGED_MEM=0 workaround), #750 and #920 (the docs
section this extends), #2729 (SVM restore hangs), #4862 (userptr restore storms before each stop on 2x RX 9070 XT),
#4866 (NUMA balancing; kprobe trace of the /dev/zero mappings; probe results for both routes on a two-socket host).
#4867 (MPOL_LOCAL) is complementary for two-socket hosts that stay on route B. The problem and a first per-caller fix
were found by @Ben1078 in their fork (https://github.com/Ben1078/Strata, branch rdna3-moe-offload-perf). The kernel
behaviour (non-XNACK queue eviction on any invalidation, ROCm/TheRock#7956) is unchanged.

Approach

Commit 1, route B (STRATA_HIP_MLOCK=1):

  • include/strata/platform/hip_host_lock.hpp (new, header-only): host_register / host_unregister / host_alloc /
    host_free call the HIP function, then mlock (or munlock first) the range, with a map of what was locked under a
    mutex. An mlock refusal (RLIMIT_MEMLOCK) prints one line naming the fix and changes nothing else. Non-Linux: the
    functions only forward.
  • include/strata/hip_compat/cuda_runtime.h, include/strata/platform/hip_compat/strata_hip.h (gfx906): the
    cudaHostRegister, cudaHostUnregister, cudaHostAlloc, cudaMallocHost, cudaFreeHost macros point there.
  • src/core/verify.cpp: the verify window's coherent mapped buffers go through host_alloc.
  • serve/server.py: /health reports locked_mib (the engine's VmLck) and kfd_evicted_ms, how long amdgpu has kept
    the engine's queues evicted (the largest /sys/class/kfd/kfd/proc/<pid>/stats_<gpu_id>/evicted_ms; null in a
    container with its own PID namespace). Tests in serve/test_server.py.
  • src/core/hip_host_lock_test.cpp (HIP + Linux, no GPU): the lock / unlock bookkeeping against VmLck.

Commit 2, route A (STRATA_HIP_ARENA_NONCOHERENT=1):

  • src/core/expert_source.cpp: the complement is allocated with hipHostMallocNonCoherent. It is written once at load
    and only read by the GPU afterwards, so it does not need the fine-grained coherence strata_host_alloc forces for
    the flag words two sides spin on.

Commit 4, route A's start-up (same switch):

  • src/core/expert_source.cpp: when the RAM free is short, the #1250 rule used to take the paced path, a registration
    (an MMU-notifier range, SVM or userptr), so route A lost its effect exactly when the file cache filled the RAM. amdgpu
    allocates GTT with __GFP_RETRY_MAYFAIL (reclaims the cache, refuses instead of calling the OOM killer), so with the
    switch the decision uses the RAM available (complement plus the reserve, the paced loop's own rule) and the complement
    is allocated in GTT in one go. A refused GTT allocation still takes the paced path; STRATA_PIN_GUARD=2 and NUMA
    placement still pace. Test: tests/core/file_expert_source_test.cpp (test_pin_pacing).

Docs (commits 3 and 5): docs/AMD_HIP.md ("Linux: verify timeouts while the kernel reclaims host memory": both
routes, host settings, what is not covered, measurements; HSA_SVM_FOR_PAGED_MEM=0 from ROCm 10.2, the TTM page pool,
where ROCm places the GTT complement with two cards visible), docs/TROUBLESHOOTING.md (both routes).

Host setup for route A

  • The GTT size and KFD's limit for these allocations are read from ttm.pages_limit once, when amdgpu loads
    (amdgpu_ttm.c, amdgpu_amdkfd_gpuvm.c). The default is half the RAM. A write to
    /sys/module/ttm/parameters/pages_limit after boot changes neither, so set it on the kernel command line
    (ttm.pages_limit=<4 KiB pages>), or in modprobe.d when that is in the initramfs before amdgpu loads. Check
    /sys/class/drm/card*/device/mem_info_gtt_total after the reboot. The KFD limit is one for the whole system (all
    GPUs, all processes).
  • Size: the resident budget (the complement) plus everything else the engine and ROCr allocate for the GPU on the host.
    Here, at 256K context with int8 KV, that rest is about 5.7 GiB (mem_info_gtt_used 38.2 GiB with a 32 GiB budget).
    Keep the limit above budget + 6 GiB or so: with a 40 GiB budget under a 44 GiB limit the complement fitted, the
    adaptive tier's exchange buffers did not ("--adapt-async 1 is off (the exchange buffers could not be page-locked)"),
    and the engine then crashed during start-up (a segfault inside libamdhip64, under a pageable hipMemcpyAsync of the
    start-up self-test, so most likely clr's staging buffer not fitting either).
  • GTT pages cannot be reclaimed or swapped, like locked pages: the rest of the host meets memory pressure sooner.
  • The start log tells which path the complement took:
    • page-locked and mapped: the GTT allocation went through;
    • GTT mode: ... available covers the complement and the reserve: one GTT allocation: free RAM was short but the RAM
      available covered it, so the complement still went to GTT in one go (commit 4);
    • page-locking refused (...); trying pageable memory: the complement itself is over the limit (it then paces);
    • page-locked after taking the pages in steps: even the RAM available was below the complement plus a reserve, or
      the GTT allocation was refused. This paced path registers the memory (an MMU-notifier range, SVM or userptr), so
      route A does not apply there (measured below). Lower the budget so that it takes the first paths.
  • ROCm 10.2 and later (TheRock nightlies): HSA_USERPTR_FOR_PAGED_MEM=0 alone no longer gives GTT; host allocations go
    to SVM unless HSA_SVM_FOR_PAGED_MEM=0 is set too (80-164 s of queue eviction per benchmark run here without it).
  • TTM keeps the GTT pages a stopped engine freed in its pool (ttm.page_pool_size, half the RAM by default), outside
    MemFree and MemAvailable: the next start lowered the budget from 32 to 18.4 GiB here. ttm.page_pool_size=262144
    (1 GiB) returns them at stop.
  • Tested on NixOS (boot.kernelParams); the way to set kernel and module parameters differs on other distributions.

Validation

Machine: one RX 7900 XTX (gfx1100) on PCIe 4.0 x16, Ryzen 7 5800X, 64 GB DDR4, NixOS, Linux 6.18.53, Docker with
--ulimit memlock=-1 and --pid host. Engine built with setup's build_engine_hip (ROCm 7.10.0a20251120 TheRock
wheels, gfx1100; the 4 November runs on ROCm 10.0.0 and on TheRock 10.2.0a20261022, see each table). Model Swift 1.5 (Qwen3.8-Flash-Next) IQ3_S native pack, --resident-budget-gib 32 --kv int8 --kv-resident 32768 --max-context 262144 --prefill auto:32768 --spec 8, MTP.

Passed:

  • On v0.2.8 (870aedd9, engine 0.1.54) + commit 1: HIP build, hip_host_lock_test (memlock unlimited and 1 MiB: ok;
    0: skip with the one-line warning), python -m unittest serve.test_server, a start with STRATA_HIP_MLOCK=1.

  • On v0.2.9 (c62d5e3a, engine 0.1.55) + both commits: HIP build; starts and daily serving with each route, with the
    expected start lines and the /health fields.

  • Route B against neither, stress A/B (same image and config, only STRATA_HIP_MLOCK changed, B0 B B0 B, each stopped
    at its first stall or after 30 min; 4 conversations of 30K-220K-token prompts, a second process holding RAM down to
    ~5 GiB available, an 18 GB file read in a loop; vm.compact_unevictable_allowed=0 in both arms; measured on 0.2.3.1):

    arm STRATA_HIP_MLOCK result
    B0-r1 0 stall after 103 s
    B-r1 1 30 min, 29/29 requests, no stall
    B0-r2 0 stall after 63 s
    B-r2 1 30 min, 28/28 requests, no stall
  • Route A against route B (v0.2.9, budget 32 GiB, GTT 44 GiB, 1 GB of RAM or less free, five fresh 30K-token prompts
    per run, then 6 GB taken by another process with the engine idle):

    Prompt read Decode Queue eviction, prompts Queue eviction, 6 GB taken
    route B (userptr + mlock) 2,330-2,370 tok/s 64-71 tok/s 229, 56, 10 ms (3 of 5) 595 ms
    route A (2 runs) 2,290-2,350 tok/s 60-72 tok/s 0 (10 of 10) 0 ms
    GTT, coherent complement (budget 22) about 2.4x slower 0 0 ms
  • Route A's start-up paths (v0.2.9, HSA_USERPTR_FOR_PAGED_MEM=0 + STRATA_HIP_ARENA_NONCOHERENT=1, two fresh
    24K-token prompts, then 14 GiB taken by another process for 40 s with the engine idle, then again during a prompt):

    start-up path GTT used kfd_evicted_ms after load / at the end 24K prompt read (idle host / under pressure)
    page-locked and mapped (budget 32) 38.2 GiB 0 / 0 2,513 / 895 tok/s
    paced, forced with STRATA_PIN_GUARD=2 (budget 32) 5.5 GiB 19,807 / 131,117 ms 775-1,238 / 349 tok/s
    budget 40 under a 44 GiB limit - - engine crashed at start-up (above)
  • Commit 4, a start with about 55 GB of unrelated files read just before (TTM pool at 1 GiB, 0.4-0.5 GiB free after the
    engine drops its own cache, budget 32 GiB, one strata_bench.py --long run each; before = v0.2.9 + commits 1-3 on
    ROCm 10.0, after = v0.2.10 + these commits on ROCm 10.2):

    start log kfd_evicted_ms at the end prompt read, median (lowest), 16K / 32K / 63K
    before page-locked after taking the pages in steps 59,960 ms 2,526 (1,086) / 3,084 (860) / 3,270-3,347 tok/s
    after GTT mode: 52.20 GiB available ..., page-locked and mapped 0 ms 2,975 (1,734) / 3,129 (1,945) / 3,355-3,419 tok/s

    The eviction counter is the result: the stalls show in the lowest runs, the medians at 32K and 63K are within 2-4%,
    and part of the 16K gap is the newer build.

  • Two cards: @tproos, 2x RX 9070 XT layer split with route A, 37 requests of long MCP sessions without the -15 that
    ended every release run after 4-8 tool calls. He still saw the eviction counter grow slowly; the two causes found
    since (clr's page-locks, the paced start) are covered by GPU_PINNED_MIN_XFER_SIZE and commit 4, not yet confirmed
    on his host. Here, an RX 7900 XTX pair (x16 + chipset x4) layer split on v0.2.10, kfd_evicted_ms 0 in
    five benchmark runs.

  • Speed with route A, tools/strata_bench.py --long, 2 rounds: prompt 4K ~1,560, 16K ~2,290, 32K ~2,350 tok/s; decode
    unchanged.

  • On a two-socket host (@vivienfanghuagood, #4866, W7900D, eviction probe): NUMA balancing 48.3 s and page migration
    34.3 s of queue eviction with route B's order (register, then mlock); 0 and 0 with route A, coherent or not.

  • Daily use (not a controlled test): route B since 23 October, route A since the evening of 2 November. From 28
    October to 3 November the engine log has about 4,000 requests over 66 engine starts and 0 no progress stops or
    verify timeouts. The last stop in that log is from 23 October, on the official image during the stress hour above.

Failed:
none observed.

Not run:

  • The page-locking refused path itself (a complement larger than the whole GTT limit); the start-up crash when the
    limit runs out after the complement was traced only to that copy (libamdhip64 has no symbols here).
  • A host short of RAM (32 GB) with route A and commit 4; @aurelbalteaux has offered to run it (#4866).
  • CUDA, SYCL, Metal builds (only HIP headers change); gfx906; Windows HIP (Linux-only, the wrappers forward there).
  • Two-GPU layer split under the stress above (only benchmark runs and @tproos's sessions).
  • A before/after of commit 4 on the same build.

Limits

  • Off by default; each route needs the host settings above, and without them the behaviour is as before.
  • Route B: migration, khugepaged collapse, fork() of the engine, CMA / memory offline and NUMA balancing are not
    covered; ROCr's own allocations are not routed through the wrappers.
  • Route A: needs a reboot to raise the GTT limit; the paced start-up path, now taken only when the RAM available is short
    or GTT is refused, does not use it (the evictions come back there); a limit too tight for the rest of the engine's host allocations ends in a crash at start-up, not a clean
    error.
  • Both: memory that cannot be reclaimed is taken from the rest of the host.
  • Measured on one machine and one model, plus the probe results and field reports in #4866.

AI disclosure

The patch, the tests and this text were prepared with an AI coding assistant (Claude, Anthropic) working on my machine
at my direction. The measurements are from runs on my hardware; logs are available on request. Credit for finding the
problem and the first per-caller fix goes to Ben1078's fork.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3913 **Author:** [@alexanderi96](https://github.com/alexanderi96) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr-hip-mlock` --- ### 📝 Commits (5) - [`984f2fb`](https://github.com/Niko1221/Strata/commit/984f2fbaa1c7a8e78c35dec9c0c10e28117acce2) HIP/Linux: mlock host memory registered or allocated for the GPU (opt-in: STRATA_HIP_MLOCK=1) - [`15bc034`](https://github.com/Niko1221/Strata/commit/15bc03434ceb2b5683b17b5588a24266b68779e8) HIP/Linux: allocate the expert complement coarse-grained (opt-in: STRATA_HIP_ARENA_NONCOHERENT=1) - [`ef6a766`](https://github.com/Niko1221/Strata/commit/ef6a766d7c6c71834e3a400e12666d2ceb6c11e1) docs (AMD_HIP): the GTT route's sizing, the start-up paths it does and does not cover, measured - [`67b8859`](https://github.com/Niko1221/Strata/commit/67b8859a97cfce18c882590e656a707db4aec58d) HIP/Linux: in GTT mode (STRATA_HIP_ARENA_NONCOHERENT=1) allocate the complement in one go when the RAM available covers it - [`237d2cb`](https://github.com/Niko1221/Strata/commit/237d2cb225fce7e871145e8eed846932faf2dbea) docs (AMD_HIP): GTT route on ROCm 10.2+ (HSA_SVM_FOR_PAGED_MEM=0), the TTM page pool, the one-go start when file cache fills the RAM ### 📊 Changes **12 files changed** (+391 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+10 -0) 📝 `docs/AMD_HIP.md` (+107 -0) 📝 `docs/TROUBLESHOOTING.md` (+5 -1) 📝 `include/strata/hip_compat/cuda_runtime.h` (+6 -9) 📝 `include/strata/platform/hip_compat/strata_hip.h` (+6 -5) ➕ `include/strata/platform/hip_host_lock.hpp` (+109 -0) 📝 `serve/server.py` (+27 -1) 📝 `serve/test_server.py` (+17 -0) 📝 `src/core/expert_source.cpp` (+44 -0) ➕ `src/core/hip_host_lock_test.cpp` (+53 -0) 📝 `src/core/verify.cpp` (+3 -2) 📝 `tests/core/file_expert_source_test.cpp` (+4 -0) </details> ### 📄 Description ## Problem and result On Linux, ROCm maps host memory for the GPU through a KFD userptr (HMM) and does not pin the pages: `hipHostRegister`, and `hipHostMalloc` under ROCr's default `HSA_USERPTR_FOR_PAGED_MEM`, leave them pageable. On a GPU without XNACK (every RDNA card) any invalidation of such a page (reclaim, swap, compaction, NUMA balancing) evicts all of the process's GPU queues until amdgpu validates the range again. Under memory pressure that lasts seconds to minutes, and the engine reports `no progress for 60 s ... 0 layers served` or `verify: timed out` (#649, #1705, #4862, #4866). The usual workaround, `HSA_USERPTR_FOR_PAGED_MEM=0` alone, makes the expert complement fine-grained GTT and reads prompts about 2.4x slower on an RX 7900 XTX. This PR adds two opt-in ways to keep that memory out of reclaim. Both are off by default; with neither set nothing changes. | | Route A: GTT (where the GTT limit can be raised) | Route B: mlock | | --- | --- | --- | | Switches | `HSA_USERPTR_FOR_PAGED_MEM=0` + `STRATA_HIP_ARENA_NONCOHERENT=1` (+ `HSA_SVM_FOR_PAGED_MEM=0` on ROCm 10.2 and later; `GPU_PINNED_MIN_XFER_SIZE=1048576` recommended) | `STRATA_HIP_MLOCK=1` | | What it does | ROCr backs every host allocation for the GPU with GTT (pinned by amdgpu, no MMU notifier), ROCr's own buffers included. The new switch allocates the expert complement coarse-grained, so prompt speed stays as with page-locked memory | Every `cudaHostRegister` / `cudaHostAlloc` / `cudaMallocHost` of the HIP build also `mlock`s its range | | Host requirements | `ttm.pages_limit` set at boot so GTT holds the complement, the KV copies and ROCr's buffers | Unlimited memlock limit; `vm.compact_unevictable_allowed=0` | | Covers | Reclaim, swap, compaction, page migration, NUMA balancing (the last two measured by @vivienfanghuagood, #4866) | Reclaim and swap. Not migration or NUMA balancing, and not ROCr's own shared `/dev/zero` mappings (short evictions remain: 10-600 ms here) | Measured on one RX 7900 XTX (below): queue eviction 0 ms with route A against 10-600 ms with route B, and a stall within two minutes with neither; prompt and decode speed the same for A and B. ## Related discussion Refs #649 (the mechanism), #1705 (closed with the `HSA_USERPTR_FOR_PAGED_MEM=0` workaround), #750 and #920 (the docs section this extends), #2729 (SVM restore hangs), #4862 (userptr restore storms before each stop on 2x RX 9070 XT), #4866 (NUMA balancing; kprobe trace of the `/dev/zero` mappings; probe results for both routes on a two-socket host). #4867 (`MPOL_LOCAL`) is complementary for two-socket hosts that stay on route B. The problem and a first per-caller fix were found by @Ben1078 in their fork (https://github.com/Ben1078/Strata, branch rdna3-moe-offload-perf). The kernel behaviour (non-XNACK queue eviction on any invalidation, ROCm/TheRock#7956) is unchanged. ## Approach Commit 1, route B (`STRATA_HIP_MLOCK=1`): - `include/strata/platform/hip_host_lock.hpp` (new, header-only): `host_register` / `host_unregister` / `host_alloc` / `host_free` call the HIP function, then `mlock` (or `munlock` first) the range, with a map of what was locked under a mutex. An `mlock` refusal (RLIMIT_MEMLOCK) prints one line naming the fix and changes nothing else. Non-Linux: the functions only forward. - `include/strata/hip_compat/cuda_runtime.h`, `include/strata/platform/hip_compat/strata_hip.h` (gfx906): the `cudaHostRegister`, `cudaHostUnregister`, `cudaHostAlloc`, `cudaMallocHost`, `cudaFreeHost` macros point there. - `src/core/verify.cpp`: the verify window's coherent mapped buffers go through `host_alloc`. - `serve/server.py`: `/health` reports `locked_mib` (the engine's VmLck) and `kfd_evicted_ms`, how long amdgpu has kept the engine's queues evicted (the largest `/sys/class/kfd/kfd/proc/<pid>/stats_<gpu_id>/evicted_ms`; `null` in a container with its own PID namespace). Tests in `serve/test_server.py`. - `src/core/hip_host_lock_test.cpp` (HIP + Linux, no GPU): the lock / unlock bookkeeping against VmLck. Commit 2, route A (`STRATA_HIP_ARENA_NONCOHERENT=1`): - `src/core/expert_source.cpp`: the complement is allocated with `hipHostMallocNonCoherent`. It is written once at load and only read by the GPU afterwards, so it does not need the fine-grained coherence `strata_host_alloc` forces for the flag words two sides spin on. Commit 4, route A's start-up (same switch): - `src/core/expert_source.cpp`: when the RAM free is short, the #1250 rule used to take the paced path, a registration (an MMU-notifier range, SVM or userptr), so route A lost its effect exactly when the file cache filled the RAM. amdgpu allocates GTT with `__GFP_RETRY_MAYFAIL` (reclaims the cache, refuses instead of calling the OOM killer), so with the switch the decision uses the RAM available (complement plus the reserve, the paced loop's own rule) and the complement is allocated in GTT in one go. A refused GTT allocation still takes the paced path; `STRATA_PIN_GUARD=2` and NUMA placement still pace. Test: `tests/core/file_expert_source_test.cpp` (`test_pin_pacing`). Docs (commits 3 and 5): `docs/AMD_HIP.md` ("Linux: verify timeouts while the kernel reclaims host memory": both routes, host settings, what is not covered, measurements; `HSA_SVM_FOR_PAGED_MEM=0` from ROCm 10.2, the TTM page pool, where ROCm places the GTT complement with two cards visible), `docs/TROUBLESHOOTING.md` (both routes). ## Host setup for route A - The GTT size and KFD's limit for these allocations are read from `ttm.pages_limit` once, when amdgpu loads (`amdgpu_ttm.c`, `amdgpu_amdkfd_gpuvm.c`). The default is half the RAM. A write to `/sys/module/ttm/parameters/pages_limit` after boot changes neither, so set it on the kernel command line (`ttm.pages_limit=<4 KiB pages>`), or in modprobe.d when that is in the initramfs before amdgpu loads. Check `/sys/class/drm/card*/device/mem_info_gtt_total` after the reboot. The KFD limit is one for the whole system (all GPUs, all processes). - Size: the resident budget (the complement) plus everything else the engine and ROCr allocate for the GPU on the host. Here, at 256K context with int8 KV, that rest is about 5.7 GiB (`mem_info_gtt_used` 38.2 GiB with a 32 GiB budget). Keep the limit above budget + 6 GiB or so: with a 40 GiB budget under a 44 GiB limit the complement fitted, the adaptive tier's exchange buffers did not ("--adapt-async 1 is off (the exchange buffers could not be page-locked)"), and the engine then crashed during start-up (a segfault inside `libamdhip64`, under a pageable `hipMemcpyAsync` of the start-up self-test, so most likely clr's staging buffer not fitting either). - GTT pages cannot be reclaimed or swapped, like locked pages: the rest of the host meets memory pressure sooner. - The start log tells which path the complement took: - `page-locked and mapped`: the GTT allocation went through; - `GTT mode: ... available covers the complement and the reserve: one GTT allocation`: free RAM was short but the RAM available covered it, so the complement still went to GTT in one go (commit 4); - `page-locking refused (...); trying pageable memory`: the complement itself is over the limit (it then paces); - `page-locked after taking the pages in steps`: even the RAM available was below the complement plus a reserve, or the GTT allocation was refused. This paced path registers the memory (an MMU-notifier range, SVM or userptr), so route A does not apply there (measured below). Lower the budget so that it takes the first paths. - ROCm 10.2 and later (TheRock nightlies): `HSA_USERPTR_FOR_PAGED_MEM=0` alone no longer gives GTT; host allocations go to SVM unless `HSA_SVM_FOR_PAGED_MEM=0` is set too (80-164 s of queue eviction per benchmark run here without it). - TTM keeps the GTT pages a stopped engine freed in its pool (`ttm.page_pool_size`, half the RAM by default), outside `MemFree` and `MemAvailable`: the next start lowered the budget from 32 to 18.4 GiB here. `ttm.page_pool_size=262144` (1 GiB) returns them at stop. - Tested on NixOS (`boot.kernelParams`); the way to set kernel and module parameters differs on other distributions. ## Validation Machine: one RX 7900 XTX (gfx1100) on PCIe 4.0 x16, Ryzen 7 5800X, 64 GB DDR4, NixOS, Linux 6.18.53, Docker with `--ulimit memlock=-1` and `--pid host`. Engine built with setup's `build_engine_hip` (ROCm 7.10.0a20251120 TheRock wheels, gfx1100; the 4 November runs on ROCm 10.0.0 and on TheRock 10.2.0a20261022, see each table). Model Swift 1.5 (Qwen3.8-Flash-Next) IQ3_S native pack, `--resident-budget-gib 32 --kv int8 --kv-resident 32768 --max-context 262144 --prefill auto:32768 --spec 8`, MTP. **Passed:** - On v0.2.8 (870aedd9, engine 0.1.54) + commit 1: HIP build, `hip_host_lock_test` (memlock unlimited and 1 MiB: ok; 0: skip with the one-line warning), `python -m unittest serve.test_server`, a start with `STRATA_HIP_MLOCK=1`. - On v0.2.9 (c62d5e3a, engine 0.1.55) + both commits: HIP build; starts and daily serving with each route, with the expected start lines and the `/health` fields. - Route B against neither, stress A/B (same image and config, only `STRATA_HIP_MLOCK` changed, B0 B B0 B, each stopped at its first stall or after 30 min; 4 conversations of 30K-220K-token prompts, a second process holding RAM down to ~5 GiB available, an 18 GB file read in a loop; `vm.compact_unevictable_allowed=0` in both arms; measured on 0.2.3.1): | arm | STRATA_HIP_MLOCK | result | |---|---|---| | B0-r1 | 0 | stall after 103 s | | B-r1 | 1 | 30 min, 29/29 requests, no stall | | B0-r2 | 0 | stall after 63 s | | B-r2 | 1 | 30 min, 28/28 requests, no stall | - Route A against route B (v0.2.9, budget 32 GiB, GTT 44 GiB, 1 GB of RAM or less free, five fresh 30K-token prompts per run, then 6 GB taken by another process with the engine idle): | | Prompt read | Decode | Queue eviction, prompts | Queue eviction, 6 GB taken | | --- | --- | --- | --- | --- | | route B (userptr + mlock) | 2,330-2,370 tok/s | 64-71 tok/s | 229, 56, 10 ms (3 of 5) | 595 ms | | route A (2 runs) | 2,290-2,350 tok/s | 60-72 tok/s | 0 (10 of 10) | 0 ms | | GTT, coherent complement (budget 22) | about 2.4x slower | | 0 | 0 ms | - Route A's start-up paths (v0.2.9, `HSA_USERPTR_FOR_PAGED_MEM=0` + `STRATA_HIP_ARENA_NONCOHERENT=1`, two fresh 24K-token prompts, then 14 GiB taken by another process for 40 s with the engine idle, then again during a prompt): | start-up path | GTT used | `kfd_evicted_ms` after load / at the end | 24K prompt read (idle host / under pressure) | | --- | --- | --- | --- | | `page-locked and mapped` (budget 32) | 38.2 GiB | 0 / 0 | 2,513 / 895 tok/s | | paced, forced with `STRATA_PIN_GUARD=2` (budget 32) | 5.5 GiB | 19,807 / 131,117 ms | 775-1,238 / 349 tok/s | | budget 40 under a 44 GiB limit | - | - | engine crashed at start-up (above) | - Commit 4, a start with about 55 GB of unrelated files read just before (TTM pool at 1 GiB, 0.4-0.5 GiB free after the engine drops its own cache, budget 32 GiB, one `strata_bench.py --long` run each; before = v0.2.9 + commits 1-3 on ROCm 10.0, after = v0.2.10 + these commits on ROCm 10.2): | | start log | `kfd_evicted_ms` at the end | prompt read, median (lowest), 16K / 32K / 63K | | --- | --- | --- | --- | | before | `page-locked after taking the pages in steps` | 59,960 ms | 2,526 (1,086) / 3,084 (860) / 3,270-3,347 tok/s | | after | `GTT mode: 52.20 GiB available ...`, `page-locked and mapped` | 0 ms | 2,975 (1,734) / 3,129 (1,945) / 3,355-3,419 tok/s | The eviction counter is the result: the stalls show in the lowest runs, the medians at 32K and 63K are within 2-4%, and part of the 16K gap is the newer build. - Two cards: @tproos, 2x RX 9070 XT layer split with route A, 37 requests of long MCP sessions without the `-15` that ended every release run after 4-8 tool calls. He still saw the eviction counter grow slowly; the two causes found since (clr's page-locks, the paced start) are covered by `GPU_PINNED_MIN_XFER_SIZE` and commit 4, not yet confirmed on his host. Here, an RX 7900 XTX pair (x16 + chipset x4) layer split on v0.2.10, `kfd_evicted_ms` 0 in five benchmark runs. - Speed with route A, `tools/strata_bench.py --long`, 2 rounds: prompt 4K ~1,560, 16K ~2,290, 32K ~2,350 tok/s; decode unchanged. - On a two-socket host (@vivienfanghuagood, #4866, W7900D, eviction probe): NUMA balancing 48.3 s and page migration 34.3 s of queue eviction with route B's order (register, then mlock); 0 and 0 with route A, coherent or not. - Daily use (not a controlled test): route B since 23 October, route A since the evening of 2 November. From 28 October to 3 November the engine log has about 4,000 requests over 66 engine starts and 0 `no progress` stops or verify timeouts. The last stop in that log is from 23 October, on the official image during the stress hour above. **Failed:** none observed. **Not run:** - The `page-locking refused` path itself (a complement larger than the whole GTT limit); the start-up crash when the limit runs out after the complement was traced only to that copy (`libamdhip64` has no symbols here). - A host short of RAM (32 GB) with route A and commit 4; @aurelbalteaux has offered to run it (#4866). - CUDA, SYCL, Metal builds (only HIP headers change); gfx906; Windows HIP (Linux-only, the wrappers forward there). - Two-GPU layer split under the stress above (only benchmark runs and @tproos's sessions). - A before/after of commit 4 on the same build. ## Limits - Off by default; each route needs the host settings above, and without them the behaviour is as before. - Route B: migration, khugepaged collapse, fork() of the engine, CMA / memory offline and NUMA balancing are not covered; ROCr's own allocations are not routed through the wrappers. - Route A: needs a reboot to raise the GTT limit; the paced start-up path, now taken only when the RAM available is short or GTT is refused, does not use it (the evictions come back there); a limit too tight for the rest of the engine's host allocations ends in a crash at start-up, not a clean error. - Both: memory that cannot be reclaimed is taken from the rest of the host. - Measured on one machine and one model, plus the probe results and field reports in #4866. ## AI disclosure The patch, the tests and this text were prepared with an AI coding assistant (Claude, Anthropic) working on my machine at my direction. The measurements are from runs on my hardware; logs are available on request. Credit for finding the problem and the first per-caller fix goes to Ben1078's fork. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4832
No description provided.