XMem: physical pages can be kept in our working set so they are not paged out behind the title (VICTORY_KEEP_PAGES=1, off by default) #447
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!447
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-447"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Jesper-Andersson on GitHub · 2026-11-27 09:37 UTC · original
Jesper-Andersson:keep-pages→main· +186 −5 · 1 files · 1 commits · openA port of fxceless/victory-fork#1294 by @flxppr, adapted to main and with a free-RAM floor added. Credit for the idea and the first measurements goes there.
When the title unmaps the last view of physical pages it wrote (it remaps all the time), Windows takes the pages out of our working set and puts them on the modified list. From there it writes them to the pagefile, though the title still holds them, and they fault back in at the next mapping (
crates/victory-hle/src/modules/xmem.rs,showandView::map). On a 32 GB PC this shows as a 40-60 s stretch after entering the world: free RAM drops below 1 GB, page faults jump to thousands a frame, and single frames take 0.6-4 s.Change
VICTORY_KEEP_PAGES=1, off by default and under Wine (its sections are sparse files). Each section of physical pages gets its whole view at allocation,Section::whole. That is the view DirectStorage writes already go through (Section::window); it is now mapped eagerly and still unmapped only when the section goes. Every page that a title mapping (show) or a write view (View::map) commits is read once through it (Section::keep, one byte per 4 KiB), so it stays in our working set when the title's view goes. Nothing is locked, and no working-set minimum is set: Windows can still trim us.VICTORY_KEEP_PAGES_FREE_MB(default 512, 0 = no limit) is a floor: below that much free RAM it stops reading pages in, and starts again a quarter above (keep_band; free RAM is sampled at most every 100 ms). The PR this ports has no floor. A 2 GB floor was tried first and paused exactly where the switch helps (see below), so the default is only a guard against running out of RAM.VICTORY_KEEP_PAGES=1: physical pages held in our working set ...withasked_mb/granted_mb/headroom_mbat the first section and each GiB after; a warningno kept view for physical pagesif Windows refuses a view; an info line when the floor pauses or resumes.Where it does nothing
keeping()is false,keep_sectionandSection::keepreturn at once; the window is still mapped lazily as before.VICTORY_SECTION_WINDOW=0still works: the per-write views stay, and only keeping uses the whole view.Measured
These numbers are from a local branch, not from main itself. It is main plus about 50 merged PRs (local
test@ 68b0055), with this change on top and one unrelated switch that stays off. The commit here is the same change applied to main.RTX 2070 SUPER 8 GB (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11. Diag build, Series S + DLSS, intro skipped, the same scripted route into the world, about 150 s in the world. Only frames with at least 1,000 draws count; "steady" is the last 60 s.
KEEP_PAGES=1,FREE_MB=0(2 runs)KEEP_PAGES=1, 2 GB floor (1 run)free RAM low, pages no longer read in free_mb=2044) and kept little of the gain. With the default 512 MB floor, those two runs would have gone exactly as with no floor.Later runs on the same local branch, with the 512 MB default floor:
The original PR measured the pagefile writes directly. On a SATA SSD with 48 GB, they fell from 8.5 GB in 8 min to 0.3 GB with the switch. On 16 GB with an NVMe it was neutral to slightly worse, because Windows trims the working set anyway there. That is why it stays opt-in.
Checks
cargo test -p victory-hle --lib --locked: 162 passed, 2 ignored (new:keep_pages_is_on_only_for_1,keep_headroom_defaults_to_512_mib_and_0_turns_it_off,keep_band_stops_below_headroom_and_resumes_a_quarter_above)VICTORY_KEEP_PAGES=1 cargo test -p victory-hle --lib --locked xmem: 20 passed, 1 ignoredcargo clippy -p victory-hle --all-targets --locked: no warnings in victory-hle (4 in victory-gpu, as on main)cargo xtask policy --staged: 1 file okNot checked
VICTORY_KEEP_PAGES_FREE_MB=0and with the 512 default.Related
xmem.rsbut changes how pages are backed. It does not keep pages resident.This change was made with AI assistance (Claude Code).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.