XMem: the kept section view stays above the title's window #4936
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!4936
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4935"
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?
@lingbz112 on GitHub · 2026-12-01 14:42 UTC · original
lingbz112:xmem-section-view-above-window→main· +103 −0 · 1 files · 2 commits · openRelated: #2081 (the start crash from the title's window being full; this is
the request after the 8 GiB spare has placed the 6,236 MiB heap)
What it changes
Section::window()keeps one view of the whole page-pool section (so aDirectStorage write does not map, commit and fault a view per page). It was
mapped wherever Windows chose, and for a 6 GiB pool that address landed inside
[4 GiB, 2^37)— the title's own window. A 6,236 MiB TileHeap (page pool)therefore cost the title another 6,236 MiB of its window.
On the reporting PC (details under "How it was tested") the window then had
0–6 MB free: the 8 GiB spare placed the TileHeap on the second try and was
given back, the 6 GiB view took what was left, and the title's next 8–13 MiB
request (
kind=0x203000,flags=0x181/0x3) was refused withERROR_NOT_ENOUGH_MEMORY. The title asserted (0x80000003) at Game Init,Frame 0, about 1 s later, 7 starts out of 7.
This reserves a placeholder with our own first-fit walk above
2^37and mapsthe section view into it (
MapViewOfFile3,MEM_REPLACE_PLACEHOLDER);VirtualAlloc2withMEM_ADDRESS_REQUIREMENTS+MEM_RESERVE_PLACEHOLDERreturns
ERROR_INVALID_PARAMETERon 26300, so the walk finds the free run andthe placeholder is taken at that address. Where the host gives no view above
2^37(Wine),window()falls back to the mapping it had before, unchanged.The view is ours alone: no title address, nothing the title sees, and no
shader reads it by page number (the by-address directory covers title memory,
not this alias). The same section and the same bytes are written; only the
address of the alias changes, so the DirectStorage optimisation is kept.
How it was tested
STRIX Z690-A GAMING WIFI, Windows 11 Pro 10.0.26300 (64-bit, native).
The layer's MFG Unlocker reports the card as an RTX 4090 so DLSS frame
generation is offered; that is the name the play logs carry. Monitor
2560x1440.
balanced, frame generation 2x (auto), ray tracing off.
Game Init, Frame 0, with
XMemVirtualAlloc ... size=8294400/13631488 ... largest_free_mb=0..6and0x80000003; minidump shows thewindow 100% taken (
0x1C2DE00000TileHeap + a second 6,236 MiBMEM_MAPPEDview right beside it).the kept section view is above the title's window at=0x2000000000— theview is at 128 GiB, outside
[4 GiB, 2^37); 48 present windows / 626submissions in a 60 s run, no XMem refusal after the 6.5 GiB first-fit (the
8 GiB spare still places it), no crash, no dump. The run was stopped after
60 s; no longer session was tested.
cargo test -p victory-hle --lib window: 13 passed, including the newthe_retained_window_keeps_out_of_the_title_window.cargo test -p victory-hle --lib a_refused_view_above_falls_back_to_the_old_mapping:1 passed — a thread-local test seam makes the above-window reservation
fail, and
window()still maps the section with the oldMapViewOfFilepath (bytes written through the retained view are read back through the
section's own view).
cargo test -p victory-hle --lib xmem: 50 passed, 1 failed —a_read_by_range_waits_only_for_a_remapping_that_meets_it(a timingassertion), which passes 3/3 when run alone. It does not touch this code.
cargo clippy -p victory-hle --all-targets --locked -- -D warningsfailsin
victory-gpu(5collapsible_if-style suggestions, e.g.host/menu.rs:669) — not files this change touches.Checked for overlap
crates/victory-hle/src/modules/xmem.rs: #2133 (closed, the 2^37 fallback),#2263 (closed; its 8 GiB spare is in main), #3242, #3126, #3353, #3787,
#4143, #4318, #4364, #4419, #4611, #3085, #2439. None changes
Section::window().Related: #3353 (spare default 6,300 MiB) and #3787 (the window walk) touch
the same file and the same startup failure family, but neither moves this
view, so on the PC above they leave the window short by the 6 GiB the view
takes.
@gut0to on GitHub · 2026-12-01 14:58 UTC · original · reviewed
AI-assisted review: I checked the new mapping path and its regression test. I used AI assistance and verified this test suggestion against the current diff.
@ -1075,6 +1075,9 @@ impl Section {return None;}let base = *self.window.get_or_init(|| {if let Some(at) = self.whole_view_above_window() {@gut0to on GitHub · 2026-12-01 14:58 UTC · original
Could this fallback be tested deterministically? This path intentionally treats failure to reserve or map a placeholder above the title window as a reason to use the previous
MapViewOfFilepath, but the added test only exercises the successful above-window mapping on non-Wine hosts; the Wine branch does not verify that the new reservation path failed. A test seam that forces reservation failure could confirmwindow()still returns a usable page through the fallback and protects this compatibility path.@ -1075,6 +1093,9 @@ impl Section {return None;}let base = *self.window.get_or_init(|| {if let Some(at) = self.whole_view_above_window() {@lingbz112 on GitHub · 2026-12-01 15:04 UTC · original
Good point - added in
d567da7.A thread-local seam (
ABOVE_WINDOW_REFUSED,#[cfg(test)]only) makeswhole_view_above_window()returnNoneon the running test's thread, so thefallback is forced without an environment variable and without touching the
tests that expect a view above 2^37 (each test runs on its own thread).
a_refused_view_above_falls_back_to_the_old_mappingmaps a two-page sectionthrough
window()with the seam set, writes 8 bytes through the retained viewand reads them back through the section's own view, so the fallback is the
one
MapViewOfFilepath and the pages behind it are the section's.The release build compiles the non-test stub (
false), so nothing of the seamis in a shipped binary.
@cloph-dsp on GitHub · 2026-12-01 15:15 UTC · original
Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree, per-worktree CARGO_TARGET_DIR.
Base
5fabb46eaf6ed8771321787f8871051abde69b9b, headd567da7fca1c418e73038d97692d231600042d74.git diff --numstat→ crates/victory-hle/src/modules/xmem.rs 103/0.Two tests, both new on the base (
git grep -F <name> 5fabb46e -- .returns no match):modules::xmem::tests::a_refused_view_above_falls_back_to_the_old_mapping,modules::xmem::tests::the_retained_window_keeps_out_of_the_title_window.Note on the third name that appears in the diff:
whole_view_above_windowis not a test — it is the helper at xmem.rs:1135,fn whole_view_above_window(&self) -> Option<usize>, used by both tests.git diff --check "5fabb46e..d567da7f"→ no output, exit 0.Result, each:
running 1 test,test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 483 filtered out; finished in 0.00s.The tests drive the section book directly with synthetic reservations and an injected refusal; no title memory, no device, GPU/driver N/A. No game data.
@Dukestar69 on GitHub · 2026-12-01 16:23 UTC · original · approved these changes
Reviewed crates/victory-hle/src/modules/xmem.rs: mapping Section's retained whole-section view above 1 << TITLE_TOP_BITS via
eserve_first_fit + MapViewOfFile3(MEM_REPLACE_PLACEHOLDER) (releasing the placeholder on failure and falling back to MapViewOfFile) keeps internal views from consuming the title's [4 GiB, 2^37) address window. Minor nit: the /// doc comment above hread_local! at xmem.rs:983 triggers an unused_doc_comments warning in test builds (// avoids it). Verified on Windows: he_retained_window_keeps_out_of_the_title_window and _refused_view_above_falls_back_to_the_old_mapping both passed (2/2).
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.