XMem: the kept section view stays above the title's window #4936

Open
github-bot wants to merge 2 commits from github-bot/gh-4935 into main AGit
Owner

@⁠lingbz112 on GitHub · 2026-12-01 14:42 UTC · original
lingbz112:xmem-section-view-above-window → main · +103 −0 · 1 files · 2 commits · open

Related: #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 a
DirectStorage 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 with
ERROR_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^37 and maps
the section view into it (MapViewOfFile3, MEM_REPLACE_PLACEHOLDER);
VirtualAlloc2 with MEM_ADDRESS_REQUIREMENTS + MEM_RESERVE_PLACEHOLDER
returns ERROR_INVALID_PARAMETER on 26300, so the walk finds the free run and
the 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

  • Machine: Intel Core i5-14600KF (6P+8E, 20 threads), 32 GB DDR5, ASUS ROG
    STRIX Z690-A GAMING WIFI, Windows 11 Pro 10.0.26300 (64-bit, native).
  • GPU: NVIDIA GeForce RTX 2080 Ti 11 GB, driver 32.0.16.2140 (GeForce 621.40).
    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.
  • Profile: Series X files v1.0.2.1, 1440p target (1080p scene upscaled), DLSS
    balanced, frame generation 2x (auto), ray tracing off.
  • Before (release build, same files and settings): 7 of 7 starts stopped at
    Game Init, Frame 0, with XMemVirtualAlloc ... size=8294400 /
    13631488 ... largest_free_mb=0..6 and 0x80000003; minidump shows the
    window 100% taken (0x1C2DE00000 TileHeap + a second 6,236 MiB
    MEM_MAPPED view right beside it).
  • After (this change): the log shows
    the kept section view is above the title's window at=0x2000000000 — the
    view is at 128 GiB, outside [4 GiB, 2^37); 48 present windows / 626
    submissions 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 new
    the_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 old MapViewOfFile
    path (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 timing
    assertion), which passes 3/3 when run alone. It does not touch this code.
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings fails
    in victory-gpu (5 collapsible_if-style suggestions, e.g.
    host/menu.rs:669) — not files this change touches.
  • Not tested: Wine, Series S, and streaming-heavy gameplay longer than 60 s.

Checked for overlap

  • Searched open and closed pull requests for this crash and for
    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.
**@⁠lingbz112** on GitHub · 2026-12-01 14:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4935) `lingbz112:xmem-section-view-above-window` → `main` · +103 −0 · 1 files · 2 commits · open Related: #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 a DirectStorage 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 with `ERROR_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^37` and maps the section view into it (`MapViewOfFile3`, `MEM_REPLACE_PLACEHOLDER`); `VirtualAlloc2` with `MEM_ADDRESS_REQUIREMENTS` + `MEM_RESERVE_PLACEHOLDER` returns `ERROR_INVALID_PARAMETER` on 26300, so the walk finds the free run and the 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 - Machine: Intel Core i5-14600KF (6P+8E, 20 threads), 32 GB DDR5, ASUS ROG STRIX Z690-A GAMING WIFI, Windows 11 Pro 10.0.26300 (64-bit, native). - GPU: NVIDIA GeForce RTX 2080 Ti 11 GB, driver 32.0.16.2140 (GeForce 621.40). 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. - Profile: Series X files v1.0.2.1, 1440p target (1080p scene upscaled), DLSS balanced, frame generation 2x (auto), ray tracing off. - Before (release build, same files and settings): 7 of 7 starts stopped at Game Init, Frame 0, with `XMemVirtualAlloc ... size=8294400` / `13631488 ... largest_free_mb=0..6` and `0x80000003`; minidump shows the window 100% taken (`0x1C2DE00000` TileHeap + a second 6,236 MiB `MEM_MAPPED` view right beside it). - After (this change): the log shows `the kept section view is above the title's window at=0x2000000000` — the view is at 128 GiB, outside `[4 GiB, 2^37)`; 48 present windows / 626 submissions 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 new `the_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 old `MapViewOfFile` path (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 timing assertion), which passes 3/3 when run alone. It does not touch this code. - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` fails in `victory-gpu` (5 `collapsible_if`-style suggestions, e.g. `host/menu.rs:669`) — not files this change touches. - Not tested: Wine, Series S, and streaming-heavy gameplay longer than 60 s. ## Checked for overlap - [x] Searched open and closed pull requests for this crash and for `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.
Section::window() keeps one view of the whole page-pool section, so a
DirectStorage write does not map, commit and fault a view per page. It was
mapped wherever the host chose, and for a 6 GiB pool that address landed
inside [4 GiB, 2^37) - the title's own window - taking that much of it.

After the 8 GiB spare placed the title's 6,236 MiB TileHeap and was given
back, the view took what was left: the window had 0-6 MB free and the
title's next 8-13 MiB request was refused with ERROR_NOT_ENOUGH_MEMORY,
and the title asserted (0x80000003) at Game Init.

Reserve a placeholder with our own first-fit walk above 2^37 and map the
section into it (MapViewOfFile3, MEM_REPLACE_PLACEHOLDER). The view is ours
alone: no title address, and no shader reads it by page number, so the same
bytes are written and only the alias moves. Where the host gives no view
above 2^37 (Wine), window() maps it as before.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 14:44:57 +00:00
Author
Owner

@⁠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.

**@⁠gut0to** on GitHub · 2026-12-01 14:58 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4935#pullrequestreview-6133830315) · **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() {
Author
Owner

@⁠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 MapViewOfFile path, 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 confirm window() still returns a usable page through the fallback and protects this compatibility path.

**@⁠gut0to** on GitHub · 2026-12-01 14:58 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4935#discussion_r4756070103) 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 `MapViewOfFile` path, 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 confirm `window()` still returns a usable page through the fallback and protects this compatibility path.
A thread-local seam (`ABOVE_WINDOW_REFUSED`, `#[cfg(test)]` only) makes
`whole_view_above_window()` return None on the running test's thread, and
`a_refused_view_above_falls_back_to_the_old_mapping` maps a section through
`window()`, writes through the retained view and reads the bytes back
through the section's own view. Reviewed on #4935.
@ -1075,6 +1093,9 @@ impl Section {
return None;
}
let base = *self.window.get_or_init(|| {
if let Some(at) = self.whole_view_above_window() {
Author
Owner

@⁠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) makes
whole_view_above_window() return None on the running test's thread, so the
fallback 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_mapping maps a two-page section
through window() with the seam set, writes 8 bytes through the retained view
and reads them back through the section's own view, so the fallback is the
one MapViewOfFile path and the pages behind it are the section's.

cargo test -p victory-hle --lib a_refused_view_above_falls_back_to_the_old_mapping  ... 1 passed
cargo test -p victory-hle --lib window                                               ... 13 passed

The release build compiles the non-test stub (false), so nothing of the seam
is in a shipped binary.

**@⁠lingbz112** on GitHub · 2026-12-01 15:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4935#discussion_r4756149832) Good point - added in d567da7. A thread-local seam (`ABOVE_WINDOW_REFUSED`, `#[cfg(test)]` only) makes `whole_view_above_window()` return `None` on the running test's thread, so the fallback 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_mapping` maps a two-page section through `window()` with the seam set, writes 8 bytes through the retained view and reads them back through the section's own view, so the fallback is the one `MapViewOfFile` path and the pages behind it are the section's. ``` cargo test -p victory-hle --lib a_refused_view_above_falls_back_to_the_old_mapping ... 1 passed cargo test -p victory-hle --lib window ... 13 passed ``` The release build compiles the non-test stub (`false`), so nothing of the seam is in a shipped binary.
Author
Owner

@⁠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, head d567da7fca1c418e73038d97692d231600042d74. 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_window is 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.

$env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4935'
cargo test --locked -p victory-hle --lib -- modules::xmem::tests::a_refused_view_above_falls_back_to_the_old_mapping --exact --test-threads=1 --quiet
cargo test --locked -p victory-hle --lib -- modules::xmem::tests::the_retained_window_keeps_out_of_the_title_window --exact --test-threads=1 --quiet

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.

**@⁠cloph-dsp** on GitHub · 2026-12-01 15:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4935#issuecomment-7315600311) 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`, head `d567da7fca1c418e73038d97692d231600042d74`. `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_window` is 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. ``` $env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4935' cargo test --locked -p victory-hle --lib -- modules::xmem::tests::a_refused_view_above_falls_back_to_the_old_mapping --exact --test-threads=1 --quiet cargo test --locked -p victory-hle --lib -- modules::xmem::tests::the_retained_window_keeps_out_of_the_title_window --exact --test-threads=1 --quiet ``` 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.
Author
Owner

@⁠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).

**@⁠Dukestar69** on GitHub · 2026-12-01 16:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4935#pullrequestreview-6135367494) · **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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/4936/head:github-bot/gh-4935'
git switch 'github-bot/gh-4935'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4935'
git switch 'github-bot/gh-4935'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4935'
git switch 'github-bot/gh-4935'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4935'
git switch 'main'
git merge --squash 'github-bot/gh-4935'
git switch 'main'
git merge --ff-only 'github-bot/gh-4935'
git switch 'main'
git merge 'github-bot/gh-4935'
git push origin 'main'
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!4936
No description provided.