Repository navigation
Conversation
…M_TRIM_MB 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 <noreply@anthropic.com>
|
Holding this as a draft while I check a possible regression. In two in-game runs of 🤖 Generated with Claude Code |
|
Result of the isolation runs (same PC,
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 |
… set while free RAM is under VICTORY_RAM_TRIM_MB) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 trustno1-coder#2638. Clarify that refaults may still cost time on the submitting thread.
|
One interaction with VICTORY_KEEP_RAM_GB is reproducible without the title. Windows accepted a 256 MiB hard minimum. A background thread then called 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 |
|
@tyr0nsur thanks, that's a real interaction: I took your Tested: 🤖 Generated with Claude Code |
…ns little `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 <noreply@anthropic.com>
|
Follow-up
Tested: 🤖 Generated with Claude Code |
|
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 ( Builds: v2026.11.29.05 ( The trim works as described. In each PR run it fired at about minute 8, when free memory reached about 2.5 GB:
🤖 Generated with Claude Code |
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_setinresource.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, besideresidency::refresh):VICTORY_RAM_TRIM_MBis set (unset or0: off, the default; the runs below used2560). While free memory is under that line it callsK32EmptyWorkingSeton our own process, at most once everyVICTORY_RAM_TRIM_EVERY_Sseconds (default 8).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.VICTORY_KEEP_RAM_GB,QUOTA_LIMITS_HARDWS_MIN_ENABLE), and resumes if it is released (Play: the kept RAM's hard minimum is let go before the PC runs out #2638). Commit847e683by @tyr0nsur.working set trimmed (VICTORY_RAM_TRIM_MB): …).memory now:line, written once a second, now ends withworking-set trims N.Costs:
K32EmptyWorkingSettakes 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_oftenandtrims_that_gain_little_back_off.How it was tested
In game on this branch's base (
main41adb55 + this change), same PC and route: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 plainmaingot through with 1,006 MiB free at its lowest.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.mainat 41adb55 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 byVICTORY_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 testpassed for the crates it touches: yes.cargo test -p victory-gpu --lib residencygave 9 passed. Clippy forvictory-gpu(--all-targets, and again with--all-features) added no new warnings. Pristinemainalready fails-D warnings:victory-shaderhas 3 errors (unused imports inemit/lower,while_immutable_conditioninanalysis.rs), andvictory-gpuhas 25 pre-existing warnings. None of them are in the lines this PR touches.cargo xtask policy --stagedpassed.Checked for overlap
SetProcessWorkingSetSizeEx(the kept-RAM lock). It does not empty the set.EmptyWorkingSetoutside the manual F7 flush. This PR complements them.🤖 Generated with Claude Code