HLE: physical pages come from 2 MiB sections, so remaps stop waiting on Windows' large-page worker #3177
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3177
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3177"
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?
@KainanP on GitHub · 2026-11-26 11:12 UTC · original
KainanP:perf/physical-sections-2mib→main· +319 −40 · 2 files · 2 commits · openProblem
XMemAllocatePhysicalPagesmakes one pagefile-backed section per request. Grand Theft Auto VI asks for 6.1 GiB in one call and maps it one 64 KiB view at a time, so that one section ends up with views by the hundred thousand. Windows' large-page rebuild worker (MiRebuildLargePages→MiTradePage→MiTrimSection) trades a section's pages one at a time. For each page it walks the section's views (MiViewMayContainPage) while it holds the section's lock. The title's map and unmap calls (MiInsertVad,MiDeleteVad) wait behind that lock.RyanCase94 traced this with xperf on fxceless/victory-fork#1089. Fork testers then measured it in the game. Main has the same allocation and mapping code (
xmem.rs):remapping:summed over the opening cutsceneThe median frame time did not change in those runs. What changed was the long frames: the 0.3-0.8 s freezes while driving, and HLVM04's p90 went from about 118 ms to 105 ms.
Change
A request is now backed by sections of at most
VICTORY_SECTION_MBMiB, 2 by default on Windows.0keeps one section per request, and that stays the default under Wine, where sections are committed sparse files and this stall does not apply. Page numbers,views,shownand the page table are unchanged. A run of pages (for a mapping,write_physicalor a DirectStoragepage_window) already stopped at an allocation boundary, and now it also stops at a section boundary. A window that would cross one returnsNone, and the caller'swrite_physicalpath handles it as before. The allocation moved intoallocate_physical(n, per)so that tests can pick the section size.The idea and first patch come from RyanCase94 (fxceless/victory-fork#1089). CuteBooty ported it to the fork, off by default there (fxceless/victory-fork#1274). The fork kept it off because of its in-place heap census, which needs whole sections. Main has no such code, which is why this PR turns it on by default. It is a one-line change if you prefer it off.
Measured (synthetic, no game)
physical_remap_bench(included,#[ignore]) runs the realXMemAllocatePhysicalPages/XMemMapPhysicalPagespath. It maps 4 GiB a page per view and touches every page. It then remaps a random page at a random address for 10 s while another thread allocates, touches and frees 2 GiB, the kind of memory churn that wakes the rebuild worker. The run alternates the two modes over 5 rounds in one process.i7-14650HX, 32 GB, Windows 11 26200, release build, median of 5 rounds:
Per round, one section ran 3,033 / 58,814 / 16,898 / 6,644 / 3,134 remaps/s. In one round of five the worker did not run, and the two modes were then equal. 2 MiB sections ran 46,726-54,744 remaps/s in every round. A standalone version (raw
MapViewOfFile3, no VIctory code) gives the same picture: 1,784 calls of 1 ms or more against 45 in 15 s. With a thread that only empties the working set and makes no allocations, neither mode stalls. So the trigger is memory being made and freed, which a streaming title does constantly.Cost when nothing stalls: with no other thread making memory (
VICTORY_SECTION_BENCH=4096,5,3,0), 2 MiB sections are about 8 % slower per remap (median 10.0 µs against 9.1 µs; 77,858 against 84,785 remaps/s). A request of 6.1 GiB also costs about 3,100 section handles instead of one.Not measured: the game itself (I don't run it), and Wine (unchanged there by default). The in-game numbers above come from the fork, not from main. It would help if a game owner could run an A/B on main with
VICTORY_SECTION_MB=0against the default, watching long frames while streaming (cutscene, driving) more than the median.Tests
sections_hold_at_most_the_pages_asked: 33 pages give runs[33]or[32, 1]with consecutive numbers. It also covers a two-byte write across the 2 MiB boundary (no window in place,write_physicalwrites both bytes) and a 33-pageXMemMapPhysicalPages(two views, both bytes visible, writes through the view land in the right page). It then unmaps everything back to a reservation.cargo test --locked -p victory-hle: 153 passed, 1 ignored (the benchmark). The existing xmem tests now run with the 2 MiB default.cargo clippy --locked -p victory-hle --all-targets -- -D warnings, with and without--all-features: clean.cargo check --workspace --all-targets: clean.cargo xtask policy: 191 files ok. rustfmt: the lines I added are formatted, and the file's other rustfmt differences come from main.AI use: Claude Code (Claude Opus 5.5) wrote the port, the benchmark and this description, and ran the measurements on my machine. No game files or game-derived data were used.
🤖 Generated with Claude Code
@Dukestar69 on GitHub · 2026-11-26 13:11 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-hle --lib modules::xmem:: -- --test-threads=1: 15/15 passed (1 ignored bench; includingsections_hold_at_most_the_pages_asked).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly caps physical page backing sections at 2 MiB to avoid large-page section lock contention on Windows remaps.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@cloph-dsp on GitHub · 2026-11-26 13:59 UTC · original
Independent local verification of head
5b7611aon Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-hle --lib -- modules::xmem::tests::sections_hold_at_most_the_pages_asked --exact— 1 passed, 0 failed.git diff --check origin/main HEAD— clean.Used a worktree-local
CARGO_TARGET_DIR. Synthetic page-count inputs only; no game files, extracted shaders or DRM material used. AI-assisted (Hy4 flash). GPU/driver N/A (CPU-only HLE test).@andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:58 UTC · original
I measured the DirectStorage side of the section-size change on exact
5b7611a(Windows 10 19045, release). The same executable ran the real uncompressed memory-source request path withVICTORY_SECTION_MB=0and2. Each setting ran in five fresh processes, alternating order, with four warmups and 31 measured calls per case. The table gives the median of the five per-process medians.The cross-section cases used the staging-buffer fallback with the 2 MiB setting. All checked destination bytes and both adjacent sentinels matched. The 16 existing DirectStorage tests passed at that setting. These timings cover RAM-to-page writes under a synthetic load. The title's request sizes, file and decompression times, and your measured map/unmap stall are separate measurements.
The reproducible ignored benchmark is
f74d1c4. SetVICTORY_SECTION_MBto 0 or 2 for a fresh run ofcargo test --release --locked -p victory-hle --lib section_size_directstorage_probe -- --ignored --nocapture. If you have a representative DirectStorage destination-size trace, the share of requests crossing the 2 MiB boundary would help weigh this cost against the remap improvement.Please retain the Git author if reusing the benchmark, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit.@KainanP on GitHub · 2026-11-26 20:19 UTC · original
Checked this PR against the regression reported in LooperSalty/AnyXboxX#428. The AnyXboxX port of this change (#352 there) caused a TDR on an RTX 3080 Ti even with the switch unset. The cause was on the GPU side: the AnyXboxX port added a hook that unmapped our own view of a section as soon as the section closed. This PR has no GPU side: no close hook, no unmap. So that bug does not apply here.
I did find small differences in the one-section path (
VICTORY_SECTION_MB=0, and Wine), fixed in9bfd4aac:*count = 0. Before, the count was left as it was. New testa_count_too_large_is_refused_as_beforefails on5b7611aand passes now.debugline was logged before the host call instead of after it.warnline gained asizefield. It is kept only when the request is split.cargo test --locked -p victory-hlepasses (154 tests, 1 ignored).cargo clippy -p victory-hle --all-targets -D warningsis clean, and the asset policy check passes. Synthetic tests only. Not run in game.AI use: Claude Code (Claude Opus 5.5).
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.