xmem: page remaps skip the kernel calls that change nothing (VICTORY_REMAP_LEAN=1) #1069

Open
github-bot wants to merge 1 commit from github-bot/gh-1069 into main AGit
Owner

@⁠alexis27yt on GitHub · 2026-11-25 18:23 UTC · original
alexis27yt:remap-lean → main · +134 −20 · 1 files · 1 commits · open

Each page the title remaps (map_alias, ~850 a streaming frame per the README) takes four calls on the process's address space: unmap, split the placeholder, map, commit. Two of them change nothing in the common case:

  • the split fails every time the placeholder is already the range, as the title's one-page remaps leave it (10,200 of 10,200 in a measurement below);
  • committing a section page that a view already committed changes nothing.

With VICTORY_REMAP_LEAN=1 (off by default) the view is mapped first and the placeholder split only if that fails, and section pages committed once are not committed again. One bit a page is kept inside the Section, so it lives and dies with the section and a reused page number starts clear. Two calls a remap instead of four.

Measured outside the title on an i5-12400F: a harness that repeats the same four calls (850 one-page remaps a frame over a 256 MiB SEC_RESERVE section into one-page placeholders):

contention today (4 calls) lean (2 calls)
none 5.0 µs/remap 3.0 µs
4 threads VirtualProtect 4 KiB 6.3 µs 5.6 µs
1 thread GetWriteWatch(RESET) of 1 GiB 19.9 µs 9.6 µs

Honest scope: that is ~2-9 ms of a streaming frame, against the 246 ms of remapping the README measures in game. The calls themselves are not where that time goes. Even beside a 1 GiB write-watch asking (~5 ms each), a remap averaged 10-20 µs here, not the ~290 µs per page seen in game. So the rest is waiting on something this harness does not reproduce: the MAPPING lock behind in-place readers, or a longer holder of the address space. The frame log's RemapWaitUs against RemapUs from a streaming scene would tell which.

shortcut: a page the title itself decommits through one of its views would still be noted committed (documented at the switch); no title is known to do that with physical pages.

Tests: new a_section_notes_the_pages_committed_through_it; all 13 xmem tests (real mappings) pass with and without the switch on the i5-12400F. Clippy: no new warnings.

**@⁠alexis27yt** on GitHub · 2026-11-25 18:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/1069) `alexis27yt:remap-lean` → `main` · +134 −20 · 1 files · 1 commits · open Each page the title remaps (`map_alias`, ~850 a streaming frame per the README) takes four calls on the process's address space: unmap, split the placeholder, map, commit. Two of them change nothing in the common case: - the split fails every time the placeholder is already the range, as the title's one-page remaps leave it (10,200 of 10,200 in a measurement below); - committing a section page that a view already committed changes nothing. With `VICTORY_REMAP_LEAN=1` (**off by default**) the view is mapped first and the placeholder split only if that fails, and section pages committed once are not committed again. One bit a page is kept **inside the `Section`**, so it lives and dies with the section and a reused page number starts clear. Two calls a remap instead of four. **Measured outside the title** on an i5-12400F: a harness that repeats the same four calls (850 one-page remaps a frame over a 256 MiB `SEC_RESERVE` section into one-page placeholders): | contention | today (4 calls) | lean (2 calls) | |---|---|---| | none | 5.0 µs/remap | 3.0 µs | | 4 threads `VirtualProtect` 4 KiB | 6.3 µs | 5.6 µs | | 1 thread `GetWriteWatch(RESET)` of 1 GiB | 19.9 µs | 9.6 µs | **Honest scope:** that is ~2-9 ms of a streaming frame, against the 246 ms of remapping the README measures in game. The calls themselves are not where that time goes. Even beside a 1 GiB write-watch asking (~5 ms each), a remap averaged 10-20 µs here, not the ~290 µs per page seen in game. So the rest is waiting on something this harness does not reproduce: the `MAPPING` lock behind in-place readers, or a longer holder of the address space. The frame log's `RemapWaitUs` against `RemapUs` from a streaming scene would tell which. `shortcut:` a page the title itself decommits through one of its views would still be noted committed (documented at the switch); no title is known to do that with physical pages. Tests: new `a_section_notes_the_pages_committed_through_it`; all 13 `xmem` tests (real mappings) pass with and without the switch on the i5-12400F. Clippy: no new warnings.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:00 +00:00
Author
Owner

@⁠tikD1337 on GitHub · 2026-11-25 20:09 UTC · original

Measured the split you asked for, on native Windows 11, RTX 4070 Ti SUPER (driver 621.01), Ryzen 5 7600, Series X profile. The build is a diagnostics build of origin/main d510ee4 with frame-log counters of my own (not in any PR). The 330 s scripted run goes menus → opening cutscene → standing in the prison, with the usual launcher switches.

The remap time is not waiting. RemapWaitUs stays at or under 0.2 ms a frame in all 8 runs, with or without #1063's batching. Readers hold the MAPPING lock 2–6 ms a frame, nearly all of it texture refresh, never draws.

It is the kernel calls. I timed the hold time inside xmem:

  • kernel calls: the VirtualFree split or coalesce, MapViewOfFile3, the VirtualAlloc commit, UnmapViewOfFile2;
  • notes to the GPU side: title_memory_remapped and title_memory_view, which take the guards' and the views' mutexes.
remap ms/frame wait kernel calls GPU-side notes calls/frame
streaming frames, batching off 96.9 0.1 94.9 1.2 284
streaming frames, #1063 on 116.7 0.2 112.8 2.6 354
heaviest 5 s reading, off 689.8 0.9 675.8 7.4 2,469

That is about 0.27 ms of kernel time per remap call in game, against your 10–20 µs outside the title. So the time goes to the address-space calls being slow inside the title's process, not to the lock behind in-place readers. I did not test VICTORY_REMAP_LEAN, and I did not split the kernel time by call.

**@⁠tikD1337** on GitHub · 2026-11-25 20:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/1069#issuecomment-7173263861) Measured the split you asked for, on native Windows 11, RTX 4070 Ti SUPER (driver 621.01), Ryzen 5 7600, Series X profile. The build is a diagnostics build of `origin/main` d510ee4 with frame-log counters of my own (not in any PR). The 330 s scripted run goes menus → opening cutscene → standing in the prison, with the usual launcher switches. **The remap time is not waiting.** `RemapWaitUs` stays at or under 0.2 ms a frame in all 8 runs, with or without #1063's batching. Readers hold the `MAPPING` lock 2–6 ms a frame, nearly all of it texture refresh, never draws. **It is the kernel calls.** I timed the hold time inside `xmem`: - **kernel calls:** the `VirtualFree` split or coalesce, `MapViewOfFile3`, the `VirtualAlloc` commit, `UnmapViewOfFile2`; - **notes to the GPU side:** `title_memory_remapped` and `title_memory_view`, which take the guards' and the views' mutexes. | | remap ms/frame | wait | kernel calls | GPU-side notes | calls/frame | |---|---|---|---|---|---| | streaming frames, batching off | 96.9 | 0.1 | 94.9 | 1.2 | 284 | | streaming frames, #1063 on | 116.7 | 0.2 | 112.8 | 2.6 | 354 | | heaviest 5 s reading, off | 689.8 | 0.9 | 675.8 | 7.4 | 2,469 | That is about 0.27 ms of kernel time per remap call in game, against your 10–20 µs outside the title. So the time goes to the address-space calls being slow inside the title's process, not to the lock behind in-place readers. I did not test `VICTORY_REMAP_LEAN`, and I did not split the kernel time by call.
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/xmem.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1069/head:github-bot/gh-1069'
git switch 'github-bot/gh-1069'

Merge

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