HLE: physical pages come from 2 MiB sections, so remaps stop waiting on Windows' large-page worker #3175

Open
KainanP wants to merge 4 commits from upstream-pr/3177 into main
KainanP commented 2026-11-26 11:12:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T11:12:15Z.


Problem

XMemAllocatePhysicalPages makes 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):

Who What One section per request 2 MiB sections
RyanCase94, RTX 4070 Ti (#1089) map/unmap calls of 1 ms or more in the first 90 s of the prison ~11,000, ~60 s 31, 55 ms
Exopus-0x65f7ad0, RTX 5060 Ti 16 GB RAM (#1089) remapping: summed over the opening cutscene 32-65 s (5 runs) 2.5 s (1 run)
Garu667, RTX 3080 (fork #1274) remapping per frame while driving 42.8 ms 5.0 ms
CuteBooty, RTX 3070 (fork #1274) texture refresh waiting on remaps per frame, worst wait 37 ms, 816 ms ~1 ms, 28-62 ms

The 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_MB MiB, 2 by default on Windows. 0 keeps 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, shown and the page table are unchanged. A run of pages (for a mapping, write_physical or a DirectStorage page_window) already stopped at an allocation boundary, and now it also stops at a section boundary. A window that would cross one returns None, and the caller's write_physical path handles it as before. The allocation moved into allocate_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 real XMemAllocatePhysicalPages / XMemMapPhysicalPages path. 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:

remaps/s median call p99 call calls of 1 ms or more (time)
one section (main's behaviour) 6,644 16.3 µs 4,093 µs 1,386 (8.6 s of 10 s)
2 MiB sections 50,607 14.4 µs 36.8 µs 28 (1.0 s)

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=0 against the default, watching long frames while streaming (cutscene, driving) more than the median.

Tests

  • New test 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_physical writes both bytes) and a 33-page XMemMapPhysicalPages (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

DirectStorage writes across sections

In one prison-intro run (Venom2054, RTX 5070 Ti, VICTORY_SECTION_MB=2), 7,531 of 96,578 physical-page writes (7.80%) touched more than one section. Those writes carried 3.56 of 6.40 GiB (55.6%). Of them, 583 (0.60% of all writes) were consecutive pages of one allocation, which had a single view before the split. With 2 MiB sections, such writes used to go through the staging buffer. Uncompressed requests are now copied into each section's pages in order, with no buffer (xmem::fill_physical). Compressed requests keep the single window or the buffer.

andrewpozdnakov7-jpg's section_size_directstorage_probe measured the memory-source path. The table gives medians of per-process p50s over 5 fresh processes in alternating order:

Destination range Before, one section Before, 2 MiB After, one section After, 2 MiB
64 KiB within a section 0.0190 ms 0.0200 ms 0.0188 ms 0.0189 ms
64 KiB crossing a section 0.0194 ms 0.0459 ms 0.0186 ms 0.0240 ms
Aligned 2 MiB 0.448 ms 0.445 ms 0.459 ms 0.454 ms
Unaligned 4 MiB 0.948 ms 1.82 ms 0.920 ms 0.942 ms
8 MiB at a 64 KiB boundary 1.98 ms 3.74 ms 1.94 ms 2.02 ms
<!-- greyfinch-sync:Marvisak/VIctory:issue:5508963571 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T11:12:15Z. --- ## Problem `XMemAllocatePhysicalPages` makes 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`): | Who | What | One section per request | 2 MiB sections | |---|---|---|---| | RyanCase94, RTX 4070 Ti (#1089) | map/unmap calls of 1 ms or more in the first 90 s of the prison | ~11,000, ~60 s | 31, 55 ms | | Exopus-0x65f7ad0, RTX 5060 Ti 16 GB RAM (#1089) | `remapping:` summed over the opening cutscene | 32-65 s (5 runs) | 2.5 s (1 run) | | Garu667, RTX 3080 (fork #1274) | remapping per frame while driving | 42.8 ms | 5.0 ms | | CuteBooty, RTX 3070 (fork #1274) | texture refresh waiting on remaps per frame, worst wait | 37 ms, 816 ms | ~1 ms, 28-62 ms | The 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_MB` MiB, **2 by default on Windows**. `0` keeps 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`, `shown` and the page table are unchanged. A run of pages (for a mapping, `write_physical` or a DirectStorage `page_window`) already stopped at an allocation boundary, and now it also stops at a section boundary. A window that would cross one returns `None`, and the caller's `write_physical` path handles it as before. The allocation moved into `allocate_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 real `XMemAllocatePhysicalPages` / `XMemMapPhysicalPages` path. 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: | | remaps/s | median call | p99 call | calls of 1 ms or more (time) | |---|---:|---:|---:|---:| | one section (main's behaviour) | 6,644 | 16.3 µs | 4,093 µs | 1,386 (8.6 s of 10 s) | | 2 MiB sections | **50,607** | 14.4 µs | **36.8 µs** | **28 (1.0 s)** | 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=0` against the default, watching long frames while streaming (cutscene, driving) more than the median. ## Tests - New test `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_physical` writes both bytes) and a 33-page `XMemMapPhysicalPages` (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](https://claude.com/claude-code) ### DirectStorage writes across sections In one prison-intro run (Venom2054, RTX 5070 Ti, `VICTORY_SECTION_MB=2`), 7,531 of 96,578 physical-page writes (7.80%) touched more than one section. Those writes carried 3.56 of 6.40 GiB (55.6%). Of them, 583 (0.60% of all writes) were consecutive pages of one allocation, which had a single view before the split. With 2 MiB sections, such writes used to go through the staging buffer. Uncompressed requests are now copied into each section's pages in order, with no buffer (`xmem::fill_physical`). Compressed requests keep the single window or the buffer. andrewpozdnakov7-jpg's `section_size_directstorage_probe` measured the memory-source path. The table gives medians of per-process p50s over 5 fresh processes in alternating order: | Destination range | Before, one section | Before, 2 MiB | After, one section | After, 2 MiB | | --- | ---: | ---: | ---: | ---: | | 64 KiB within a section | 0.0190 ms | 0.0200 ms | 0.0188 ms | 0.0189 ms | | 64 KiB crossing a section | 0.0194 ms | 0.0459 ms | 0.0186 ms | 0.0240 ms | | Aligned 2 MiB | 0.448 ms | 0.445 ms | 0.459 ms | 0.454 ms | | Unaligned 4 MiB | 0.948 ms | 1.82 ms | 0.920 ms | 0.942 ms | | 8 MiB at a 64 KiB boundary | 1.98 ms | 3.74 ms | 1.94 ms | 2.02 ms |
Dukestar69 commented 2026-11-26 13:11:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:11:04Z.

Review: APPROVED


Verified against origin/main (63bcca4):

  • cargo test -p victory-hle --lib modules::xmem:: -- --test-threads=1: 15/15 passed (1 ignored bench; including sections_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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074699972 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#pullrequestreview-6074699972). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T13:11:04Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-hle --lib modules::xmem:: -- --test-threads=1`: 15/15 passed (1 ignored bench; including `sections_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 commented 2026-11-26 14:01:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T13:59:17Z.


Independent local verification of head 5b7611a on 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194114925 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7194114925). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T13:59:17Z. --- Independent local verification of head `5b7611a` on 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 commented 2026-11-26 15:02:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T14:58:27Z.


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 with VICTORY_SECTION_MB=0 and 2. 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.

Destination range One section 2 MiB sections
64 KiB within a section 0.0324 ms 0.0326 ms
64 KiB crossing a section 0.0377 ms 0.0556 ms
Aligned 2 MiB 0.780 ms 0.835 ms
Unaligned 4 MiB 2.01 ms 4.17 ms
8 MiB at a 64 KiB boundary 4.26 ms 8.11 ms

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. Set VICTORY_SECTION_MB to 0 or 2 for a fresh run of cargo 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195598662 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7195598662). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T14:58:27Z. --- 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 with `VICTORY_SECTION_MB=0` and `2`. 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. | Destination range | One section | 2 MiB sections | | --- | ---: | ---: | | 64 KiB within a section | 0.0324 ms | 0.0326 ms | | 64 KiB crossing a section | 0.0377 ms | 0.0556 ms | | Aligned 2 MiB | 0.780 ms | 0.835 ms | | Unaligned 4 MiB | 2.01 ms | 4.17 ms | | 8 MiB at a 64 KiB boundary | 4.26 ms | 8.11 ms | 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`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/f74d1c449cf4bf3554a6b698381eca5f702282e8). Set `VICTORY_SECTION_MB` to 0 or 2 for a fresh run of `cargo 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 commented 2026-11-26 20:19:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T20:19:48Z.


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 in 9bfd4aac:

  • A page count too large to multiply set *count = 0. Before, the count was left as it was. New test a_count_too_large_is_refused_as_before fails on 5b7611a and passes now.
  • The debug line was logged before the host call instead of after it.
  • The failure warn line gained a size field. It is kept only when the request is split.
  • Page numbers were written to the title's array after the page-table lock was released. Before, each number was written as its page went in.

cargo test --locked -p victory-hle passes (154 tests, 1 ignored). cargo clippy -p victory-hle --all-targets -D warnings is clean, and the asset policy check passes. Synthetic tests only. Not run in game.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202542928 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7202542928). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T20:19:48Z. --- 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 in 9bfd4aac: - A page count too large to multiply set `*count = 0`. Before, the count was left as it was. New test `a_count_too_large_is_refused_as_before` fails on 5b7611a and passes now. - The `debug` line was logged before the host call instead of after it. - The failure `warn` line gained a `size` field. It is kept only when the request is split. - Page numbers were written to the title's array after the page-table lock was released. Before, each number was written as its page went in. `cargo test --locked -p victory-hle` passes (154 tests, 1 ignored). `cargo clippy -p victory-hle --all-targets -D warnings` is clean, and the asset policy check passes. Synthetic tests only. Not run in game. _AI use: Claude Code (Claude Opus 5.5)._
Venom2054 commented 2026-11-27 00:20:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Venom2054 on 2026-11-27T00:20:38Z.


I measured the destination distribution requested in the DirectStorage benchmark comment. This is one Windows / RTX 5070 Ti prison-intro run with VICTORY_SECTION_MB=2 on a local renderer build incorporating this PR at 9bfd4aa. The sample goes from launch through about 133 seconds after entering the 3D scene.

Requested output size Successful physical-page writes Writes touching multiple backing sections
Under 2 MiB 96,319 7,272
2–4 MiB inclusive 259 259
Above 4 MiB 0 0
Total 96,578 7,531 (7.80%)

Those 7,531 requests accounted for 3.56 of 6.40 GiB written (55.61%), counting the entire payload of each crossing request. Of those, 583 requests (0.60% of all writes) followed consecutive pages of a single original allocation. The other 6,948 already had a gap or changed original allocation. That distinction matters when estimating how many writes lose the contiguous-page fast path specifically because of the split.

The counter records a request once after a successful write and compares the actual backing sections of the destination pages in order. All counted writes were file-sourced and completed in full. Ordinary virtual-address destinations are outside the denominator. These are workload counts; the time cost of staging those requests would need a separate measurement. AI-assisted measurement and analysis.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7206380913 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7206380913). Originally posted by [Venom2054](https://github.com/Venom2054) on 2026-11-27T00:20:38Z. --- I measured the destination distribution requested in the [DirectStorage benchmark comment](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7195598662). This is one Windows / RTX 5070 Ti prison-intro run with `VICTORY_SECTION_MB=2` on a local renderer build incorporating this PR at `9bfd4aa`. The sample goes from launch through about 133 seconds after entering the 3D scene. | Requested output size | Successful physical-page writes | Writes touching multiple backing sections | | --- | ---: | ---: | | Under 2 MiB | 96,319 | 7,272 | | 2–4 MiB inclusive | 259 | 259 | | Above 4 MiB | 0 | 0 | | **Total** | **96,578** | **7,531 (7.80%)** | Those 7,531 requests accounted for **3.56 of 6.40 GiB written (55.61%)**, counting the entire payload of each crossing request. Of those, **583 requests (0.60% of all writes)** followed consecutive pages of a single original allocation. The other 6,948 already had a gap or changed original allocation. That distinction matters when estimating how many writes lose the contiguous-page fast path specifically because of the split. The counter records a request once after a successful write and compares the actual backing sections of the destination pages in order. All counted writes were file-sourced and completed in full. Ordinary virtual-address destinations are outside the denominator. These are workload counts; the time cost of staging those requests would need a separate measurement. AI-assisted measurement and analysis.
KainanP commented 2026-11-27 13:01:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T13:01:14Z.


Thanks @andrewpozdnakov7-jpg for the benchmark and @Venom2054 for the distribution. Both changed the PR.

Venom2054's numbers show that 7.8% of physical-page writes touched more than one section. Those writes carried 55.6% of the bytes. Only 583 writes (0.60%) were consecutive pages of one allocation that lost the one-view path because of the split. The benchmark showed what that path costs: the staging buffer roughly doubled the time for large writes.

Change (95c854e3): uncompressed requests into physical pages no longer go through the buffer. xmem::fill_physical maps one view per run of one section's pages, in order, and reads that run's part of the source (memory or file) directly into it. write_physical now uses the same code with a slice as the source, so the bytes land where the buffered path put them for any page list. This includes the 6,948 crossing writes that already had gaps. Compressed requests still use the single window or the buffer, because a decoder needs its whole output in one slice. A view that fails part way falls back to the buffer as before. A file that ends early fails the request with END_OF_FILE. Nothing outside the destination is written in either case.

Your benchmark, cherry-picked with your authorship (87c6020e). Release build, Windows 11. Each setting ran in 5 fresh processes in alternating order. The table gives the median of the per-process p50s. The before and after runs were back to back on the same machine. My absolute times are lower than yours:

Destination range Before, one section Before, 2 MiB After, one section After, 2 MiB
64 KiB within a section 0.0190 ms 0.0200 ms 0.0188 ms 0.0189 ms
64 KiB crossing a section 0.0194 ms 0.0459 ms 0.0186 ms 0.0240 ms
Aligned 2 MiB 0.448 ms 0.445 ms 0.459 ms 0.454 ms
Unaligned 4 MiB 0.948 ms 1.82 ms 0.920 ms 0.942 ms
8 MiB at a 64 KiB boundary 1.98 ms 3.74 ms 1.94 ms 2.02 ms

With 2 MiB sections, 4 MiB and 8 MiB writes now take about the same time as with one section. A 64 KiB crossing write still costs about 5 µs more, because it maps a second view. The benchmark's direct column still reports whether a single view fits. Its byte and sentinel checks pass at both settings.

New tests:

  • copies_across_sections_need_no_buffer: copies across 2 to 5 sections, from memory and from a file, with aligned and unaligned starts and ends. It checks every destination byte, the bytes on both sides, and that no buffer was used.
  • copies_across_sections_fail_whole: a file that ends early (END_OF_FILE); a view that fails once (the buffered retry writes every byte); a view that always fails (E_INVALIDARG); an unknown page (nothing written, and the queued status is E_INVALIDARG). No case writes a byte outside the destination.

cargo test --locked -p victory-hle --lib passes: 156 passed, 2 ignored. cargo clippy -p victory-hle --all-targets -D warnings is clean with default features and with --all-features. The asset policy check passes. Synthetic tests only. Not run in game.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218958573 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7218958573). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T13:01:14Z. --- Thanks @andrewpozdnakov7-jpg for the benchmark and @Venom2054 for the distribution. Both changed the PR. Venom2054's numbers show that 7.8% of physical-page writes touched more than one section. Those writes carried 55.6% of the bytes. Only 583 writes (0.60%) were consecutive pages of one allocation that lost the one-view path because of the split. The benchmark showed what that path costs: the staging buffer roughly doubled the time for large writes. Change (95c854e3): uncompressed requests into physical pages no longer go through the buffer. `xmem::fill_physical` maps one view per run of one section's pages, in order, and reads that run's part of the source (memory or file) directly into it. `write_physical` now uses the same code with a slice as the source, so the bytes land where the buffered path put them for any page list. This includes the 6,948 crossing writes that already had gaps. Compressed requests still use the single window or the buffer, because a decoder needs its whole output in one slice. A view that fails part way falls back to the buffer as before. A file that ends early fails the request with `END_OF_FILE`. Nothing outside the destination is written in either case. Your benchmark, cherry-picked with your authorship (87c6020e). Release build, Windows 11. Each setting ran in 5 fresh processes in alternating order. The table gives the median of the per-process p50s. The before and after runs were back to back on the same machine. My absolute times are lower than yours: | Destination range | Before, one section | Before, 2 MiB | After, one section | After, 2 MiB | | --- | ---: | ---: | ---: | ---: | | 64 KiB within a section | 0.0190 ms | 0.0200 ms | 0.0188 ms | 0.0189 ms | | 64 KiB crossing a section | 0.0194 ms | 0.0459 ms | 0.0186 ms | 0.0240 ms | | Aligned 2 MiB | 0.448 ms | 0.445 ms | 0.459 ms | 0.454 ms | | Unaligned 4 MiB | 0.948 ms | 1.82 ms | 0.920 ms | 0.942 ms | | 8 MiB at a 64 KiB boundary | 1.98 ms | 3.74 ms | 1.94 ms | 2.02 ms | With 2 MiB sections, 4 MiB and 8 MiB writes now take about the same time as with one section. A 64 KiB crossing write still costs about 5 µs more, because it maps a second view. The benchmark's `direct` column still reports whether a single view fits. Its byte and sentinel checks pass at both settings. New tests: - `copies_across_sections_need_no_buffer`: copies across 2 to 5 sections, from memory and from a file, with aligned and unaligned starts and ends. It checks every destination byte, the bytes on both sides, and that no buffer was used. - `copies_across_sections_fail_whole`: a file that ends early (`END_OF_FILE`); a view that fails once (the buffered retry writes every byte); a view that always fails (`E_INVALIDARG`); an unknown page (nothing written, and the queued status is `E_INVALIDARG`). No case writes a byte outside the destination. `cargo test --locked -p victory-hle --lib` passes: 156 passed, 2 ignored. `cargo clippy -p victory-hle --all-targets -D warnings` is clean with default features and with `--all-features`. The asset policy check passes. Synthetic tests only. Not run in game. _AI use: Claude Code (Claude Opus 5.5)._
kilolimaVI commented 2026-11-27 14:08:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T14:08:00Z.


Probe numbers from a laptop, since the PR has none yet: head 95c854e, Windows 11, Ryzen 7 8845HS (Radeon 780M), toolchain 1.98.1, --release -- section_size_directstorage_probe --ignored --nocapture, p50 / p95 of 31 runs after 4 warm-ups.

case VICTORY_SECTION_MB=0 (one window) VICTORY_SECTION_MB=2
64k-within 24.3 / 29.6 µs 18.3 / 20.9 µs (direct)
64k-across 18.6 / 20.5 µs 23.7 / 29.6 µs (split)
2m-aligned 489.4 / 866.0 µs 378.0 / 588.2 µs (direct)
4m-unaligned 852.8 / 914.5 µs 834.6 / 858.7 µs (split)
8m-aligned 1608.3 / 1756.9 µs 1589.1 / 1700.5 µs (split)

So the split copy into 2 MiB sections costs about the same as a single window at 4 and 8 MiB, and about 5 µs more for a 64 KiB copy straddling a section. cargo test -p victory-hle --lib --locked -- dstorage xmem --test-threads=1: 34 passed, 2 ignored. One run of the probe each, so the small cases are within noise.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220383444 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7220383444). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T14:08:00Z. --- Probe numbers from a laptop, since the PR has none yet: head 95c854e, Windows 11, Ryzen 7 8845HS (Radeon 780M), toolchain 1.98.1, `--release -- section_size_directstorage_probe --ignored --nocapture`, p50 / p95 of 31 runs after 4 warm-ups. | case | `VICTORY_SECTION_MB=0` (one window) | `VICTORY_SECTION_MB=2` | |---|---|---| | 64k-within | 24.3 / 29.6 µs | 18.3 / 20.9 µs (direct) | | 64k-across | 18.6 / 20.5 µs | 23.7 / 29.6 µs (split) | | 2m-aligned | 489.4 / 866.0 µs | 378.0 / 588.2 µs (direct) | | 4m-unaligned | 852.8 / 914.5 µs | 834.6 / 858.7 µs (split) | | 8m-aligned | 1608.3 / 1756.9 µs | 1589.1 / 1700.5 µs (split) | So the split copy into 2 MiB sections costs about the same as a single window at 4 and 8 MiB, and about 5 µs more for a 64 KiB copy straddling a section. `cargo test -p victory-hle --lib --locked -- dstorage xmem --test-threads=1`: 34 passed, 2 ignored. One run of the probe each, so the small cases are within noise. AI-assisted (Claude).
KainanP commented 2026-11-29 12:06:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-29T12:06:42Z.


@kilolimaVI thanks for the AMD laptop numbers. They agree with the PR's "cost when nothing stalls" section: a split copy at 4 and 8 MiB costs about the same as one window, and a 64 KiB copy across a section boundary costs a few µs more. Your probe had no allocation churn running alongside, so the rebuild worker stall this PR targets wouldn't show up in it.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7255574524 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3177#issuecomment-7255574524). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-29T12:06:42Z. --- @kilolimaVI thanks for the AMD laptop numbers. They agree with the PR's "cost when nothing stalls" section: a split copy at 4 and 8 MiB costs about the same as one window, and a 64 KiB copy across a section boundary costs a few µs more. Your probe had no allocation churn running alongside, so the rebuild worker stall this PR targets wouldn't show up in it. _AI use: Claude Code (Claude Opus 5.5)._
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3177:upstream-pr/3177'
git switch 'upstream-pr/3177'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3177'
git switch 'upstream-pr/3177'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3177'
git switch 'upstream-pr/3177'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3177'
git switch 'main'
git merge --squash 'upstream-pr/3177'
git switch 'main'
git merge --ff-only 'upstream-pr/3177'
git switch 'main'
git merge 'upstream-pr/3177'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3175
No description provided.