Skip to content

perf(victory): physical pages from 2 MiB sections (VICTORY_SECTION_MB, off by default) - #352

Merged
LooperSalty merged 2 commits into
LooperSalty:mainfrom
KainanP:perf/physical-sections-2mib
Nov 26, 2026
Merged

LooperSalty merged 2 commits into
LooperSalty:mainfrom
KainanP:perf/physical-sections-2mib

Conversation

@KainanP

@KainanP KainanP commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Change

VICTORY_SECTION_MB=2 backs each XMemAllocatePhysicalPages request with pagefile-backed sections of at most 2 MiB. Today a request gets one section: 6.1 GiB in a single call for GTA VI. Off by default. Unset or 0 runs today's code path.

The cost being fixed: the title maps that one section a 64 KiB view at a time, so the section carries a very large number of views. Windows' large-page rebuild worker (MiRebuildLargePages → MiTradePage → MiTrimSection) trades the section's pages one at a time, and for each page it walks the section's views while holding the section's lock. The title's map and unmap calls wait behind it. RyanCase94 found this in a kernel trace (fxceless/victory-fork#1089). The fork measured it in game, always against the fork's own base:

  • RyanCase94 (#1089): map/unmap calls of 1 ms or more dropped from about 11,000 (60 s) to 31 (55 ms).
  • Exopus (#1089): remapping: summed over the opening cutscene dropped from 32-65 s to 2.5 s.
  • Garu667 (fork #1274): remapping went from 42.8 to 5.0 ms a frame, with the same median fps.
  • CuteBooty (fork #1274): the 0.3-0.8 s freezes while driving went away.

The median frame did not change in those runs. The gain is in long frames while the world streams, which matches the dips described in the README's known limits.

GPU side (inplace.rs):

  • sections and ALIASES (our own views of a title section, VICTORY_QUIET_BACK) are now maps keyed by handle. They used to be vectors scanned linearly, and with 2 MiB sections there are thousands of entries.
  • A section's own view is unmapped when the section closes (title_memory_section_closed). Before, it stayed until the handle number came round again. A copy that is still writing through such a view faults and falls back, through the existing write_alias handler.
  • The census groups sections by size.

This is a port of fxceless/victory-fork#1274 (CuteBooty), which comes from RyanCase94's patch in #1089. Both are credited in THIRD_PARTY.md and in the commit's Source: line.

Linked issue: none (upstream: fxceless/victory-fork#1089; the same change for Marvisak/VIctory is #3177 there).

Verification

Windows 11 26200, i7-14650HX, 32 GB, Rust 1.98.1 MSVC, from third_party/victory:

cargo test --locked -p victory-hle --lib                          -> 111 passed, 1 ignored (the benchmark)
VICTORY_SECTION_MB=2 cargo test --locked -p victory-hle --lib     -> 111 passed, 1 ignored
cargo test --locked -p victory-gpu --lib inplace                  -> 6 passed
cargo clippy --locked -p victory-gpu -p victory-hle --all-targets -> no warning in the changed files
python -m pytest tests/test_lanceur_victory.py tests/test_resume_journal_victory.py -> 58 passed

cargo clippy ... -D warnings stops at an existing redundant_closure in victory-formats/src/texture.rs, which is also on main.

New test sections_hold_at_most_the_pages_asked:

  • 33 pages give runs [33] or [32, 1], with consecutive page numbers.
  • A two-byte write across the 2 MiB boundary gets no in-place window, and write_physical still writes both bytes.
  • A 33-page XMemMapPhysicalPages makes two views. Both bytes are visible through them, and a write through the view lands in the right page.

Measured (synthetic, no game)

physical_remap_bench (#[ignore]) goes through the real XMemAllocatePhysicalPages and XMemMapPhysicalPages. It maps 4 GiB one page per view and touches every page. It then remaps a random page at a random address for 10 s, while another thread makes, touches and frees 2 GiB. It runs 5 rounds per mode, alternating.

cargo test --locked --release -p victory-hle --lib physical_remap_bench -- --ignored --nocapture
Tree Mode Rounds where the worker stalled Remaps/s in those rounds Calls of 1 ms or more, summed over 5 rounds
this branch one section per request 2 of 5 2,053 and 5,892 21.8 s of 50 s
this branch 2 MiB sections 0 of 5 36,258-40,417 in all rounds 6.0 s of 50 s
upstream VIctory port one section per request 4 of 5 3,033-16,898 34.6 s of 50 s
upstream VIctory port 2 MiB sections 0 of 5 46,726-54,744 in all rounds 4.5 s of 50 s

In rounds where the worker did not run, the two modes measure the same. The roughly 30 slow calls a round that both modes show come from the busy machine, not from the sections. Without the churn thread, 2 MiB sections cost about 8 % per remap (10.0 µs against 9.1 µs median, upstream port).

Not measured: the game. Could you A/B it with the launcher's override, -Override @{ VICTORY_SECTION_MB = '2' }? Look at the frame log's remapping: field and the longest frames while driving or in a cutscene, more than the median. If it holds up, it belongs in the tuned set. I left the launcher, its test and the docs unchanged so that this PR stays one behaviour.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it: not applicable as such. This is a speed change behind a switch, so the new test checks that the split keeps pages, writes and views right, and the benchmark shows the gain.
  • The commands and results of each check are given above.
  • No game, console or SDK file, no key, no dump, no download link.
  • Code taken from another project: GPL-3.0, credit in THIRD_PARTY.md.

AI use: Claude Code (Claude Opus 5.5) did the port, the benchmark and this description, and ran the checks on my machine. No game files or game data.

🤖 Generated with Claude Code

…, off by default)

XMemAllocatePhysicalPages made one pagefile-backed section per request
(6.1 GiB at once for GTA VI), mapped a 64 KiB view at a time. Windows'
large-page rebuild worker walks every view of a section under its lock for
each page it trades, so the title's map and unmap calls wait behind it
(fxceless/victory-fork#1089). VICTORY_SECTION_MB=2 backs a request with
sections of at most 2 MiB; unset or 0 keeps one section per request.

GPU side: sections and our own views of them (VICTORY_QUIET_BACK) are kept
by handle in maps instead of vectors scanned linearly, a closed section's
own view is unmapped at once (title_memory_section_closed), and the census
groups sections by size.

Synthetic benchmark included (ignored test physical_remap_bench).

Source: fxceless/victory-fork#1274 (CuteBooty), idea and first patch from fxceless/victory-fork#1089 (RyanCase94)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants