Play: the kept RAM's hard minimum is let go before the PC runs out #2638

Open
unueberlegt wants to merge 4 commits from upstream-pr/2638 into main
unueberlegt commented 2026-11-29 15:21:33 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by unueberlegt on 2026-11-29T15:21:33Z.


What this changes

VICTORY_KEEP_RAM_GB's hard working-set minimum keeps its guarantee, but:

  • the maximum is soft again (QUOTA_LIMITS_HARDWS_MAX_DISABLE is no longer set): under pressure the memory manager may trim the set back to it, where before the process could claim the whole PC;
  • while the game runs, a thread watches the PC's free memory, and under 2 GB the hard minimum is let go — once, and a line says so. After that the game is trimmed as it would be without the switch;
  • a start asking for more than half the PC's memory says what that costs.

Why

The hard minimum is held even as the game's commit grows past what the PC can hold. Measured on an RTX 5070 12 GB / 31 GB PC, Series X, 1440p, DLSS Quality, FG 2× (#2464's §3): with 20 GB kept, the PC fell to 980 MB free, 202 host allocations were refused (0x8007000E), and the game died 4 minutes 49 seconds in — reading through a NULL pointer in VCRUNTIME140's copy loop, called from its own code, its crash handler taking the process down. The same run without the switch survives the same exhaustion as a zombie at 3 fps with 297 refused allocations: the difference the minimum makes is that nothing can be given back, so a failing allocation fails fatally in code that (a console title) has no out-of-memory path. #2464's reporter lost the device instead of the title — their 32 GB of page file kept the host's allocations alive, and the pressure landed on the card's residency.

The switch's own case (Windows cutting the working set from 15 GB to 2 GB at once, the game at half speed for minutes) is untouched: the minimum is kept as long as the PC can spare it.

Testing

  • New the_hard_minimum_is_let_go_when_the_pc_runs_out: the threshold's edges.
  • Measured, as above: dead 4:49 with 20 GB kept; 27 minutes alive without it; the disarm fires at the 515 MB–1 GB dips the kept run reaches before it dies.

Part of #2464 (its §3; §2 — the PC exhausting without the switch — is measured and reported there: 48 GB committed, ~300 refusals, 3 fps on this PC).

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5552128728 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2638). Originally posted by [unueberlegt](https://github.com/unueberlegt) on 2026-11-29T15:21:33Z. --- ## What this changes `VICTORY_KEEP_RAM_GB`'s hard working-set minimum keeps its guarantee, but: - the maximum is soft again (`QUOTA_LIMITS_HARDWS_MAX_DISABLE` is no longer set): under pressure the memory manager may trim the set back to it, where before the process could claim the whole PC; - while the game runs, a thread watches the PC's free memory, and under 2 GB the hard minimum is let go — once, and a line says so. After that the game is trimmed as it would be without the switch; - a start asking for more than half the PC's memory says what that costs. ## Why The hard minimum is held even as the game's commit grows past what the PC can hold. Measured on an RTX 5070 12 GB / 31 GB PC, Series X, 1440p, DLSS Quality, FG 2× (#2464's §3): with 20 GB kept, the PC fell to 980 MB free, 202 host allocations were refused (`0x8007000E`), and the game died 4 minutes 49 seconds in — reading through a NULL pointer in VCRUNTIME140's copy loop, called from its own code, its crash handler taking the process down. The same run without the switch survives the same exhaustion as a zombie at 3 fps with 297 refused allocations: the difference the minimum makes is that nothing can be given back, so a failing allocation fails fatally in code that (a console title) has no out-of-memory path. #2464's reporter lost the device instead of the title — their 32 GB of page file kept the host's allocations alive, and the pressure landed on the card's residency. The switch's own case (Windows cutting the working set from 15 GB to 2 GB at once, the game at half speed for minutes) is untouched: the minimum is kept as long as the PC can spare it. ## Testing - New `the_hard_minimum_is_let_go_when_the_pc_runs_out`: the threshold's edges. - Measured, as above: dead 4:49 with 20 GB kept; 27 minutes alive without it; the disarm fires at the 515 MB–1 GB dips the kept run reaches before it dies. Part of #2464 (its §3; §2 — the PC exhausting without the switch — is measured and reported there: 48 GB committed, ~300 refusals, 3 fps on this PC). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
dyshay commented 2026-11-29 15:40:03 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T15:40:03Z.


Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7258270176 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2638#issuecomment-7258270176). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-29T15:40:03Z. --- Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.
tyr0nsur commented 2026-11-30 08:34:57 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T08:34:57Z.


I reproduced two Win32 failures in the working-set setup and disarm paths of this PR.

  • With min = max = 256 MiB and flag 0x1, SetProcessWorkingSetSizeEx returned ERROR_INVALID_PARAMETER (87). The hard minimum was never installed on this machine.
  • With a 256 MiB minimum and 512 MiB maximum, install succeeded. The original disarm flags 0x4 | 0x8 also returned 87 and the reported flags stayed 0x9. Those two bits control the maximum in opposite directions.

Follow-up commit 0358b98, based on b82884e, keeps distinct sizes and uses only QUOTA_LIMITS_HARDWS_MIN_DISABLE (0x2). In the same Windows probe, the corrected call succeeded, flags changed from 0x9 to 0xA, and the guard proposed on #3749 detected the release. The watcher now reports a failed call and retries at the next low-RAM sample. The existing threshold test and staged asset-policy check passed. The API probe ran in a disposable process without the title.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7273084950 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2638#issuecomment-7273084950). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T08:34:57Z. --- I reproduced two Win32 failures in the working-set setup and disarm paths of this PR. - With `min = max = 256 MiB` and flag `0x1`, `SetProcessWorkingSetSizeEx` returned `ERROR_INVALID_PARAMETER` (87). The hard minimum was never installed on this machine. - With a 256 MiB minimum and 512 MiB maximum, install succeeded. The original disarm flags `0x4 | 0x8` also returned 87 and the reported flags stayed `0x9`. Those two bits control the maximum in opposite directions. [Follow-up commit `0358b98`](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/0358b98f3a7ac470e3ed8adfaf367c74af2ba308), based on `b82884e`, keeps distinct sizes and uses only `QUOTA_LIMITS_HARDWS_MIN_DISABLE` (`0x2`). In the same Windows probe, the corrected call succeeded, flags changed from `0x9` to `0xA`, and the guard proposed on #3749 detected the release. The watcher now reports a failed call and retries at the next low-RAM sample. The existing threshold test and staged asset-policy check passed. The API probe ran in a disposable process without the title.
unueberlegt commented 2026-12-01 08:42:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by unueberlegt on 2026-12-01T08:42:10Z.


Thanks for the reproduction and for pinning both failures down — the analysis was exactly right, and the fix is now on the branch.

Your 0358b98 is cherry-picked onto fix/keep-ram-self-disarm (authorship kept): distinct sizes on install and release (max = min * 2), only QUOTA_LIMITS_HARDWS_MIN_ENABLE on the way in and QUOTA_LIMITS_HARDWS_MIN_DISABLE on the way out, and a failed release is now logged and retried at the next low-RAM sample instead of silently ending the watch. The branch also carries a merge of current main, so it is MERGEABLE again.

@dyshay, one note for the janus-prs runs: they exercised the pre-fix form. Depending on the machine, either the hard minimum never installed (ERROR_INVALID_PARAMETER with equal sizes, so the run measured effectively no switch), or it installed and the broken disarm flags left it hard for the rest of the run — the case this PR exists for. If the queued RTX 4090 runs have not happened yet, a re-run against the updated branch would measure the switch as it is meant to work.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7305665611 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2638#issuecomment-7305665611). Originally posted by [unueberlegt](https://github.com/unueberlegt) on 2026-12-01T08:42:10Z. --- Thanks for the reproduction and for pinning both failures down — the analysis was exactly right, and the fix is now on the branch. Your `0358b98` is cherry-picked onto `fix/keep-ram-self-disarm` (authorship kept): distinct sizes on install and release (`max = min * 2`), only `QUOTA_LIMITS_HARDWS_MIN_ENABLE` on the way in and `QUOTA_LIMITS_HARDWS_MIN_DISABLE` on the way out, and a failed release is now logged and retried at the next low-RAM sample instead of silently ending the watch. The branch also carries a merge of current main, so it is MERGEABLE again. @dyshay, one note for the `janus-prs` runs: they exercised the pre-fix form. Depending on the machine, either the hard minimum never installed (`ERROR_INVALID_PARAMETER` with equal sizes, so the run measured effectively no switch), or it installed and the broken disarm flags left it hard for the rest of the run — the case this PR exists for. If the queued RTX 4090 runs have not happened yet, a re-run against the updated branch would measure the switch as it is meant to work.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2638:upstream-pr/2638'
git switch 'upstream-pr/2638'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2638'
git switch 'upstream-pr/2638'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2638'
git switch 'upstream-pr/2638'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2638'
git switch 'main'
git merge --squash 'upstream-pr/2638'
git switch 'main'
git merge --ff-only 'upstream-pr/2638'
git switch 'main'
git merge 'upstream-pr/2638'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!2638
No description provided.