Repository navigation
hrx: a parked host-weight slot outlives the arena that parked it (engine #900) - #182
Conversation
…m (engine ggml-org#900) A slot parked while an execution is in flight (arena_deferred_) survives the arena being re-created, so end_execution() reclaims it into the NEW free list at its OLD offset. Those offsets interleave with live allocations: the free list then claims 193.2 MiB in 5 blocks in a 200 MiB arena whose only weight is 121.7 MiB, the next weight of that size is refused, and the refusal reports 205 MiB parked against a 200 MiB limit - both numbers the issue quotes. It is not only a wrong count. arena_take_locked() hands out whatever block fits, so a stale extent that is large enough would be given to a second weight while the first still holds it: one extent, two weights, silent corruption. The grow path already drops everything else that pointed into the released arena (entries_, last_use_, resident_bytes_, the free list); the parked list belongs with them, and no lease can reference a parked extent because eviction only takes entries the cache solely owns (use_count() == 1). Measured on Qwen3-0.6B-Q4_K_M, -ngl 0, one gpu-hold ticket, base = the pin's staged binary vs this build, budgets 200/210/220/230/240. Base: parked exceeds the limit at every budget (205/200 ... 245/240) and a 121.7 MiB weight is refused at every budget. Fix: resident + parked + free sums to the limit (199.3 of 200 ... 239.9 of 240), the free list is one block instead of 4-5, and the 121.7 MiB weight is admitted every time.
|
#182 ready for review at Diagnostic-free behaviour fix: a parked ( Not measured: the corruption case itself (a stale extent large enough to be taken by a later weight) — the arms stop one step before it. |
|
Regression arm at the shape the fleet serves ( Both are honest capacity refusals and both already satisfy |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at fee91177d. Five lines, the right five, and the artefacts in
~/amd-oss/hrx-study/evidence/memory/arena-deferred-20261103-{2024,2124,2136}.log say what the PR says they say — I
re-read the arms rather than the table.
The code. arena_deferred_.clear() lands in the block that releases the old buffer and drops entries_/
last_use_/stats_/arena_free_ — i.e. with everything else that pointed into the released arena — and it is the
same clear the cache already does in reset() (host-memory.cpp:2039), so the pattern is not new. The invariant that
makes it safe holds: a slot is parked only when executions_ != 0 on a reclaim (:1528-1532), and eviction only takes
entries with use_count() == 1 (:1607, :1805 — "a lease is a borrowed snapshot, so use_count() == 1 means the
cache is the only owner"), so no live lease can refer to a parked extent, and the whole old buffer is released
wholesale anyway. host-memory.cpp at this head is -fsyntax-only clean with the real hrx-system/loom include paths.
The logs, re-derived. Base arms (pin binary):
base-200 0.0 resident, 193.2 MiB free in 5 blocks, 121.7 MiB wanted, 205 MiB parked -> 398.2 vs a 200 limit
base-240 0.0 resident, 233.1 MiB free in 4 blocks, 121.7 MiB wanted, 245 MiB parked -> 478.1 vs a 240 limit
base-320 0.0 resident, 72.9 MiB free in 2 blocks, 121.7 MiB wanted, 247 MiB parked
The fix arms (i900-arena-deferred/build-priv, same model and command):
fix-200 70.0 resident + 128 parked + 1.3 free = 199.3 refuses a 1.7 MiB weight (not the 121.7 one)
fix-210 80.9 + 128 + 0.4 = 209.3 refuses a 1.7 MiB weight
fix-220 92.7 + 127 + 0.2 = 219.9 refuses a 1.1 MiB weight
fix-230 102.2 + 127 + 0.7 = 229.9 refuses a 1.1 MiB weight
fix-240 112.9 + 127 + 0.0 = 239.9 refuses a 1.1 MiB weight
fix-320 identical to base-320 (0.0 / 72.9 free in 2 blocks / 121.7 wanted)
So: every base arm reports parked > limit and a free list of 4-5 blocks, every fix arm sums to the limit to printed
precision with a free list of 1, the 121.7 MiB weight the base refuses at every budget is admitted, and the arm where
no park is followed by a re-creation (320) is unchanged — which is the check that the change is narrow. base-200
reports 205 parked in all three logs, as claimed.
Two notes, neither a gate:
- The fix arms still refuse — honestly. At a 200 MiB budget the run now stops on a 1.7 MiB weight at 198 MiB
spoken for, not on a fitting 121.7 MiB one. The body's table says this correctly; the headline ("a parked host-weight
slot outlives the arena that parked it") plus "the fix admits that weight" could be read as "the run no longer
refuses", so one clause in the body — "the run then stops on the model's honest budget exhaustion at 198/200" — is
worth the space. - #180 edits the same file. Its diffs are the refusal wording (
arena_reserve's line and the latched message);
this one is a one-line bookkeeping fix in the same function's neighbourhood. Whichever merges second needs a rebase,
and #180's newdescribe()sentence would read better with "parked" now meaning real live parking — no action
needed beyond the ordering note.
The corruption the parked list could cause (an extent taken by two weights) is argued from the take path and not
demonstrated — the PR says so, and the arms do stop one step before it. Fine by me: the observable bug is closed.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
READY.
ggml/src/ggml-hrx/runtime/host-memory.cpp @ pr/182 (fee91177d): rc=0 (one pre-existing -Wunused-but-set-variable at :1559, unrelated)
Read, because five lines that drop state need the lifetime argument to hold: arena_deferred_ is filled while executions_ != 0 (:1531, and :1517 swaps it out in end_execution() when the last execution ends) and its entries are (offset, slot) extents in the current arena. arena_reserve()'s grow path releases the old buffer and re-creates the arena, resetting entries_, last_use_, resident_bytes_, arena_free_, arena_free_bytes_ — so an extent parked against the released arena has no meaning in the new one, and end_execution() would reclaim it into the new free list at an old offset. Clearing it with the arena is the correct pairing, and nothing else needs to be dropped: no lease can name a parked extent, since parking happens only for slots the cache solely owns.
I could not reproduce the arena-recreation sequence itself: that needs a built HRX binary under a gpu-hold ticket, and the PR's own arms (~/amd-oss/hrx-study/evidence/memory/arena-deferred-*.log) are the evidence for the behaviour change. What I verified is the compile and the ownership reasoning the five lines rest on.
Control arm: the fix removes the aliasing, not only the arithmetic (2026-11-04 07:01 AST)Re-ran the issue's smallest reproducer with an offset-level instrument added to both builds (the same tree, the same Qwen3-0.6B,
On the base at 200 MiB: grow #3 re-creates the arena while 92 slots are parked, 10 ms later those extents are reclaimed Two notes for the review, both consistent with what was already posted:
Evidence: |
The follow-up half of engine 1bit-MONSTER/engine#900, and it is not the coalescing the issue suggested: adjacent free
blocks are already merged (reclaim path and the eviction model both do it). The free blocks were genuinely not adjacent —
they were stale. A slot parked for a running execution outlived the arena that parked it.
Root cause
HostWeightCache::arena_reserve()(ggml/src/ggml-hrx/runtime/host-memory.cpp:1683) only evicts-or-refuses whenresident_bytes_ != 0. When every resident weight has been parked intoarena_deferred_, a miss hasresident_bytes_ == 0, so it falls through to the grow path, which re-creates the arena at the budget(
:1718-1720,previous_capacity != 0 → target = budget). The re-creation releases the old buffer and resetsentries_,last_use_,stats_.resident_bytes,resident_bytes_,arena_free_andarena_free_bytes_— but notarena_deferred_.end_execution()(:1517-1522) then reclaims those parked extents into the new free list at their old offsets,where
arena_reclaim_locked()merges them with their new neighbours. The offsets interleave with the live allocation, sothe free list describes blocks that partly overlap live weights. Two visible consequences, both quoted by the issue:
205 MiB parkedagainst a200 MiBlimit — the parked list belongs to an arena that no longer exists;193.2 MiB free in 5 blocksin a 200 MiB arena whose only weight is 121.7 MiB — and therefore a refusal on a weightthat fits.
And one that is not visible:
arena_take_locked()(:1644) hands out the first block that is large enough, so a staleextent big enough to serve would be given to a second weight while the first still holds it. One extent, two weights,
silent corruption — the same class as the waste ggml-org#914 removed, but writing instead of wasting.
Change
Five lines: drop the parked list with the arena that parked it, in the same place that drops everything else that
pointed into the released arena. No lease can reference a parked extent (eviction only takes entries the cache solely
owns,
use_count() == 1), so nothing else needs to move.Measured, base = the pin's own staged binary, one
gpu-holdticket, ~5 s of GPUllama-cli, Qwen3-0.6B-Q4_K_M,-dev HRX0 -ngl 0 -fit off -c 256 --temp 0 -n 4 -no-cnv -v,GGML_HRX_HOST_WEIGHT_TRACE=1, trioHSA_USE_SVM=0 HSA_USERPTR_FOR_PAGED_MEM=0 HRX_ALLOW_NO_SVM=1,GGML_HRX_HOST_WEIGHT_LIMIT_MBas shown. Logs:~/amd-oss/hrx-study/evidence/memory/arena-deferred-20261103-{2024,2124}.log,script
tools/scripts/mem-arena-deferred.sh.128 → 200 → 200)193.2 MiB free in 5 blocks,205 MiB parked233.1 MiB free in 4 blocks,245 MiB parked1.3 MiB free in 1 block,128 MiB parked, 70.0 resident0.0 MiB free in 1 block,127 MiB parked, 112.9 resident72.9 MiB free in 2 blocks,247 MiB parkedRead the two columns together: with the fix the three quantities sum to the arena's limit to printed precision in every
arm, and the base's do not. And the weight that was refused changes: at 200 MiB the base refuses a 121.7 MiB weight
while its own numbers say 193.2 MiB is free; the fix admits that weight and the run then stops on the 0.6B's honest
budget exhaustion (a 1.7 MiB weight at 198 MiB spoken for). The 320 MiB arm is byte-identical base vs fix, which is the
check that the change is narrow — there, no park is followed by a re-creation.
Sweep
GGML_HRX_HOST_WEIGHT_LIMIT_MB= 200/210/220/230/240, base vs fix, one ticket (arena-deferred-20261103-2136.log),same model and command.
resident + parked + freeagainst the limit, and which weight was refused:Every base arm obeys "parked > limit" and none of the fix arms do; the free list goes from 4-5 blocks to 1 in the fix
arms; the 121.7 MiB weight that the base refuses at every budget is admitted by the fix at every budget. Reproducible
across three tickets:
base-200reports205 parkedin all three logs (20:24, 21:24, 21:36) andfix-200reports70.0 resident / 128 parkedin the two that ran it.Not in this PR
The
resident_bytes_ == 0 → re-create the arenaescape hatch stays: with the parked list dropped it is a correctdefragmentation (the old buffer, parked extents included, is released and a fresh one is allocated at the budget), and
that is what lets a run recover from a fully parked arena. Only the bookkeeping that outlived the buffer was wrong.
Not measured
The corruption itself. Provoking it needs a stale extent large enough to be taken for a later weight at a budget where
the run survives — the arms above stop one step before. The extent arithmetic is in the log and the take path is
unchanged code.