perf(xmem): physical pages from sections of at most VICTORY_SECTION_MB MiB (off by default) #44

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

@⁠CLHelper on GitHub · 2026-11-27 13:38 UTC · original
CLHelper:perf/section-mb → main · +474 −68 · 3 files · 2 commits · open

What

XMemAllocatePhysicalPages makes one pagefile-backed section per request. The title asks for its 6.1 GiB of
physical pages in one call and then maps them a 64 KiB view at a time, so one section ends up with views by the
hundred thousand. Windows' large-page rebuild worker walks a section's views under that section's lock, and every
map and unmap of the title's pages waits behind it. That shows up as stalls when the camera turns or the player
moves.

VICTORY_SECTION_MB=<n> backs each request with sections of at most n MiB (2 is the measured value). The pages are
still numbered as one request. Unset, 0 or not a number keeps one section per request: same calls, same numbers.
Off by default.

  • xmem/section_mb.rs (new): the switch and allocate_physical(n, per), which makes the sections, reports each one
    to the GPU side and numbers the pages consecutively. Each section keeps its own window and is closed
    (title_memory_section_gone) when its last page goes, as before.
  • xmem.rs: XMemAllocatePhysicalPages calls it. Nothing else changes: a mapping or a write already ends a run at a
    section's end, and a DirectStorage destination that crosses a bound gets no window and goes through
    write_physical, run by run.
  • inplace.rs: sections and our whole views of them are kept in maps by handle instead of vectors scanned on every
    lookup (with the switch on, a request is about 3,100 sections). Census lines group alike sections; a section that
    is one of a kind prints as before.

Measured (with the switch on: same change on an earlier main, 6a31e431e)

RTX 4060 Laptop GPU (8 GB), 31 GB RAM, Windows 11. The host was left as it was (a browser open, two screens). Two
pairs, one run per arm. Mapping cost comes from the title's mapping calls (ms spent in them per second of play).

pair a, off pair a, 2 MiB pair b, off pair b, 2 MiB
time in mapping calls, whole run 55.5 s 7.3 s 17.8 s 5.9 s
waits on the section lock, whole run 26.6 s 0.6 s 6.5 s 0.4 s
worst second of mapping calls (after 60 s) 1,950 ms 264 ms 1,657 ms 442 ms
standing frame time in the world 82.1 ms 74.7 ms 75.9 ms 72.9 ms
world entry 66.2 s 45.0 s 56.1 s 50.3 s

No device removals or exceptions in any of the four runs.

Caveats:

  • One run per arm. Pair b ran hands-off; in pair a the player skipped a cutscene and moved around in the 2 MiB run
    only, so pair a's frame times are not a clean A/B (the mapping and lock numbers are the point there).
  • The numbers come from 6a31e431e. Since then xmem.rs gained renderer port 1 (VICTORY_PORT_CONSTANTS). On
    959dcaf60 this change is built and unit-tested only; it has not been measured in the title on this base.
  • Not for use together with VICTORY_PORT_CONSTANTS=1. Port 1 needs the 32-bit heap's pages in one section. With
    VICTORY_SECTION_MB set, arrange() logs its "not of one section as big as it" warning and leaves the pages where
    they are, so that heap stays on the copy path. Both are off by default. If port 1 becomes always on (#38), setting
    this switch turns port 1 off for that heap. There is no textual conflict with #38 (or with #33-#42).
  • Each DirectStorage destination that crosses a 2 MiB bound costs one extra copy (decode to a buffer, then write run
    by run). These copies are not counted separately here.
  • More sections means more kernel section objects and handles (about 3,100 for 6.1 GiB) and more views. Total commit
    does not change (still SEC_RESERVE, committed on first map or write).

Tests

cargo test -p victory-hle --lib section_mb (switch unset and VICTORY_SECTION_MB=2):

  • the switch's values;
  • 33 pages, whole vs 32+1: numbering, window and write over the bound, one call mapping two views;
  • 70 pages in 32/32/6, every section closed after free;
  • five pages in sections of two: mapped, written, partly unmapped and page-mapping-copied over the bounds;
  • the title call stays one section by default.

Plus physical_remap_bench (#[ignore = "benchmark"], title-free): it remaps single pages of a 4 GiB request while
another thread makes and frees 2 GiB, one section vs 2 MiB sections.

On this branch (Rust 1.98.1, offline, --features diagnostics for victory-gpu), next to the same commands on 959dcaf60:

  • section_mb: 5 passed, 1 ignored, with the switch unset and with it set to 2. If the per-section cap is dropped
    (let pages = n - made;), 3 of the 5 fail.
  • victory-hle --lib: 176 passed, 3 ignored (main: 171 passed, 2 ignored).
  • victory-gpu --lib: 460 passed, 2 failed, 35 ignored. This is the same on main: the two failures are
    indirect::tests::host_list_budget_starts_empty_at_each_submission and
    indirect::tests::warp_batch_charges_every_execution, and this change does not touch them.
  • cargo build --release -p victory --features diagnostics: builds, with the same 6 warnings as main.

Credit

This is a port. The finding and the cure are RyanCase94's and CuteBooty's (fxceless's fork, issue #1089, PR #1274).
The code follows voidopcode/vilocity 0f44a1706, whose xmem.rs matched this repository's. The tests follow KainanP
(Skyfrye/anyXboxx-diffbase ee8b92e14) and Xeltax (Xeltax/VIcky a8c223149).

AI-assisted.

**@⁠CLHelper** on GitHub · 2026-11-27 13:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/44) `CLHelper:perf/section-mb` → `main` · +474 −68 · 3 files · 2 commits · open ## What `XMemAllocatePhysicalPages` makes one pagefile-backed section per request. The title asks for its 6.1 GiB of physical pages in one call and then maps them a 64 KiB view at a time, so one section ends up with views by the hundred thousand. Windows' large-page rebuild worker walks a section's views under that section's lock, and every map and unmap of the title's pages waits behind it. That shows up as stalls when the camera turns or the player moves. `VICTORY_SECTION_MB=<n>` backs each request with sections of at most n MiB (2 is the measured value). The pages are still numbered as one request. Unset, `0` or not a number keeps one section per request: same calls, same numbers. **Off by default.** - `xmem/section_mb.rs` (new): the switch and `allocate_physical(n, per)`, which makes the sections, reports each one to the GPU side and numbers the pages consecutively. Each section keeps its own window and is closed (`title_memory_section_gone`) when its last page goes, as before. - `xmem.rs`: `XMemAllocatePhysicalPages` calls it. Nothing else changes: a mapping or a write already ends a run at a section's end, and a DirectStorage destination that crosses a bound gets no window and goes through `write_physical`, run by run. - `inplace.rs`: sections and our whole views of them are kept in maps by handle instead of vectors scanned on every lookup (with the switch on, a request is about 3,100 sections). Census lines group alike sections; a section that is one of a kind prints as before. ## Measured (with the switch on: same change on an earlier main, 6a31e431e) RTX 4060 Laptop GPU (8 GB), 31 GB RAM, Windows 11. The host was left as it was (a browser open, two screens). Two pairs, one run per arm. Mapping cost comes from the title's mapping calls (ms spent in them per second of play). | | pair a, off | pair a, 2 MiB | pair b, off | pair b, 2 MiB | |---|---|---|---|---| | time in mapping calls, whole run | 55.5 s | 7.3 s | 17.8 s | 5.9 s | | waits on the section lock, whole run | 26.6 s | 0.6 s | 6.5 s | 0.4 s | | worst second of mapping calls (after 60 s) | 1,950 ms | 264 ms | 1,657 ms | 442 ms | | standing frame time in the world | 82.1 ms | 74.7 ms | 75.9 ms | 72.9 ms | | world entry | 66.2 s | 45.0 s | 56.1 s | 50.3 s | No device removals or exceptions in any of the four runs. Caveats: - One run per arm. Pair b ran hands-off; in pair a the player skipped a cutscene and moved around in the 2 MiB run only, so pair a's frame times are not a clean A/B (the mapping and lock numbers are the point there). - The numbers come from 6a31e431e. Since then `xmem.rs` gained renderer port 1 (`VICTORY_PORT_CONSTANTS`). On 959dcaf60 this change is built and unit-tested only; it has not been measured in the title on this base. - Not for use together with `VICTORY_PORT_CONSTANTS=1`. Port 1 needs the 32-bit heap's pages in one section. With `VICTORY_SECTION_MB` set, `arrange()` logs its "not of one section as big as it" warning and leaves the pages where they are, so that heap stays on the copy path. Both are off by default. If port 1 becomes always on (#38), setting this switch turns port 1 off for that heap. There is no textual conflict with #38 (or with #33-#42). - Each DirectStorage destination that crosses a 2 MiB bound costs one extra copy (decode to a buffer, then write run by run). These copies are not counted separately here. - More sections means more kernel section objects and handles (about 3,100 for 6.1 GiB) and more views. Total commit does not change (still `SEC_RESERVE`, committed on first map or write). ## Tests `cargo test -p victory-hle --lib section_mb` (switch unset and `VICTORY_SECTION_MB=2`): - the switch's values; - 33 pages, whole vs 32+1: numbering, window and write over the bound, one call mapping two views; - 70 pages in 32/32/6, every section closed after free; - five pages in sections of two: mapped, written, partly unmapped and page-mapping-copied over the bounds; - the title call stays one section by default. Plus `physical_remap_bench` (`#[ignore = "benchmark"]`, title-free): it remaps single pages of a 4 GiB request while another thread makes and frees 2 GiB, one section vs 2 MiB sections. On this branch (Rust 1.98.1, offline, `--features diagnostics` for victory-gpu), next to the same commands on 959dcaf60: - `section_mb`: 5 passed, 1 ignored, with the switch unset and with it set to 2. If the per-section cap is dropped (`let pages = n - made;`), 3 of the 5 fail. - `victory-hle --lib`: 176 passed, 3 ignored (main: 171 passed, 2 ignored). - `victory-gpu --lib`: 460 passed, 2 failed, 35 ignored. This is the same on main: the two failures are `indirect::tests::host_list_budget_starts_empty_at_each_submission` and `indirect::tests::warp_batch_charges_every_execution`, and this change does not touch them. - `cargo build --release -p victory --features diagnostics`: builds, with the same 6 warnings as main. ## Credit This is a port. The finding and the cure are RyanCase94's and CuteBooty's (fxceless's fork, issue #1089, PR #1274). The code follows voidopcode/vilocity 0f44a1706, whose `xmem.rs` matched this repository's. The tests follow KainanP (Skyfrye/anyXboxx-diffbase ee8b92e14) and Xeltax (Xeltax/VIcky a8c223149). AI-assisted.
XMemAllocatePhysicalPages makes one pagefile-backed section per request
(6.1 GiB at once for the title), which it then maps a 64 KiB view at a
time. Windows' large-page rebuild worker walks a section's views under
the section's lock, so every map and unmap of the title's pages waits
behind it while the camera turns. VICTORY_SECTION_MB=<n> backs a request
with sections of at most n MiB (2 measured); unset, 0 or not a number
keeps one section per request: same calls, same numbers.

- xmem/section_mb.rs (new): the switch, and allocate_physical(n, per),
  which makes the sections, reports each to the GPU side and numbers the
  pages as one request. Each section keeps its own window and is closed
  (title_memory_section_gone) when its last page goes, as before.
- xmem.rs: XMemAllocatePhysicalPages calls it; nothing else changes. A
  mapping or a write already ends a run at a section's end; DirectStorage
  destinations over a bound get no window and go through write_physical.
- inplace.rs: sections and our whole views of them by handle in maps, not
  vectors scanned per lookup; census lines group alike sections (one of a
  kind reads as before, lines now in size order).

Not combined with VICTORY_PORT_CONSTANTS=1: renderer port 1 needs the
32-bit heap in one section; with the switch set, arrange() logs that the
pages are not of one section and leaves them, so the heap stays on the
copy path.

Tests: the switch's values; 33 pages whole vs 32+1 (numbering, window and
write over the bound, one call mapping two views); 70 pages in 32/32/6
with every section closed after free; five pages in sections of two
mapped, written, partly unmapped and page-mapping-copied over the bounds;
the title call stays one section by default.

Port of voidopcode/vilocity 0f44a1706; the finding and the cure are
RyanCase94's and CuteBooty's (fxceless's fork, issue #1089, PR #1274).
Tests after KainanP (Skyfrye/anyXboxx-diffbase ee8b92e14) and Xeltax
(Xeltax/VIcky a8c223149). AI-assisted.
physical_remap_bench maps a 4 GiB request a page at a time, then remaps
random single pages for 10 s while another thread makes, touches and
frees 2 GiB, for one section against 2 MiB sections (3 rounds). Test
code only: victory.exe is unchanged.

Adapted from KainanP's bench (Skyfrye/anyXboxx-diffbase ee8b92e14).
AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:49:41 +00:00
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/44/head:github-bot/gh-44'
git switch 'github-bot/gh-44'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-44'
git switch 'github-bot/gh-44'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-44'
git switch 'github-bot/gh-44'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-44'
git switch 'main'
git merge --squash 'github-bot/gh-44'
git switch 'main'
git merge --ff-only 'github-bot/gh-44'
git switch 'main'
git merge 'github-bot/gh-44'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.