Repository navigation
HLE: physical pages come from 2 MiB sections, so remaps stop waiting on Windows' large-page worker - #3177
HLE: physical pages come from 2 MiB sections, so remaps stop waiting on Windows' large-page worker#3177KainanP wants to merge 2 commits into
Conversation
…on Windows' large-page worker XMemAllocatePhysicalPages made one pagefile-backed section per request (Grand Theft Auto VI asks for 6.1 GiB at once), and the title maps it a 64 KiB view at a time, so that one section carries views by the hundred thousand. Windows' large-page rebuild worker trades a section's pages one by one and walks the section's views under its lock for each, holding every map and unmap of title physical memory meanwhile (fxceless/victory-fork#1089, kernel trace by RyanCase94). A request is now backed by sections of at most VICTORY_SECTION_MB MiB (default 2 on Windows; 0 keeps one section per request, the default under Wine, whose sections are committed sparse files). Page numbering, views and the page table are unchanged; a run of pages for a mapping or a DirectStorage window stops at a section boundary, as it already did at an allocation boundary. Synthetic benchmark included (ignored test physical_remap_bench): 4 GiB mapped a page per view, single-page remaps for 10 s while another thread makes, touches and frees 2 GiB. i7-14650HX, 32 GB, Windows 11, median of 5 rounds: one section 6,644 remaps/s and 1,386 remaps of 1 ms or more (8.6 s of the 10 s); 2 MiB sections 50,607 remaps/s and 28 (1.0 s). Idea and first patch: RyanCase94 (fxceless/victory-fork#1089); fork port by CuteBooty (fxceless/victory-fork#1274). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dukestar69
left a comment
There was a problem hiding this comment.
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).
|
Independent local verification of head
Used a worktree-local |
…Y_SECTION_MB) Ported from Marvisak/VIctory#3177 (5b7611ae0 by KainanP, after RyanCase94 and CuteBooty). When VICTORY_SECTION_MB=<mb> is set (e.g. 2), XMemAllocatePhysicalPages backs physical pages with <mb>-MiB sections instead of one giant section so Windows page/view remaps avoid section-wide large-page rebuild stalls. Off by default.
|
I measured the DirectStorage side of the section-size change on exact
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 Please retain the Git author if reusing the benchmark, or add |
…s before The split allocator changed the one-section path in small ways: a page count too large to multiply set the title's count to 0 (before: left as it was), the debug line came before the host call instead of after it, the failure line gained a size field, and page numbers were written to the title after the page table's lock was let go instead of as each page went in. make_sections/number_pages keep the old order and lines for one section per request; test a_count_too_large_is_refused_as_before fails on the previous head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 (
AI use: Claude Code (Claude Opus 5.5). |
Problem
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