Skip to content

[Engine] AMD on WSL2: remove a 4 s stall when the cache shrinks - #302

Open
okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/wsl-no-remap
Open

okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/wsl-no-remap

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem and result

When strata-poly gives VRAM back (a long prompt takes buffers from the expert cache, the attention caches shrink, or
POST /v1/vram is called), native Linux ROCm only returns a released VMM piece's VRAM once its addresses are freed. So
the engine unmaps every piece it keeps, frees the whole address reservation, reserves it again at the same place and
maps the kept pieces again.

Under WSL2 (librocdxg) the VRAM comes back as soon as the piece is released, so that cycle only costs time: the first
8K prompt of a fresh engine on an RX 9070 XT spent 4.2 s in hipMemUnmap. With this PR, the kept pieces stay mapped
under WSL2; native amdgpu keeps the cycle.

The first 8K prompt of a fresh engine now takes 11.9 s instead of 35.5 s, and the second one gets 4% faster.

RX 9070 XT class card (gfx1201, Salad cloud container, WSL2, ROCm 7.2.4), Inkling 2 Mini IQ4_NL, default arguments,
--max-context 16384, no prompt or conversation cache. A fresh process processes the same 8,192-token prompt three
times. Prompt time in ms (lower is better), mean of 3 fresh processes per side, main and PR interleaved:

Card Model Measure main this PR alone Change
gfx1201 16 GB (WSL2) Inkling 2 Mini IQ4_NL 1st 8K prompt (ms) 35,463 11,905 -66.4%
gfx1201 16 GB (WSL2) Inkling 2 Mini IQ4_NL 2nd 8K prompt (ms) 10,021 9,609 -4.1%

Related discussion

none

Approach

  • WSL2 is detected as before for the equal-piece rule: /dev/dxg present and /dev/kfd absent (now one shared helper).
  • Under WSL2, vmm_unmap() releases the pieces past the cut point, waits (100 ms at most) for the free-VRAM figure to
    rise as the native path does, and returns. A mapping given back whole still gets fresh addresses: nothing is kept, so
    that costs nothing, and librocdxg refuses a smaller piece after a larger one in one reservation.
  • If the VRAM does not come back within the wait, the engine logs it and uses the full cycle from then on.
  • STRATA_VMM_READDRESS=1 keeps the cycle under WSL2; =0 skips it anywhere (a test switch, with a warning outside WSL2).
  • Same bits: the same pieces at the same addresses. CUDA, Windows HIP and native Linux HIP are unchanged.
Each run (ms)
Card Model Measure Build Run 1 Run 2 Run 3
gfx1201 (WSL2) Inkling 2 Mini IQ4_NL 1st 8K prompt (ms) main 39,404 34,397 32,589
gfx1201 (WSL2) Inkling 2 Mini IQ4_NL 1st 8K prompt (ms) this PR 12,192 11,823 11,701
gfx1201 (WSL2) Inkling 2 Mini IQ4_NL 2nd 8K prompt (ms) main 10,196 9,953 9,914
gfx1201 (WSL2) Inkling 2 Mini IQ4_NL 2nd 8K prompt (ms) this PR 9,762 9,458 9,608
gfx1201 (WSL2) Inkling 2 Mini IQ4_NL 3rd 8K prompt (ms) main 9,438 9,736 9,774
gfx1201 (WSL2) Inkling 2 Mini IQ4_NL 3rd 8K prompt (ms) this PR 9,634 9,429 9,499
  • Experts in VRAM at load: 2,388 of 3,072 in every run, except main's run 1 (2,154; the first start after the model
    download). Without that run, main's mean first prompt is still 33,493 ms.
  • No "did not come back" fallback line and no "no VRAM for" line in any run of either side.
  • A first, interrupted attempt on another instance (the container was reallocated) showed the same: main 29,352 ms,
    this PR 7,919 ms for the first prompt.

Merge note (with #319, --vram-elastic): both PRs add a check to vmm_unmap() for VRAM that comes back at the
release. They conflict there. Whichever lands second keeps this PR's check (vmm_release_frees(), every map) first and
#319's one-time measure (readdress, the expert cache with the flag) after it. free0 is read when either check needs it.

Validation

Passed:

  • Settings register: STRATA_VMM_READDRESS is registered as a rollback (the name [Engine] Inkling 2: give expert-cache VRAM back while serving #319 now reads too). python3 tools/settings_register.py --check and tools/test_settings_register.py: OK at this commit. No engine code changed in this commit.
  • Builds: HIP (gfx1200;gfx1201) and CUDA (sm_75) of strata-poly.
  • The timing above (test kit kit.sh on the RX 9070 XT container: main = simplex/main 36e654b, this PR = port/wsl-no-remap c1fb2f7).
  • Frozen identity, STRATA_FREEZE_EXPERTS=1, 8K prompt, 64 tokens, three requests per process, main vs this branch:
    SAME, SAME, SAME.

Failed:

  • none observed

Not run:

  • Native Linux amdgpu (unchanged code path; no such card here).

Limits

  • The 2.6 s hipMalloc that the profile also showed is the settle probe waiting for that remap; with this change it drops to about 20 ms (RX 9070 XT, WSL2). An 8K IQ4_NL prompt in a fresh process measured 711.9 → 1,200.6 tok/s (+68.6%), the same speed as 2K; 32K 949.8 → 1,090.9 (+14.9%); 2K unchanged (median of 3, one process per run).
  • Load times on this 23 GB RAM container moved between 11 and 90 s on both sides with the page cache; they are not part
    of the measure.

🤖 Generated with Claude Code

ROCm on native Linux gives a released VMM handle's VRAM back only when its
addresses are freed, so Engine::vmm_unmap() unmaps every kept piece, frees the
reservation, reserves it again at the same place and maps the kept pieces
again (STRATA_VMM_RELEASE_WITH_ADDRESSES). Under WSL2 (librocdxg: /dev/dxg
without /dev/kfd) the VRAM comes back at the release itself: a 64 MiB handle
unmapped and released came back whole, measured on an RX 9060 XT and an
RX 9070 XT class card (ROCm 7.2.4). There the cycle only costs time: it was
the 4.2 s hipMemUnmap in the first 8K prompt read of a fresh process.

So under WSL2 vmm_unmap() releases the pieces past `bytes` and waits (100 ms
at most) for the free figure, as the native path does after its cycle, and
leaves the kept pieces mapped. Native amdgpu keeps the cycle;
STRATA_VMM_READDRESS=1 keeps it under WSL2 too. Same bits: the same pieces at
the same addresses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo okada-shogo changed the title [Engine] strata-poly on AMD under WSL2: no remap of the kept VRAM when giving some back [Fix] AMD under WSL2: don't remap the kept VRAM when the expert cache shrinks (removes a 4 s stall) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Fix] AMD under WSL2: don't remap the kept VRAM when the expert cache shrinks (removes a 4 s stall) [Engine] AMD under WSL2: don't remap the kept VRAM when the expert cache shrinks (removes a 4 s stall) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] AMD under WSL2: don't remap the kept VRAM when the expert cache shrinks (removes a 4 s stall) [Engine] AMD on WSL2: remove a 4 s stall when the cache shrinks Nov 24, 2026
Registered as a rollback with its defaults (WSL2 skips the cycle, native Linux keeps it).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant