GPU: reclaim unmapped host textures under host memory pressure #394

Open
github-bot wants to merge 2 commits from github-bot/gh-394 into main AGit
Owner

@⁠BlackBookOfficial on GitHub · 2026-11-27 21:51 UTC · original
BlackBookOfficial:perf/host-texture-reclaim → main · +125 −11 · 4 files · 2 commits · open

Problem

Host copies of the title's placed textures are cached under the same policy as the card: with VRAM below its line, the existing sweep keeps title-filled copies idle for 600 s. Their backing allocations are system memory, and on a 64 GB host with ~14 GB commit headroom the layer reached 38.9 GB private (12.8 GB of host textures) and kept growing. Empty 64 MB texture-pool blocks are likewise retained (up to 64) while VRAM has room.

Root cause

resource::let_go_idle used only host::vram_keep_below for its idle threshold. The census counted placed, title-filled copies whose title memory was unmapped, but release was still governed by the card's 10-minute rule. Pool retention is governed by pool::room and SPARE_KEPT, again by VRAM only.

Change

  • residency.rs: host-pressure policy from commit/physical headroom: 5 s idle below min(RAM/4, 16 GiB), 1 s below 8 GiB. VICTORY_HOST_TEXTURE_SWEEP=0 restores the old card-only policy.
  • resource.rs::let_go_idle: under that policy only placed copies whose entire title-memory footprint is unmapped (texture::mapped_bytes == 0, two endpoint queries when both ends are uncommitted) are eligible. Existing safeguards are unchanged: title-filled, host never wrote, Arc::strong_count == 1, COM references == 1, no list or descriptor slot. Mapped/hot copies keep the 600 s cache.
  • pool.rs::room: under host pressure keep 2 empty 64 MB blocks instead of 64, returning backing to Windows after the existing rest period.
  • copystat.rs: counters for reclaimed copies and returned pool blocks.

Results (420 s diagnostic run, same start/profile)

Metric baseline this change
private at 420 s 35,970 MB 30,753 MB
private peak 36,642 MB 33,432 MB
host textures 12,775 MB 6,316 MB
pool blocks 10,944 MB 6,080 MB
commit headroom 14,600 MB 19,053 MB
median frame 113.45 ms 111.15 ms
p90 frame 202.3 ms 148.8 ms
median fps 8.8 9.0
device removals 0 0

Net process-private reduction is ~5.2 GB; the cumulative counters (54,322 copies / 9,289 MB; 62 blocks / 3,968 MB) are not net savings. No new GPU/device-removal errors; no FSR prepare failures. Rainbow-texture warnings are pre-existing (144 baseline, 113 here) and are not addressed.

Limitations

Guest-section commit retention is not addressed (XMemFreePhysicalPages removes page-table slices; section backing is released only with the section). Long-session stability beyond 420 s is not established. No FSR, DLSS, shader, or rendering changes.

Rollback

VICTORY_HOST_TEXTURE_SWEEP=0 restores the previous card-only caching and pool spare limit.

Refs #191, #260 (not closing them).

**@⁠BlackBookOfficial** on GitHub · 2026-11-27 21:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/394) `BlackBookOfficial:perf/host-texture-reclaim` → `main` · +125 −11 · 4 files · 2 commits · open ## Problem Host copies of the title's placed textures are cached under the same policy as the card: with VRAM below its line, the existing sweep keeps title-filled copies idle for 600 s. Their backing allocations are system memory, and on a 64 GB host with ~14 GB commit headroom the layer reached 38.9 GB private (12.8 GB of host textures) and kept growing. Empty 64 MB texture-pool blocks are likewise retained (up to 64) while VRAM has room. ## Root cause `resource::let_go_idle` used only `host::vram_keep_below` for its idle threshold. The census counted placed, title-filled copies whose title memory was unmapped, but release was still governed by the card's 10-minute rule. Pool retention is governed by `pool::room` and `SPARE_KEPT`, again by VRAM only. ## Change - `residency.rs`: host-pressure policy from commit/physical headroom: 5 s idle below `min(RAM/4, 16 GiB)`, 1 s below 8 GiB. `VICTORY_HOST_TEXTURE_SWEEP=0` restores the old card-only policy. - `resource.rs::let_go_idle`: under that policy only **placed** copies whose **entire** title-memory footprint is unmapped (`texture::mapped_bytes == 0`, two endpoint queries when both ends are uncommitted) are eligible. Existing safeguards are unchanged: title-filled, host never wrote, `Arc::strong_count == 1`, COM references == 1, no list or descriptor slot. Mapped/hot copies keep the 600 s cache. - `pool.rs::room`: under host pressure keep 2 empty 64 MB blocks instead of 64, returning backing to Windows after the existing rest period. - `copystat.rs`: counters for reclaimed copies and returned pool blocks. ## Results (420 s diagnostic run, same start/profile) | Metric | baseline | this change | |---|---:|---:| | private at 420 s | 35,970 MB | **30,753 MB** | | private peak | 36,642 MB | **33,432 MB** | | host textures | 12,775 MB | **6,316 MB** | | pool blocks | 10,944 MB | **6,080 MB** | | commit headroom | 14,600 MB | **19,053 MB** | | median frame | 113.45 ms | **111.15 ms** | | p90 frame | 202.3 ms | **148.8 ms** | | median fps | 8.8 | **9.0** | | device removals | 0 | **0** | Net process-private reduction is ~5.2 GB; the cumulative counters (54,322 copies / 9,289 MB; 62 blocks / 3,968 MB) are not net savings. No new GPU/device-removal errors; no FSR prepare failures. Rainbow-texture warnings are pre-existing (144 baseline, 113 here) and are not addressed. ## Limitations Guest-section commit retention is not addressed (`XMemFreePhysicalPages` removes page-table slices; section backing is released only with the section). Long-session stability beyond 420 s is not established. No FSR, DLSS, shader, or rendering changes. ## Rollback `VICTORY_HOST_TEXTURE_SWEEP=0` restores the previous card-only caching and pool spare limit. Refs #191, #260 (not closing them).
- Host copies of placed textures whose title memory is entirely unmapped and
  that no list or descriptor slot holds go after 5 s idle when host headroom
  is below min(RAM/4, 16 GiB), and after 1 s below 8 GiB. Mapped, hot copies
  keep the existing 600 s card rule.
- Under the same pressure the texture pools keep two empty 64 MiB blocks
  instead of 64, returning their backing to Windows.
- Existing ownership, COM-reference, host-write, and GPU-lifetime checks are
  unchanged; VICTORY_HOST_TEXTURE_SWEEP=0 restores the old behaviour.
- Diagnostics: counters for reclaimed copies and returned pool blocks.

Measured on a 420 s Series X diag run: private 35,970 -> 30,753 MB,
host textures 12,775 -> 6,316 MB, pool blocks 10,944 -> 6,080 MB,
commit headroom 14,600 -> 19,053 MB, median frame 113.45 -> 111.15 ms.
No device removal; rainbow warnings unchanged in class (pre-existing).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:52:51 +00:00
Author
Owner

@⁠wildheathen on GitHub · 2026-11-27 22:54 UTC · original

Thanks for this. I read the change and built it (diag, cargo test -p victory-gpu: the PR's new test passes; the two indirect::tests failures are the ones main has). I have not run it in the game yet. Three things I found reading it, the first one matters on PCs with 32 GB:

1. Under host pressure the card's rule is switched off, not added to (resource.rs, let_go_idle). When host_texture_idle_ms() returns Some, (idle_ms, most) comes from it alone and the vram_keep_below branch is not taken. Further down, a copy whose title memory is still mapped hits continue ("the card's rule still decides when it may go"), but in this branch no rule looks at it any more. So while the PC is short of memory, mapped textures are never let go, even with VRAM past its line.

On a 32 GB PC the line is min(RAM/4, 16 GiB) = about 7.8 GiB, which is below the 8 GiB of the 1 s tier, so the 5 s tier never applies; and in the world this machine (RTX 5080 16 GB, 32 GB) has about 1.2 GB available, so the host rule would be on for the whole session. I would expect shared GPU memory to go up there, not down. A fix that keeps your idea: run the card's rule as before, and take the unmapped placed copies under the host rule in addition.

2. The mapped check walks the whole texture when it is mapped. The comment says a mapped first page answers at once, but texture::mapped_bytes(..) == 0 queries every block until the end for a mapped texture. With the 1 s rule on, that is every mapped placed texture, every pass, on the submitting thread. An early-out "is any page mapped" would do.

3. Comment vs code: "Portions mapped between the ends make it skip" — with both ends uncommitted the copy is let go without looking in between (mapped_bytes takes the two-query path). Either the comment or the check should change.

For scale on this machine: the census line "host copies of placed textures whose title memory is not mapped any more" says 811 MB at 170 s, so that is the most the copies part could give back here; the 5.2 GB you measured probably needs the longer session and the pool-block part.

Happy to measure a revised version on the 5080 (3-minute diagnostics run, memory line and census).

**@⁠wildheathen** on GitHub · 2026-11-27 22:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/394#issuecomment-7229721482) Thanks for this. I read the change and built it (`diag`, `cargo test -p victory-gpu`: the PR's new test passes; the two `indirect::tests` failures are the ones `main` has). I have not run it in the game yet. Three things I found reading it, the first one matters on PCs with 32 GB: **1. Under host pressure the card's rule is switched off, not added to** (`resource.rs`, `let_go_idle`). When `host_texture_idle_ms()` returns `Some`, `(idle_ms, most)` comes from it alone and the `vram_keep_below` branch is not taken. Further down, a copy whose title memory is still mapped hits `continue` ("the card's rule still decides when it may go"), but in this branch no rule looks at it any more. So while the PC is short of memory, mapped textures are never let go, even with VRAM past its line. On a 32 GB PC the line is `min(RAM/4, 16 GiB)` = about 7.8 GiB, which is below the 8 GiB of the 1 s tier, so the 5 s tier never applies; and in the world this machine (RTX 5080 16 GB, 32 GB) has about 1.2 GB available, so the host rule would be on for the whole session. I would expect shared GPU memory to go up there, not down. A fix that keeps your idea: run the card's rule as before, and take the unmapped placed copies under the host rule in addition. **2. The mapped check walks the whole texture when it is mapped.** The comment says a mapped first page answers at once, but `texture::mapped_bytes(..) == 0` queries every block until the end for a mapped texture. With the 1 s rule on, that is every mapped placed texture, every pass, on the submitting thread. An early-out "is any page mapped" would do. **3. Comment vs code:** "Portions mapped between the ends make it skip" — with both ends uncommitted the copy is let go without looking in between (`mapped_bytes` takes the two-query path). Either the comment or the check should change. For scale on this machine: the census line "host copies of placed textures whose title memory is not mapped any more" says 811 MB at 170 s, so that is the most the copies part could give back here; the 5.2 GB you measured probably needs the longer session and the pool-block part. Happy to measure a revised version on the 5080 (3-minute diagnostics run, memory line and census).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/394/head:github-bot/gh-394'
git switch 'github-bot/gh-394'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-394'
git switch 'github-bot/gh-394'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-394'
git switch 'github-bot/gh-394'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-394'
git switch 'main'
git merge --squash 'github-bot/gh-394'
git switch 'main'
git merge --ff-only 'github-bot/gh-394'
git switch 'main'
git merge 'github-bot/gh-394'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.