GPU: align VRAM eviction, PC promotion, and hole packing with VICTORY_ROOM_REAL #276

Closed
github-bot wants to merge 0 commits from github-bot/gh-276 into main AGit
Owner

@⁠leixner on GitHub · 2026-12-01 08:34 UTC · original
leixner:fix/vram-real-eviction-and-promotion → main · +18 −1 · 1 files · 68 commits · closed without merging

Summary

Aligns texture VRAM eviction (let_go_idle), PC-to-VRAM promotion (back_to_card), and VRAM hole-filling (texture_in_holes) with VICTORY_ROOM_REAL (on by default since 2026-11-29). Addresses the long-session VRAM saturation and PC-memory spill loop reported in #214, #222, #227, and #212.

1. Eviction stalled by fragmented pool holes (crates/victory-gpu/src/resource.rs)

  • room() refuses new VRAM allocations once real used + REAL_MARGIN > budget (VICTORY_ROOM_REAL), even when fragmented free space sits inside 64 MiB texture blocks.
  • Previously, let_go_idle() only evaluated vram_keep_below() against credited usage (used - pool::texture_room() + kept). When 1–4 GiB was fragmented inside texture blocks and real VRAM reached or exceeded budget, credited usage looked comfortably below room_line, causing let_go_idle() to return KEPT_MS (10 minutes) and stall eviction while VRAM stayed pinned over budget.
  • Added sweep_budget() so let_go_idle() takes the stricter of credited VRAM pressure and (when VICTORY_ROOM_REAL is enabled) real used against budget - REAL_MARGIN.

2. PC-to-VRAM promotion thrashing (crates/victory-gpu/src/resource.rs)

  • back_to_card() also evaluated only credited usage, so when VICTORY_ROOM_REAL was refusing VRAM allocations due to fragmented blocks, back_to_card() kept evicting up to 64 MiB/s of PC_TEXTURES that immediately spilled back into PC memory on the next draw.
  • Added back_room_with_real() to bound promotion by real VRAM headroom (budget - REAL_MARGIN - real_used) when VICTORY_ROOM_REAL is enabled.

3. Hole-filling packing & growth-backoff poisoning (crates/victory-gpu/src/pool.rs)

  • When VRAM is full and texture_in_holes() (grow = false) places textures into existing block holes, it now packs into the fullest ripe block (pack_fullest = true) so nearly-empty blocks are left to drain back to D3D12 rather than being re-populated by first-fit.
  • Prevented allow_grow = false from calling Pool::grow() (both on miss and during ripe-ahead replenishment), which previously triggered the 500 ms retry_growth_at backoff on TEXTURES.

Verification

  • cargo test -p victory-gpu --lib resource: 23 passed (including new sweep_budget_evicts_when_real_vram_exceeds_budget_despite_fragmented_blocks and promotion_room_stops_when_real_vram_at_budget)
  • cargo test -p victory-gpu --lib pool: 16 passed (including new hole_packing_prefers_fullest_block_and_does_not_poison_growth_backoff)
  • cargo xtask policy: 293 files ok

Real-world test (RTX 3070 8 GB, Ryzen 7 5700X, 32 GB RAM, Windows 11, Series X @ 1440p, DLSS Performance + FSR 3 FG)

  • Full ~9-minute prologue run (511 gameplay seconds): 0 crashes, 0 OOMs, 0 out of VRAM warnings, 0 ERROR lines.
  • When real VRAM briefly peaked at 7,458 / 6,936 MB with 1,234 MB free inside blocks (VICTORY_ROOM_REAL triggered once), let_go_idle() immediately evicted idle textures (held dropped from 2,491 MB to 1,594 MB), back_to_card() did not thrash PC textures, and all 9,120 / 9,120 subsequent textures landed in VRAM block holes with 0 new PC-memory spills.
  • Overall hole-hit rate improved from 59.4% (baseline) to 78.9%, with average longest contiguous free range per block increasing from 616 KB to 3,620 KB.
**@⁠leixner** on GitHub · 2026-12-01 08:34 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276) `leixner:fix/vram-real-eviction-and-promotion` → `main` · +18 −1 · 1 files · 68 commits · closed without merging ## Summary Aligns texture VRAM eviction (`let_go_idle`), PC-to-VRAM promotion (`back_to_card`), and VRAM hole-filling (`texture_in_holes`) with `VICTORY_ROOM_REAL` (on by default since 2026-11-29). Addresses the long-session VRAM saturation and PC-memory spill loop reported in #214, #222, #227, and #212. ### 1. Eviction stalled by fragmented pool holes (`crates/victory-gpu/src/resource.rs`) - `room()` refuses new VRAM allocations once real `used + REAL_MARGIN > budget` (`VICTORY_ROOM_REAL`), even when fragmented free space sits inside 64 MiB texture blocks. - Previously, `let_go_idle()` only evaluated `vram_keep_below()` against credited usage (`used - pool::texture_room() + kept`). When 1–4 GiB was fragmented inside texture blocks and real VRAM reached or exceeded `budget`, credited usage looked comfortably below `room_line`, causing `let_go_idle()` to return `KEPT_MS` (10 minutes) and stall eviction while VRAM stayed pinned over budget. - Added `sweep_budget()` so `let_go_idle()` takes the stricter of credited VRAM pressure and (when `VICTORY_ROOM_REAL` is enabled) real `used` against `budget - REAL_MARGIN`. ### 2. PC-to-VRAM promotion thrashing (`crates/victory-gpu/src/resource.rs`) - `back_to_card()` also evaluated only credited usage, so when `VICTORY_ROOM_REAL` was refusing VRAM allocations due to fragmented blocks, `back_to_card()` kept evicting up to 64 MiB/s of `PC_TEXTURES` that immediately spilled back into PC memory on the next draw. - Added `back_room_with_real()` to bound promotion by real VRAM headroom (`budget - REAL_MARGIN - real_used`) when `VICTORY_ROOM_REAL` is enabled. ### 3. Hole-filling packing & growth-backoff poisoning (`crates/victory-gpu/src/pool.rs`) - When VRAM is full and `texture_in_holes()` (`grow = false`) places textures into existing block holes, it now packs into the fullest ripe block (`pack_fullest = true`) so nearly-empty blocks are left to drain back to D3D12 rather than being re-populated by first-fit. - Prevented `allow_grow = false` from calling `Pool::grow()` (both on miss and during ripe-ahead replenishment), which previously triggered the 500 ms `retry_growth_at` backoff on `TEXTURES`. ## Verification - `cargo test -p victory-gpu --lib resource`: 23 passed (including new `sweep_budget_evicts_when_real_vram_exceeds_budget_despite_fragmented_blocks` and `promotion_room_stops_when_real_vram_at_budget`) - `cargo test -p victory-gpu --lib pool`: 16 passed (including new `hole_packing_prefers_fullest_block_and_does_not_poison_growth_backoff`) - `cargo xtask policy`: 293 files ok ### Real-world test (RTX 3070 8 GB, Ryzen 7 5700X, 32 GB RAM, Windows 11, Series X @ 1440p, DLSS Performance + FSR 3 FG) - Full ~9-minute prologue run (511 gameplay seconds): **0 crashes, 0 OOMs, 0 `out of VRAM` warnings, 0 `ERROR` lines**. - When real VRAM briefly peaked at `7,458 / 6,936 MB` with `1,234 MB` free inside blocks (`VICTORY_ROOM_REAL` triggered once), `let_go_idle()` immediately evicted idle textures (`held` dropped from `2,491 MB` to `1,594 MB`), `back_to_card()` did not thrash PC textures, and all **9,120 / 9,120** subsequent textures landed in VRAM block holes with **0** new PC-memory spills. - Overall hole-hit rate improved from **59.4%** (baseline) to **78.9%**, with average longest contiguous free range per block increasing from **616 KB** to **3,620 KB**.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 08:36:54 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 08:48 UTC · original

Ran the resource and pool test groups at 8ea1a40 on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q -p victory-gpu --lib resource -- --test-threads=1
23 passed; 0 failed; 0 ignored; 491 filtered out      (exit 0)

cargo test -q -p victory-gpu --lib pool -- --test-threads=1
16 passed; 0 failed; 0 ignored; 498 filtered out      (exit 0)

Both counts match the description's groups, including sweep_budget_evicts_when_real_vram_exceeds_budget_despite_fragmented_blocks, promotion_room_stops_when_real_vram_at_budget and hole_packing_prefers_fullest_block_and_does_not_poison_growth_backoff. This adapter has 16 GB of VRAM, but the long-session 8 GB spill described in the PR was not reproduced here.

Not tested: the full workspace suite, a title run, an 8 GB card, a long session with fragmented texture blocks, AMD adapters, Wine, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 08:48 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#issuecomment-7305819144) Ran the `resource` and `pool` test groups at `8ea1a40` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q -p victory-gpu --lib resource -- --test-threads=1 23 passed; 0 failed; 0 ignored; 491 filtered out (exit 0) cargo test -q -p victory-gpu --lib pool -- --test-threads=1 16 passed; 0 failed; 0 ignored; 498 filtered out (exit 0) ``` Both counts match the description's groups, including `sweep_budget_evicts_when_real_vram_exceeds_budget_despite_fragmented_blocks`, `promotion_room_stops_when_real_vram_at_budget` and `hole_packing_prefers_fullest_block_and_does_not_poison_growth_backoff`. This adapter has 16 GB of VRAM, but the long-session 8 GB spill described in the PR was not reproduced here. Not tested: the full workspace suite, a title run, an 8 GB card, a long session with fragmented texture blocks, AMD adapters, Wine, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠bannnned on GitHub · 2026-12-01 08:55 UTC · original · reviewed

I found two cases where the new memory limits can be spent on copies that do not fit the intent of the pass.

**@⁠bannnned** on GitHub · 2026-12-01 08:55 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#pullrequestreview-6127924817) · **reviewed** I found two cases where the new memory limits can be spent on copies that do not fit the intent of the pass.
@ -2403,3 +2406,1 @@
+ targets_room_kept();
crate::host::vram_keep_below(budget, used, room_line(budget))
}
Some([budget, used, ..]) if keep => sweep_budget(
Author
Owner

@⁠bannnned on GitHub · 2026-12-01 08:55 UTC · original

[P2] Count only local-memory copies toward the DXGI pressure sweep

When the new real-VRAM check tightens the sweep, the age-sorted candidates can still include PC-heap textures. The loop adds their full host.bytes to bytes and can stop at most before reaching any VRAM-backed copy. If the oldest eligible copies are in PC heaps, the sweep can leave local DXGI usage unchanged and make those textures upload again on their next use. Could we filter or account for candidates by heap placement when applying the local-memory quota?

**@⁠bannnned** on GitHub · 2026-12-01 08:55 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#discussion_r4751475166) **[P2] Count only local-memory copies toward the DXGI pressure sweep** When the new real-VRAM check tightens the sweep, the age-sorted candidates can still include PC-heap textures. The loop adds their full `host.bytes` to `bytes` and can stop at `most` before reaching any VRAM-backed copy. If the oldest eligible copies are in PC heaps, the sweep can leave local DXGI usage unchanged and make those textures upload again on their next use. Could we filter or account for candidates by heap placement when applying the local-memory quota?
@ -2536,2 +2546,2 @@
let used = used.saturating_sub(crate::pool::texture_room()) + crate::shadow::card_room_kept() + targets_room_kept();
let room = back_room(room_line(budget), used);
let credited = used.saturating_sub(crate::pool::texture_room()) + crate::shadow::card_room_kept() + targets_room_kept();
let room = back_room_with_real(room_line(budget), credited, budget, used, room_real());
Author
Owner

@⁠bannnned on GitHub · 2026-12-01 08:55 UTC · original

[P3] Check the next copy against the remaining promotion allowance

If real headroom clamps this pass to 20 MiB and the first eligible PC copy is 32 MiB, the existing check still lets it go because it compares only the bytes already dropped. The cap can be exceeded by the last selected copy, and a later use may have to recreate it in PC memory. Could we skip candidates larger than the remaining allowance before unstaging them?

**@⁠bannnned** on GitHub · 2026-12-01 08:55 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#discussion_r4751475172) **[P3] Check the next copy against the remaining promotion allowance** If real headroom clamps this pass to 20 MiB and the first eligible PC copy is 32 MiB, the existing check still lets it go because it compares only the bytes already dropped. The cap can be exceeded by the last selected copy, and a later use may have to recreate it in PC memory. Could we skip candidates larger than the remaining allowance before unstaging them?
Author
Owner

@⁠leixner on GitHub · 2026-12-01 08:57 UTC · original

Thanks for the sharp review @⁠bannnned! Addressed both in 1ada65c:

  1. Bounded VRAM sweep (let_go_idle): When most != u64::MAX, skip PC-heap textures (!in_pc_heap(&host.texture)) so local-VRAM pressure sweeps only evict and count local-memory copies toward most.
  2. Promotion allowance (ack_to_card): Added its_promotion(bytes, host.bytes, room) so candidates larger than the remaining pass allowance are skipped (kept in IN_PC_LIST) instead of overshooting the cap.

Re-verified cargo test -p victory-gpu --lib resource (23 passed) and cargo xtask policy (293 files ok).

**@⁠leixner** on GitHub · 2026-12-01 08:57 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#issuecomment-7306019478) Thanks for the sharp review @⁠bannnned! Addressed both in 1ada65c: 1. **Bounded VRAM sweep (let_go_idle)**: When most != u64::MAX, skip PC-heap textures (!in_pc_heap(&host.texture)) so local-VRAM pressure sweeps only evict and count local-memory copies toward most. 2. **Promotion allowance (ack_to_card)**: Added its_promotion(bytes, host.bytes, room) so candidates larger than the remaining pass allowance are skipped (kept in IN_PC_LIST) instead of overshooting the cap. Re-verified cargo test -p victory-gpu --lib resource (23 passed) and cargo xtask policy (293 files ok).
Author
Owner

@⁠bannnned on GitHub · 2026-12-01 09:37 UTC · original

Manual A/B on an RTX 5070 Ti (16 GiB), Ryzen 7 5700X3D, and 32 GiB RAM. I used Series X at native 2560×1440, frame generation off, and VICTORY_ROOM_REAL=1. A was 297f58a (base) and B was 8ea1a40 (PR). All four runs exited cleanly and predate the follow-up in 1ada65c.

  • Default budget, A → B: 16.0 → 16.2 FPS. Frames over 100 ms went from 9.2% to 7.5%.
  • 14,000 MiB internal budget, A → B: 14.9 → 14.3 FPS. Frames over 100 ms went from 13.1% to 15.9%. Failed attempts to place textures in existing VRAM holes went from 614/3,476 (17.7%) to 117/2,608 (4.5%). Both builds also created textures in PC memory.

Frame timing uses equal-length post-load windows within each pair (180 s at the default budget and 150 s with the cap). One manual pass per build gives mixed frame-time results. The capped run showed a lower VRAM hole miss rate on B.

With the cap, minimum sampled headroom was 440 MiB on A and 429 MiB on B. Four B samples met the new sweep's earlier pressure threshold. The logs do not identify the heap placement of each swept copy, and the sampled headroom stayed above the range where the new promotion cap would reduce the 64 MiB allowance. These runs give gameplay coverage for 8ea1a40. The two review edge cases still need a targeted check on the follow-up.

**@⁠bannnned** on GitHub · 2026-12-01 09:37 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#issuecomment-7306959301) Manual A/B on an RTX 5070 Ti (16 GiB), Ryzen 7 5700X3D, and 32 GiB RAM. I used Series X at native 2560×1440, frame generation off, and `VICTORY_ROOM_REAL=1`. A was `297f58a` (base) and B was `8ea1a40` (PR). All four runs exited cleanly and predate the follow-up in `1ada65c`. - **Default budget, A → B:** 16.0 → 16.2 FPS. Frames over 100 ms went from 9.2% to 7.5%. - **14,000 MiB internal budget, A → B:** 14.9 → 14.3 FPS. Frames over 100 ms went from 13.1% to 15.9%. Failed attempts to place textures in existing VRAM holes went from 614/3,476 (17.7%) to 117/2,608 (4.5%). Both builds also created textures in PC memory. Frame timing uses equal-length post-load windows within each pair (180 s at the default budget and 150 s with the cap). One manual pass per build gives mixed frame-time results. The capped run showed a lower VRAM hole miss rate on B. With the cap, minimum sampled headroom was 440 MiB on A and 429 MiB on B. Four B samples met the new sweep's earlier pressure threshold. The logs do not identify the heap placement of each swept copy, and the sampled headroom stayed above the range where the new promotion cap would reduce the 64 MiB allowance. These runs give gameplay coverage for `8ea1a40`. The two review edge cases still need a targeted check on the follow-up.
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 09:38 UTC · original

This is a new response on the same thread as my report at 8ea1a40 (#276); the head moved to 1ada65cf (the bounded-sweep / promotion-room correction), so I am not editing that comment.

Ran the resource and pool test groups at 1ada65cf on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q -p victory-gpu --lib resource -- --test-threads=1
23 passed; 0 failed; 0 ignored; 491 filtered out      (exit 0)

cargo test -q -p victory-gpu --lib pool -- --test-threads=1
16 passed; 0 failed; 0 ignored; 498 filtered out      (exit 0)

Both groups still pass at the new head, with the same counts as at 8ea1a40. I did not repeat the manual A/B on the card.

Not tested: the full workspace suite, a title run, a long session with fragmented texture blocks, an 8 GB card, AMD adapters, Wine, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 09:38 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#issuecomment-7306996732) This is a new response on the same thread as my report at `8ea1a40` (https://git.gtahub.st/github/readmet3xt-lab--foxhound/pulls/276); the head moved to `1ada65cf` (the bounded-sweep / promotion-room correction), so I am not editing that comment. Ran the `resource` and `pool` test groups at `1ada65cf` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q -p victory-gpu --lib resource -- --test-threads=1 23 passed; 0 failed; 0 ignored; 491 filtered out (exit 0) cargo test -q -p victory-gpu --lib pool -- --test-threads=1 16 passed; 0 failed; 0 ignored; 498 filtered out (exit 0) ``` Both groups still pass at the new head, with the same counts as at `8ea1a40`. I did not repeat the manual A/B on the card. Not tested: the full workspace suite, a title run, a long session with fragmented texture blocks, an 8 GB card, AMD adapters, Wine, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 11:38 UTC · original

Checked: nothing harmful in it, it merges and passes the lint check. Because it changes a run at default settings (or code on the submission path), it is not merged to main directly: it is on the batch being tested for the next release, as one commit with you as its author. Nothing is needed from you now; the result of the run will be posted here.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 11:38 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/276#issuecomment-7309922272) Checked: nothing harmful in it, it merges and passes the lint check. Because it changes a run at default settings (or code on the submission path), it is not merged to main directly: it is on the batch being tested for the next release, as one commit with you as its author. Nothing is needed from you now; the result of the run will be posted here.
github-bot closed this pull request 2026-12-02 07:54:54 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.