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

Open
alexis27yt wants to merge 1 commit from upstream-pr/1069 into main
alexis27yt commented 2026-11-25 18:23:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by alexis27yt on 2026-11-25T18:23:08Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6610951986 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1069). Originally posted by [alexis27yt](https://github.com/alexis27yt) on 2026-11-25T18:23:08Z. --- 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.
tikD1337 commented 2026-11-25 20:09:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by tikD1337 on 2026-11-25T20:09:19Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7173263861 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1069#issuecomment-7173263861). Originally posted by [tikD1337](https://github.com/tikD1337) on 2026-11-25T20:09:19Z. --- 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 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/1069:upstream-pr/1069'
git switch 'upstream-pr/1069'

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/1069'
git switch 'upstream-pr/1069'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1069'
git switch 'upstream-pr/1069'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1069'
git switch 'main'
git merge --squash 'upstream-pr/1069'
git switch 'main'
git merge --ff-only 'upstream-pr/1069'
git switch 'main'
git merge 'upstream-pr/1069'
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
fxceless/victory-fork!1067
No description provided.