Host memory: empty the working set while free RAM is under VICTORY_RAM_TRIM_MB #3749

Closed
github-bot wants to merge 3 commits from github-bot/gh-3749 into main AGit
Owner

@⁠Mikey970 on GitHub · 2026-11-30 05:56 UTC · original
Mikey970:pr/ram-trim → main · +186 −2 · 2 files · 3 commits · closed without merging

Title: [pr-performance] Host memory: empty the working set while free RAM is under VICTORY_RAM_TRIM_MB

Fixes #

What it changes

Today the process's working set goes back to Windows only on a hard flush (F7, empty_working_set in resource.rs), which someone has to press. When the PC runs low on free physical memory, nothing gives it back on its own. Most of the working set is title memory (sections backed by the page file) whose texture pages are cold once they have been uploaded.

This adds a thread of its own, victory-ram-trim, started once by the once-a-second sweep (host.rs, beside residency::refresh):

  • It samples free physical memory every 250 ms while free memory is under twice the line, and every second otherwise.
  • Opt-in: it runs only when VICTORY_RAM_TRIM_MB is set (unset or 0: off, the default; the runs below used 2560). While free memory is under that line it calls K32EmptyWorkingSet on our own process, at most once every VICTORY_RAM_TRIM_EVERY_S seconds (default 8).
  • Back-off: a trim that frees less than 256 MiB doubles the wait before the next one, up to 2 minutes; a trim that frees more resets it to VICTORY_RAM_TRIM_EVERY_S. Without this, a PC whose free memory stays under the line (a 16 GB one) would trim every 8 s for the whole run.
  • Hard minimum: a due trim is skipped while Windows reports a hard minimum working set (VICTORY_KEEP_RAM_GB, QUOTA_LIMITS_HARDWS_MIN_ENABLE), and resumes if it is released (#2638). Commit 847e683 by @⁠tyr0nsur.
  • Each trim logs free memory and the working set before the call and 200 ms after it (working set trimmed (VICTORY_RAM_TRIM_MB): …).
  • The memory now: line, written once a second, now ends with working-set trims N.

Costs: K32EmptyWorkingSet takes every pageable page of the process, including the CPU-visible pages of D3D12 upload and readback heaps. Dirty pages are written to the page file, and pages still in use fault back in on whichever thread touches them next, the submitting thread included. tyr0nsur measured 0 → 32,768 faults (0.34 → 24.5 ms) re-reading a hot 128 MiB after a trim. That is why it is opt-in and backs off. The trim call itself runs on its own thread. The thread does not start in unit tests. The switch logic has unit tests: trims_come_under_the_line_and_not_too_often and trims_that_gain_little_back_off.

How it was tested

  • In game on this branch's base (main 41adb551 + this change), same PC and route:

    • Without it (plain main, same settings): the run reached world entry and free physical RAM fell from 4.4 GB to 72 MB within two seconds (working set 19.9 GB, system commit 49 GB); the bench's 1 GiB free-RAM guard stopped it at about 48 s. A cold-cache run of plain main got through with 1,006 MiB free at its lowest.
    • With it: one trim at world entry, working set trimmed (VICTORY_RAM_TRIM_MB): … trims=1 ok=true free_before_mib=2437 free_after_mib=5303 working_set_before_mib=18366 working_set_after_mib=299; the whole 375 s route completed with 2,438 MiB free at the lowest and no errors.
    • Build: main at 41adb551 with this change, release, RTX 4080 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Series X profile, DLSS Performance through Streamline (1080p rendered, 3840x2160 output), ray tracing off, frame generation off, warm pipeline cache from an earlier run, the 375 s Chapter 1 route (interrogation, therapist, flyover, boat, shore) driven by VICTORY_KEYS.
  • GPU and profile: RTX 4080, 32 GB RAM, Series X profile, 1080p rendered to 4K with DLSS. Measured on our fork's build (Mikey970/VIctory-NVIDIA), which had the same change.

  • Before: in two runs of the Chapter 1 flyover, the PC ran out of free RAM (under 1 GiB) at 153–166 s. Each run was stopped by our RAM guard.

  • After: every later run of the 375 s route finished. For example, runs R20, R26 and R41 kept 2.3–3.4 GB free at their lowest point and did 3–13 trims per run (working-set trims N).

  • For shader changes, the wave sizes tested: n/a

  • cargo test passed for the crates it touches: yes. cargo test -p victory-gpu --lib residency gave 9 passed. Clippy for victory-gpu (--all-targets, and again with --all-features) added no new warnings. Pristine main already fails -D warnings: victory-shader has 3 errors (unused imports in emit/lower, while_immutable_condition in analysis.rs), and victory-gpu has 25 pre-existing warnings. None of them are in the lines this PR touches. cargo xtask policy --staged passed.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2638, #2671, #2234, #3584
    • #2638 changes the hard minimum of SetProcessWorkingSetSizeEx (the kept-RAM lock). It does not empty the set.
    • #2671, #2234 and #3381 trim our own spare pools (upload buffers, snapshot buffers, chunks) under pressure. They do not touch the process working set.
    • #3584 makes the free-RAM pressure lines configurable.
    • None of them calls EmptyWorkingSet outside the manual F7 flush. This PR complements them.

🤖 Generated with Claude Code

**@⁠Mikey970** on GitHub · 2026-11-30 05:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749) `Mikey970:pr/ram-trim` → `main` · +186 −2 · 2 files · 3 commits · closed without merging **Title:** [pr-performance] Host memory: empty the working set while free RAM is under VICTORY_RAM_TRIM_MB Fixes # ## What it changes Today the process's working set goes back to Windows only on a hard flush (F7, `empty_working_set` in `resource.rs`), which someone has to press. When the PC runs low on free physical memory, nothing gives it back on its own. Most of the working set is title memory (sections backed by the page file) whose texture pages are cold once they have been uploaded. This adds a thread of its own, `victory-ram-trim`, started once by the once-a-second sweep (`host.rs`, beside `residency::refresh`): - It samples free physical memory every 250 ms while free memory is under twice the line, and every second otherwise. - **Opt-in:** it runs only when `VICTORY_RAM_TRIM_MB` is set (unset or `0`: off, the default; the runs below used `2560`). While free memory is under that line it calls `K32EmptyWorkingSet` on our own process, at most once every `VICTORY_RAM_TRIM_EVERY_S` seconds (default 8). - **Back-off:** a trim that frees less than 256 MiB doubles the wait before the next one, up to 2 minutes; a trim that frees more resets it to `VICTORY_RAM_TRIM_EVERY_S`. Without this, a PC whose free memory stays under the line (a 16 GB one) would trim every 8 s for the whole run. - **Hard minimum:** a due trim is skipped while Windows reports a hard minimum working set (`VICTORY_KEEP_RAM_GB`, `QUOTA_LIMITS_HARDWS_MIN_ENABLE`), and resumes if it is released (#2638). Commit `847e683` by @⁠tyr0nsur. - Each trim logs free memory and the working set before the call and 200 ms after it (`working set trimmed (VICTORY_RAM_TRIM_MB): …`). - The `memory now:` line, written once a second, now ends with `working-set trims N`. Costs: `K32EmptyWorkingSet` takes every pageable page of the process, including the CPU-visible pages of D3D12 upload and readback heaps. Dirty pages are written to the page file, and pages still in use fault back in on whichever thread touches them next, the submitting thread included. tyr0nsur measured 0 → 32,768 faults (0.34 → 24.5 ms) re-reading a hot 128 MiB after a trim. That is why it is opt-in and backs off. The trim call itself runs on its own thread. The thread does not start in unit tests. The switch logic has unit tests: `trims_come_under_the_line_and_not_too_often` and `trims_that_gain_little_back_off`. ## How it was tested - **In game on this branch's base (`main` 41adb551 + this change), same PC and route:** - Without it (plain `main`, same settings): the run reached world entry and free physical RAM fell from 4.4 GB to 72 MB within two seconds (working set 19.9 GB, system commit 49 GB); the bench's 1 GiB free-RAM guard stopped it at about 48 s. A cold-cache run of plain `main` got through with 1,006 MiB free at its lowest. - With it: one trim at world entry, `working set trimmed (VICTORY_RAM_TRIM_MB): … trims=1 ok=true free_before_mib=2437 free_after_mib=5303 working_set_before_mib=18366 working_set_after_mib=299`; the whole 375 s route completed with 2,438 MiB free at the lowest and no errors. - Build: `main` at 41adb551 with this change, release, RTX 4080 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Series X profile, DLSS Performance through Streamline (1080p rendered, 3840x2160 output), ray tracing off, frame generation off, warm pipeline cache from an earlier run, the 375 s Chapter 1 route (interrogation, therapist, flyover, boat, shore) driven by `VICTORY_KEYS`. - GPU and profile: RTX 4080, 32 GB RAM, Series X profile, 1080p rendered to 4K with DLSS. **Measured on our fork's build** (Mikey970/VIctory-NVIDIA), which had the same change. - Before: in two runs of the Chapter 1 flyover, the PC ran out of free RAM (under 1 GiB) at 153–166 s. Each run was stopped by our RAM guard. - After: every later run of the 375 s route finished. For example, runs R20, R26 and R41 kept 2.3–3.4 GB free at their lowest point and did 3–13 trims per run (`working-set trims N`). - For shader changes, the wave sizes tested: n/a - `cargo test` passed for the crates it touches: yes. `cargo test -p victory-gpu --lib residency` gave 9 passed. Clippy for `victory-gpu` (`--all-targets`, and again with `--all-features`) added no new warnings. Pristine `main` already fails `-D warnings`: `victory-shader` has 3 errors (unused imports in `emit/lower`, `while_immutable_condition` in `analysis.rs`), and `victory-gpu` has 25 pre-existing warnings. None of them are in the lines this PR touches. `cargo xtask policy --staged` passed. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2638, #2671, #2234, #3584 - #2638 changes the hard *minimum* of `SetProcessWorkingSetSizeEx` (the kept-RAM lock). It does not empty the set. - #2671, #2234 and #3381 trim our own spare pools (upload buffers, snapshot buffers, chunks) under pressure. They do not touch the process working set. - #3584 makes the free-RAM pressure lines configurable. - None of them calls `EmptyWorkingSet` outside the manual F7 flush. This PR complements them. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A thread of its own (victory-ram-trim, started by the once-a-second sweep)
samples free physical memory, every 250 ms while under twice the line, else
every second; under VICTORY_RAM_TRIM_MB (2560; 0: off) it calls
K32EmptyWorkingSet on the process, at most every VICTORY_RAM_TRIM_EVERY_S (8)
seconds, and logs free memory and the working set before and 200 ms after.
Until now the working set was given back only on a hard flush (F7). Most of
it is title memory whose uploaded texture pages are cold; pages still used
come back by soft faults. D3D12 heaps are not touched. The "memory now:"
line gives the trims.

On a 32 GB PC (RTX 4080, Series X profile, 1080p to 4K DLSS) the Chapter 1
flyover took free memory under 1 GiB at 153-166 s in two runs; with the
trims (3-13 a run) every run of the 375 s route finished, 2.3-3.4 GB free
at the lowest. Measured on a fork build, not yet on this base.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 05:57:21 +00:00
Author
Owner

@⁠Mikey970 on GitHub · 2026-11-30 06:00 UTC · original

Holding this as a draft while I check a possible regression. In two in-game runs of main 41adb551 + this PR + #3749/#3750/#3751 together (RTX 4080, Series X, DLSS Performance via Streamline), the run ended near the end of the 375 s route with a host command list did not close (The parameter is incorrect. (0x80070057)); a run of plain main with the same settings finished clean. The slot-eviction look let go of no texture in either run, and the trim fired 1–3 times, so neither is an obvious cause yet. I am running each change on its own and will mark this ready again (or fix it) with the result.

🤖 Generated with Claude Code

**@⁠Mikey970** on GitHub · 2026-11-30 06:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7270214749) Holding this as a draft while I check a possible regression. In two in-game runs of `main` 41adb551 + this PR + #3749/#3750/#3751 together (RTX 4080, Series X, DLSS Performance via Streamline), the run ended near the end of the 375 s route with `a host command list did not close (The parameter is incorrect. (0x80070057))`; a run of plain `main` with the same settings finished clean. The slot-eviction look let go of no texture in either run, and the trim fired 1–3 times, so neither is an obvious cause yet. I am running each change on its own and will mark this ready again (or fix it) with the result. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠Mikey970 on GitHub · 2026-11-30 06:16 UTC · original

Result of the isolation runs (same PC, main 41adb551 + this PR, Series X, DLSS Performance via Streamline, 375 s Chapter 1 route):

Run Working-set trim Other PRs World entry Route
plain main (2 runs) none none 1 of 2 stopped by the 1 GiB free-RAM guard (72 MB free) the other completed (1,799 MB free at its lowest)
this branch, trim off (VICTORY_RAM_TRIM_MB=0) off #3750/#3751 off or inert stopped by the guard (949 MB free) —
this branch alone in effect (#3750 off) on — 6 trims, 2,528 MB free at the lowest completed 375 s, no errors
with #3750 and #3751 too (2 runs) on, 1 and 3 trims on 2,438 / 2,528 MB free at the lowest completed / ended at the shore with a host command list did not close

The end-of-route error only appeared with #3750's look-aside on, never with this change alone, so I am marking this one ready again; #3750 stays a draft while I look into that.

🤖 Generated with Claude Code

**@⁠Mikey970** on GitHub · 2026-11-30 06:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7270477044) Result of the isolation runs (same PC, `main` 41adb551 + this PR, Series X, DLSS Performance via Streamline, 375 s Chapter 1 route): | Run | Working-set trim | Other PRs | World entry | Route | |---|---|---|---|---| | plain `main` (2 runs) | none | none | 1 of 2 stopped by the 1 GiB free-RAM guard (72 MB free) | the other completed (1,799 MB free at its lowest) | | this branch, trim off (`VICTORY_RAM_TRIM_MB=0`) | off | #3750/#3751 off or inert | stopped by the guard (949 MB free) | — | | this branch alone in effect (#3750 off) | on | — | 6 trims, 2,528 MB free at the lowest | **completed 375 s, no errors** | | with #3750 and #3751 too (2 runs) | on, 1 and 3 trims | on | 2,438 / 2,528 MB free at the lowest | completed / ended at the shore with `a host command list did not close` | The end-of-route error only appeared with #3750's look-aside on, never with this change alone, so I am marking this one ready again; #3750 stays a draft while I look into that. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 08:34 UTC · original

One interaction with VICTORY_KEEP_RAM_GB is reproducible without the title. Windows accepted a 256 MiB hard minimum. A background thread then called K32EmptyWorkingSet. After the same 200 ms delay used here, the working set went from 387 MiB to under 1 MiB while the hard-minimum flag and size were still reported as enabled. Private commit stayed at 385 MiB.

In seven fresh-process runs per arm, reading one byte per page in the 128 MiB hot part of a 384 MiB allocation went from 0 faults / 0.344 ms median without trim to 32,768 faults / 24.520 ms after trim. This only measures the page reread. The background call is off the submit thread, but later access to trimmed pages can still cost time there.

Follow-up commit 847e683, based on 0f9e2cd, skips a due trim while Windows reports a hard minimum. The guarded probe kept the working set at 387 MiB and recorded zero faults on the hot reread. It still trims when no hard minimum is active, and the live query allows trimming after the minimum is released by #2638. The 8 residency tests passed with the diagnostics feature and the staged asset-policy check passed.

**@⁠tyr0nsur** on GitHub · 2026-11-30 08:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7273085518) One interaction with VICTORY_KEEP_RAM_GB is reproducible without the title. Windows accepted a 256 MiB hard minimum. A background thread then called `K32EmptyWorkingSet`. After the same 200 ms delay used here, the working set went from 387 MiB to under 1 MiB while the hard-minimum flag and size were still reported as enabled. Private commit stayed at 385 MiB. In seven fresh-process runs per arm, reading one byte per page in the 128 MiB hot part of a 384 MiB allocation went from 0 faults / 0.344 ms median without trim to 32,768 faults / 24.520 ms after trim. This only measures the page reread. The background call is off the submit thread, but later access to trimmed pages can still cost time there. [Follow-up commit `847e683`](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/847e683e8d515d635df765cf733fad1f116a1321), based on `0f9e2cd`, skips a due trim while Windows reports a hard minimum. The guarded probe kept the working set at 387 MiB and recorded zero faults on the hot reread. It still trims when no hard minimum is active, and the live query allows trimming after the minimum is released by #2638. The 8 residency tests passed with the diagnostics feature and the staged asset-policy check passed.
K32EmptyWorkingSet can remove pages below the floor requested by
VICTORY_KEEP_RAM_GB while Windows still reports that floor as enabled.
Check the effective policy before each due trim. This keeps the hard floor
while it is active and lets trim resume if Windows releases it, as in
#2638. Clarify that refaults may still cost time on the submitting thread.
Author
Owner

@⁠Mikey970 on GitHub · 2026-11-30 13:54 UTC · original

@⁠tyr0nsur thanks, that's a real interaction: K32EmptyWorkingSet empties pages below a hard minimum that Windows still reports as enabled, so with VICTORY_KEEP_RAM_GB set the trim undid the floor and the later refaults land on whichever thread touches the pages.

I took your 847e683 onto this branch as-is (fast-forward, your authorship). A due trim is now skipped while GetProcessWorkingSetSizeEx reports QUOTA_LIMITS_HARDWS_MIN_ENABLE (logged once for each minimum it sees), and trimming resumes once the minimum is released (#2638). The doc comment now also says refaults can still cost time on the submitting thread.

Tested: cargo test -p victory-gpu --lib -- residency:: 8 passed; clippy on victory-gpu --all-targets adds no warning (the CI check failure is the pre-existing unwind_copy one on main 41adb551). I have not run it in-game yet with VICTORY_KEEP_RAM_GB set.

🤖 Generated with Claude Code

**@⁠Mikey970** on GitHub · 2026-11-30 13:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7280546655) @⁠tyr0nsur thanks, that's a real interaction: `K32EmptyWorkingSet` empties pages below a hard minimum that Windows still reports as enabled, so with `VICTORY_KEEP_RAM_GB` set the trim undid the floor and the later refaults land on whichever thread touches the pages. I took your `847e683` onto this branch as-is (fast-forward, your authorship). A due trim is now skipped while `GetProcessWorkingSetSizeEx` reports `QUOTA_LIMITS_HARDWS_MIN_ENABLE` (logged once for each minimum it sees), and trimming resumes once the minimum is released (#2638). The doc comment now also says refaults can still cost time on the submitting thread. Tested: `cargo test -p victory-gpu --lib -- residency::` 8 passed; clippy on `victory-gpu --all-targets` adds no warning (the CI `check` failure is the pre-existing `unwind_copy` one on `main` 41adb551). I have not run it in-game yet with `VICTORY_KEEP_RAM_GB` set. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`VICTORY_RAM_TRIM_MB` is now off unless set (default 0; the measured runs
used 2560). On a PC whose free memory stays under the line (a 16 GB one)
it emptied the whole working set every 8 s for the rest of the run, each
time writing dirty pages out and faulting the hot ones back in. A trim
that frees under 256 MiB now doubles the wait before the next one, up to
2 minutes; one that frees more resets it (`next_trim_wait`, test
`trims_that_gain_little_back_off`). The doc no longer says D3D12 heaps
are untouched: `K32EmptyWorkingSet` takes every pageable page, the
CPU-visible pages of upload and readback heaps among them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠Mikey970 on GitHub · 2026-11-30 14:44 UTC · original

Follow-up 9a0d18ae, after a review of the default:

  • Opt-in: VICTORY_RAM_TRIM_MB now defaults to 0 (off). With 2560 on by default, a PC whose free memory stays under the line (a 16 GB one) would empty the whole working set every 8 s for the whole run, paging dirty pages out and faulting hot ones back in (cf. @⁠tyr0nsur's 0 → 32,768 faults on a 128 MiB reread). The runs in the description used 2560.
  • Back-off: a trim that frees less than 256 MiB doubles the wait before the next one, up to 2 minutes; a trim that frees more resets it.
  • Doc fix: the doc no longer says D3D12 heaps are untouched. K32EmptyWorkingSet takes every pageable page, including the CPU-visible pages of upload and readback heaps.

Tested: cargo test -p victory-gpu --lib -- residency:: 9 passed (new trims_that_gain_little_back_off); no new clippy warnings. Description updated to match.

🤖 Generated with Claude Code

**@⁠Mikey970** on GitHub · 2026-11-30 14:44 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7281851976) Follow-up `9a0d18ae`, after a review of the default: - **Opt-in:** `VICTORY_RAM_TRIM_MB` now defaults to `0` (off). With 2560 on by default, a PC whose free memory stays under the line (a 16 GB one) would empty the whole working set every 8 s for the whole run, paging dirty pages out and faulting hot ones back in (cf. @⁠tyr0nsur's 0 → 32,768 faults on a 128 MiB reread). The runs in the description used `2560`. - **Back-off:** a trim that frees less than 256 MiB doubles the wait before the next one, up to 2 minutes; a trim that frees more resets it. - **Doc fix:** the doc no longer says D3D12 heaps are untouched. `K32EmptyWorkingSet` takes every pageable page, including the CPU-visible pages of upload and readback heaps. Tested: `cargo test -p victory-gpu --lib -- residency::` 9 passed (new `trims_that_gain_little_back_off`); no new clippy warnings. Description updated to match. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠nick0451 on GitHub · 2026-11-30 14:51 UTC · original

Test on a 32 GB PC, where free RAM really does drop under the line. RTX 3090 with the card budget capped to emulate an 8 GB card (VICTORY_VRAM_BUDGET_MB=6800), i9-14900K, 32 GB (31.8 GiB), Windows 11. Series S, the city street save standing with a tap every 25 s, 20 min per run, window off screen.

Builds: v2026.11.29.05 (41adb551) against the same with this PR merged (0f9e2cde; the PR has moved on since).

The trim works as described. In each PR run it fired at about minute 8, when free memory reached about 2.5 GB:

run free RAM before → after working set before → after working set mean over the run mean fps
PR, run 1 2,344 → 4,753 MiB (2 trims) 21,279 → 3,443 MiB about 10 GB ~19.5
PR, run 2 2,547 → 5,222 MiB 22,125 → 2,642 MiB 9.9 GB 19.6
PR, run 3 2,485 → 4,753 MiB 22,025 → 3,094 MiB 10.4 GB 20.9
main — — 22.3 GB 19.5
  • Private memory is unchanged (about 25 GB). The pages go to the page file and come back as needed. In my 30 s samples there was no frame-rate dip around a trim, though a sub-second hitch wouldn't show at that rate.
  • One thing to look at: PR run 1 ended about 14 min in, roughly 3 min after its second trim, with a host command list did not close (The parameter is incorrect. (0x80070057)) (host GPU failure). The two later PR runs, with one trim each, ran the full 20 minutes. No main run under the same 8 GB cap failed in about 10 runs over the last two days. So it is 1 of 3 here and 0 of about 10 on main. That is not enough to blame the trim (the same failure is reported on 8 GB cards without it, #3254), but it's worth knowing that the only failure came in the run with two trims.

🤖 Generated with Claude Code

**@⁠nick0451** on GitHub · 2026-11-30 14:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7282037839) Test on a 32 GB PC, where free RAM really does drop under the line. RTX 3090 with the card budget capped to emulate an 8 GB card (`VICTORY_VRAM_BUDGET_MB=6800`), i9-14900K, 32 GB (31.8 GiB), Windows 11. Series S, the city street save standing with a tap every 25 s, 20 min per run, window off screen. **Builds:** v2026.11.29.05 (`41adb551`) against the same with this PR merged (`0f9e2cde`; the PR has moved on since). **The trim works as described.** In each PR run it fired at about minute 8, when free memory reached about 2.5 GB: | run | free RAM before → after | working set before → after | working set mean over the run | mean fps | |---|---|---|---|---| | PR, run 1 | 2,344 → 4,753 MiB (2 trims) | 21,279 → 3,443 MiB | about 10 GB | ~19.5 | | PR, run 2 | 2,547 → 5,222 MiB | 22,125 → 2,642 MiB | 9.9 GB | 19.6 | | PR, run 3 | 2,485 → 4,753 MiB | 22,025 → 3,094 MiB | 10.4 GB | 20.9 | | main | — | — | 22.3 GB | 19.5 | - Private memory is unchanged (about 25 GB). The pages go to the page file and come back as needed. In my 30 s samples there was no frame-rate dip around a trim, though a sub-second hitch wouldn't show at that rate. - **One thing to look at:** PR run 1 ended about 14 min in, roughly 3 min after its second trim, with `a host command list did not close (The parameter is incorrect. (0x80070057))` (host GPU failure). The two later PR runs, with one trim each, ran the full 20 minutes. No main run under the same 8 GB cap failed in about 10 runs over the last two days. So it is 1 of 3 here and 0 of about 10 on main. That is not enough to blame the trim (the same failure is reported on 8 GB cards without it, #3254), but it's worth knowing that the only failure came in the run with two trims. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠futurepro62 on GitHub · 2026-12-01 05:10 UTC · original

Data from the same idea run on another tree, in case it helps decide defaults here. I ported KyleS98's automatic hand-back from VIctory-Neo (mod trim in its residency.rs, commits 87f89c5, 18231b9, bbb0995, d9d2c3d; full report in Neo #39). It uses the same call (K32EmptyWorkingSet on our own process, on a thread of its own), so @⁠nick0451's question about sub-second hitches is one these runs can answer.

PC and build: RTX 5070 Ti 16 GB (621.40), Ryzen 7 9800X3D, 31 GB RAM, Windows 11. This fork's 93008750 plus local commits plus the port. Series X, 4K output, DLSS Performance, frame generation 4x, free play and story missions (not a fixed route). VICTORY_KEEP_RAM_GB=0, because the 14 GB hard minimum blocked the hand-back, as @⁠tyr0nsur found here.

How Neo's version differs from this PR

  • Two triggers: free RAM under a tenth of the PC (3-8 GiB; 3,185 MB here), or the working set over two fifths of the PC (6-20 GiB; 12,743 MB here), at most every 2 minutes. This PR has only the first.
  • Never while the driver makes pipelines: it waits until no pipeline has been made for 10 s, or acts at once only below a third of the free-RAM line. Neo traced a launch stall (the title's watchdog after a 30 s stall) to NVIDIA's shader-cache files (*.nvph, mapped into the process: 13 GB of a 40 GB working set in Neo's measurement; this PC has the same files) being trimmed in the middle of a build. That guard may be worth having here too.

What the logs show (6 runs, about 2 hours, 26 hand-backs)

  • Each call took 1.2-3.1 s on its thread. The working set went from 13-22 GB to 1.2-3.4 GB.
  • Hitch per hand-back: in round 9 (34 min, 12 hand-backs), the 10 s around each hand-back had 52 frames over 100 ms a minute, against 35 otherwise, and held the two worst frames (409 and 394 ms). So yes, there is a hitch, about 0.3-1 s spread over a few frames. The working set grew back to 8-10 GB within 40-60 s.
  • Effect: working set median 11.7 GB against 18-20 GB without it, free RAM median 5.0 against 3.7-4.2 GB, and a mission that had crashed twice finished. Private memory did not change (34.6 GB peak).
  • Trimming to a size instead of emptying doesn't work: a hard maximum with SetProcessWorkingSetSizeEx (to 8 GB, then restoring the old limits) still took the set to 1.5-3.2 GB. Each hand-back then landed as one long frame (0.5-1.05 s).
  • Errors: no a host command list did not close in any of the 6 logs. One run ended in a device hang (0x887A0006, relay fence, the submitting thread had been preparing one submission for 4,820 ms) 43 s after a hand-back. That run also had VICTORY_WINDOWS_BAR_MB=2048 on, and I had put it down to #3563 (it came as a minigame screen opened), but with nick0451's 1-of-3 it is worth saying: 1 failure in 6 runs, 43 s after a trim.

Method: hand-back times and sizes are from the build's own WARN lines (victory_gpu::memory). Frame times are from the VICTORY_FPS_LINE 5 s lines and a 1 s recorder of the process (working set, private, free RAM). Long frames are counted in 10 s windows centred on each WARN line. One PC, runs not on a fixed route, so per-scene fps is compared by draws per frame only. Not tested: this PR's build itself, and any PC other than this one.

**@⁠futurepro62** on GitHub · 2026-12-01 05:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7301487800) Data from the same idea run on another tree, in case it helps decide defaults here. I ported KyleS98's automatic hand-back from [VIctory-Neo](https://github.com/KyleS98/VIctory-Neo) (`mod trim` in its `residency.rs`, commits `87f89c5`, `18231b9`, `bbb0995`, `d9d2c3d`; full report in [Neo #39](https://github.com/KyleS98/VIctory-Neo/issues/39)). It uses the same call (`K32EmptyWorkingSet` on our own process, on a thread of its own), so @⁠nick0451's question about sub-second hitches is one these runs can answer. **PC and build:** RTX 5070 Ti 16 GB (621.40), Ryzen 7 9800X3D, 31 GB RAM, Windows 11. This fork's `93008750` plus local commits plus the port. Series X, 4K output, DLSS Performance, frame generation 4x, free play and story missions (not a fixed route). `VICTORY_KEEP_RAM_GB=0`, because the 14 GB hard minimum blocked the hand-back, as @⁠tyr0nsur found here. **How Neo's version differs from this PR** - **Two triggers:** free RAM under a tenth of the PC (3-8 GiB; 3,185 MB here), or the working set over two fifths of the PC (6-20 GiB; 12,743 MB here), at most every 2 minutes. This PR has only the first. - **Never while the driver makes pipelines:** it waits until no pipeline has been made for 10 s, or acts at once only below a third of the free-RAM line. Neo traced a launch stall (the title's watchdog after a 30 s stall) to NVIDIA's shader-cache files (`*.nvph`, mapped into the process: 13 GB of a 40 GB working set in Neo's measurement; this PC has the same files) being trimmed in the middle of a build. That guard may be worth having here too. **What the logs show (6 runs, about 2 hours, 26 hand-backs)** - Each call took 1.2-3.1 s on its thread. The working set went from 13-22 GB to 1.2-3.4 GB. - **Hitch per hand-back:** in round 9 (34 min, 12 hand-backs), the 10 s around each hand-back had 52 frames over 100 ms a minute, against 35 otherwise, and held the two worst frames (409 and 394 ms). So yes, there is a hitch, about 0.3-1 s spread over a few frames. The working set grew back to 8-10 GB within 40-60 s. - **Effect:** working set median 11.7 GB against 18-20 GB without it, free RAM median 5.0 against 3.7-4.2 GB, and a mission that had crashed twice finished. Private memory did not change (34.6 GB peak). - **Trimming to a size instead of emptying doesn't work:** a hard maximum with `SetProcessWorkingSetSizeEx` (to 8 GB, then restoring the old limits) still took the set to 1.5-3.2 GB. Each hand-back then landed as one long frame (0.5-1.05 s). - **Errors:** no `a host command list did not close` in any of the 6 logs. One run ended in a device hang (`0x887A0006`, relay fence, the submitting thread had been preparing one submission for 4,820 ms) **43 s after a hand-back**. That run also had `VICTORY_WINDOWS_BAR_MB=2048` on, and I had put it down to #3563 (it came as a minigame screen opened), but with nick0451's 1-of-3 it is worth saying: 1 failure in 6 runs, 43 s after a trim. **Method:** hand-back times and sizes are from the build's own WARN lines (`victory_gpu::memory`). Frame times are from the `VICTORY_FPS_LINE` 5 s lines and a 1 s recorder of the process (working set, private, free RAM). Long frames are counted in 10 s windows centred on each WARN line. One PC, runs not on a fixed route, so per-scene fps is compared by draws per frame only. Not tested: this PR's build itself, and any PC other than this one.
Author
Owner

@⁠xteral67 on GitHub · 2026-12-01 17:16 UTC · original

Results with a working-set trim close to this PR, on a PC that runs out of RAM in a large city.

Setup: RTX 3080 Ti 12 GB, 32 GB RAM, Series X profile, 1440p, DLSS quality, FSR 3 frame generation 2x, diagnostics build. One 26-minute drive into the biggest city.

  • Before the trim: working set 25.0 GB, free RAM 0.5 GB. Pipeline compiles in the driver took 5-7 s each and froze the game.
  • One trim (K32EmptyWorkingSet) took 3.06 s on its own thread with no visible stall.
  • After: working set 6.3 GB, free RAM 11.8 GB, then 3.3-11 GB for the rest of the drive. Compiles took 0.55-0.76 s.
  • One run only.

Differences in our version, in case they are useful here:

  • it never trims while pipeline work runs, or within 3 s of it;
  • at least 30 s between trims;
  • it measures the gain 10 s later and waits longer when a trim gave little back.
**@⁠xteral67** on GitHub · 2026-12-01 17:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7319031461) Results with a working-set trim close to this PR, on a PC that runs out of RAM in a large city. Setup: RTX 3080 Ti 12 GB, 32 GB RAM, Series X profile, 1440p, DLSS quality, FSR 3 frame generation 2x, diagnostics build. One 26-minute drive into the biggest city. - Before the trim: working set 25.0 GB, free RAM 0.5 GB. Pipeline compiles in the driver took 5-7 s each and froze the game. - One trim (`K32EmptyWorkingSet`) took 3.06 s on its own thread with no visible stall. - After: working set 6.3 GB, free RAM 11.8 GB, then 3.3-11 GB for the rest of the drive. Compiles took 0.55-0.76 s. - One run only. Differences in our version, in case they are useful here: - it never trims while pipeline work runs, or within 3 s of it; - at least 30 s between trims; - it measures the gain 10 s later and waits longer when a trim gave little back.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 17:24 UTC · original · edited 2026-12-01 17:49 UTC

The recent runs used a compiler quiet window before trimming the working set. xteral67's run used three seconds. futurepro62's run also kept an emergency path for free RAM below a third of the trim line.

000b036e applies that scheduling rule on 9a0d18ae. A due trim defers while a tracked driver compile is running and for three seconds after it finishes. Below a third of the line it can still run, subject to the existing hard working-set minimum and backoff. This is a check at scheduling time, so a compile can still start after it.

A focused Windows fixture used the exact scheduling gate and compile finish path. It exercised active, recently finished and idle compiler states, acute pressure and an unexpired backoff. Windows cargo check --locked -p victory-gpu and staged asset policy passed. Whether this reduces stalls needs a matched run. The PR head still conflicts in host.rs. e390ba38 carries the three PR commits and the quiet-window change onto main at 5fabb46e with their original authors. It keeps the current memory sweep and card breakdown, then appends the trim count. Windows cargo check --locked -p victory-gpu passed on this head and staged asset policy checked all three changed files. The branch gives the PR author a clean starting point for a matched run and rebase.

Please keep the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change in.

AI-assisted with OpenAI Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 17:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7319246450) · edited 2026-12-01 17:49 UTC The recent runs used a compiler quiet window before trimming the working set. [xteral67's run](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/3749) used three seconds. [futurepro62's run](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/3749) also kept an emergency path for free RAM below a third of the trim line. [000b036e](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/000b036ee66d902f3f1aef3f3f04ea61612a5fbc) applies that scheduling rule on `9a0d18ae`. A due trim defers while a tracked driver compile is running and for three seconds after it finishes. Below a third of the line it can still run, subject to the existing hard working-set minimum and backoff. This is a check at scheduling time, so a compile can still start after it. A focused Windows fixture used the exact scheduling gate and compile finish path. It exercised active, recently finished and idle compiler states, acute pressure and an unexpired backoff. Windows `cargo check --locked -p victory-gpu` and staged asset policy passed. Whether this reduces stalls needs a matched run. The PR head still conflicts in `host.rs`. [e390ba38](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/e390ba38721461ea3a4d508dee214eea13bf40b7) carries the three PR commits and the quiet-window change onto `main` at `5fabb46e` with their original authors. It keeps the current memory sweep and card breakdown, then appends the trim count. Windows `cargo check --locked -p victory-gpu` passed on this head and staged asset policy checked all three changed files. The branch gives the PR author a clean starting point for a matched run and rebase. Please keep the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change in. AI-assisted with OpenAI Codex.
github-bot closed this pull request 2026-12-01 18:51:23 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:49 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3749#issuecomment-7321606322) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
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
github/trustno1-coder--VIctory-NVIDIA!3749
No description provided.