xmem: mapping pages asks the host only for what it needs #2916

Open
github-bot wants to merge 2 commits from github-bot/gh-2916 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:53 UTC · original
0xkn0wh3r3:hle/xmem-maps-ask-only-what-they-need → main · +287 −28 · 1 files · 2 commits · open

What

XMemMapPhysicalPages and map_alias now skip two of the four host calls a mapping took (unmap, split, map, commit):

  • No split of a placeholder that is already the view's own. Unmapping a whole view records its placeholder (address and length). A later view of exactly that range is mapped straight over it. If the title has joined that placeholder with others since, MapViewOfFile3 fails (a replaced placeholder must be exactly the view's size) and the code splits and maps as before. The recorded placeholders are only a hint: nothing is recorded with VICTORY_MAP_LEAN=0, a map drops every one its range meets (the title releases and joins placeholders with the host's own VirtualFree, which we don't see), and at most 2^17 are kept, after which the map starts afresh.
  • No commit of section pages that are already committed. Each section keeps one bit per page, set when any view commits the page (the title's views or our own Views for DirectStorage writes). A section page committed through one view is committed in every view of it.

VICTORY_MAP_LEAN=0 makes both calls every time, as before.

Why

The title streams through one thread, which maps a batch's pages and then submits it, and every page gets mapped twice: into the title's pool, then by the GPU into its tiled heap (map_alias). Each call waits on the process's address-space lock, behind the GPU side's guards and the driver. The fork measured 200–400 µs per page in the world, against about 10 µs in a menu, so models arrived only as fast as their pages could be mapped.

Uncontended on this machine (map_bench, ignored; 64 pages mapped and unmapped 3,000 times, alternating runs), the time per page went from about 6.5 µs to 5.0 µs. Under lock contention each call costs far more, so dropping two of four should matter more there; I couldn't reproduce that contention here.

Nothing here depends on the GPU vendor.

Where it comes from

From the avatarmanz/VIctory-7900XTX fork, commit 49d7126, only its VICTORY_MAP_LEAN part, rewritten on main's xmem. Left out: its streaming log (VICTORY_DSTORAGE_LOG), its priority lift of the streaming thread (#2903 handles the title's idle-priority threads instead), and its thread-affinity names.

Related open PRs: #234 also keeps a per-page commit bitmap, bundled with persistent section views and overlapped DirectStorage reads. #1224 joins split placeholders; if both land, a recorded placeholder that #1224 has joined falls back to the split as described above.

Tested (Windows 11, RTX 5070 Ti)

  • cargo test -p victory-hle: 154 passed, 1 ignored (the benchmark). New tests:
    • pages_mapped_again_hold_what_they_held: three pages moved around eight slots for six rounds keep their bytes at both ends, with the placeholders joined halfway through (from the fork).
    • a_page_mapped_again_takes_its_own_placeholder: the page's commit bit is set; unmapping records the placeholder; mapping again uses it and finds the page committed; after the title joins the placeholders, mapping there still works and the bytes are kept.
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.

Not tested

  • Not run with the title, so the in-world gain is unmeasured here; the 200–400 µs figure is the fork's.
  • Not tested under Wine. Sections there are committed whole and commit already returns early; the split path is unchanged.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2916) `0xkn0wh3r3:hle/xmem-maps-ask-only-what-they-need` → `main` · +287 −28 · 1 files · 2 commits · open ## What `XMemMapPhysicalPages` and `map_alias` now skip two of the four host calls a mapping took (unmap, split, map, commit): - **No split of a placeholder that is already the view's own.** Unmapping a whole view records its placeholder (address and length). A later view of exactly that range is mapped straight over it. If the title has joined that placeholder with others since, `MapViewOfFile3` fails (a replaced placeholder must be exactly the view's size) and the code splits and maps as before. The recorded placeholders are only a hint: nothing is recorded with `VICTORY_MAP_LEAN=0`, a map drops every one its range meets (the title releases and joins placeholders with the host's own `VirtualFree`, which we don't see), and at most 2^17 are kept, after which the map starts afresh. - **No commit of section pages that are already committed.** Each section keeps one bit per page, set when any view commits the page (the title's views or our own `View`s for DirectStorage writes). A section page committed through one view is committed in every view of it. `VICTORY_MAP_LEAN=0` makes both calls every time, as before. ## Why The title streams through one thread, which maps a batch's pages and then submits it, and every page gets mapped twice: into the title's pool, then by the GPU into its tiled heap (`map_alias`). Each call waits on the process's address-space lock, behind the GPU side's guards and the driver. The fork measured 200–400 µs per page in the world, against about 10 µs in a menu, so models arrived only as fast as their pages could be mapped. Uncontended on this machine (`map_bench`, ignored; 64 pages mapped and unmapped 3,000 times, alternating runs), the time per page went from about 6.5 µs to 5.0 µs. Under lock contention each call costs far more, so dropping two of four should matter more there; I couldn't reproduce that contention here. Nothing here depends on the GPU vendor. ## Where it comes from From the avatarmanz/VIctory-7900XTX fork, commit [`49d7126`](https://github.com/avatarmanz/VIctory-7900XTX/commit/49d71266b25f8d432cfc86ec3d27c304a5191e66), only its `VICTORY_MAP_LEAN` part, rewritten on main's xmem. Left out: its streaming log (`VICTORY_DSTORAGE_LOG`), its priority lift of the streaming thread (#2903 handles the title's idle-priority threads instead), and its thread-affinity names. Related open PRs: #234 also keeps a per-page commit bitmap, bundled with persistent section views and overlapped DirectStorage reads. #1224 joins split placeholders; if both land, a recorded placeholder that #1224 has joined falls back to the split as described above. ## Tested (Windows 11, RTX 5070 Ti) - `cargo test -p victory-hle`: 154 passed, 1 ignored (the benchmark). New tests: - `pages_mapped_again_hold_what_they_held`: three pages moved around eight slots for six rounds keep their bytes at both ends, with the placeholders joined halfway through (from the fork). - `a_page_mapped_again_takes_its_own_placeholder`: the page's commit bit is set; unmapping records the placeholder; mapping again uses it and finds the page committed; after the title joins the placeholders, mapping there still works and the bytes are kept. - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. ## Not tested - Not run with the title, so the in-world gain is unmeasured here; the 200–400 µs figure is the fork's. - Not tested under Wine. Sections there are committed whole and `commit` already returns early; the split path is unchanged.
The title streams through one thread of its own, which maps the pages of
a batch and then submits it, and every page is mapped twice: into the
title's pool, then by the GPU into its tiled heap (map_alias). Each
mapping took four system calls: unmap the old view, split the
placeholder, map the section, commit its pages. Each waits for the
process's address-space lock, behind the GPU side's guards and the
driver; the fork measured 200 to 400 us a page in the world against 10
in a menu, and loads that came only as fast as their pages could be
mapped.

- No split of a placeholder that is already the view's own: an unmap of
  a whole view notes its placeholder, and a view of exactly that range
  is mapped over it as it is. If the title has joined it with others
  since, that map fails and the placeholder is split as before.
- No commit of section pages already committed: each section keeps a
  bit per page, set when a view (the title's or one of ours) commits
  it; committed through one view, a page is committed in every view.

VICTORY_MAP_LEAN=0 does both every time, as before.

A page mapped and unmapped again takes two calls instead of four:
uncontended on this machine, about 6.5 us a page before and 5.0 after
(map_bench, ignored). Tests: pages keep their bytes over six rounds of
moves, also after the title joins the placeholders; a page mapped again
where it was takes its own placeholder and is not committed again, and
after a join it is mapped by the split as before.

From avatarmanz/VIctory-7900XTX 49d7126 (its VICTORY_MAP_LEAN part; the
streaming log, the priority lift of the streaming thread and the stack
affinity names are left out).

Co-authored-by: local <local@localhost>
The placeholders an unmap leaves were noted for good: an entry went only
when its address was mapped again, so placeholders the title releases or
joins (with the host's own VirtualFree, which we do not see) stayed, and
doing that at new addresses grew the map for the whole run, also with
VICTORY_MAP_LEAN=0. (Review on #2916.)

- Nothing is noted while VICTORY_MAP_LEAN=0.
- A map forgets every noted placeholder its range meets, also one that
  begins below it, not only one at its own address.
- At most 2^17 are noted (8 GiB of pages unmapped one by one); past that
  the map starts afresh. They are only a hint: a miss splits as before.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:26 +00:00
Author
Owner

@⁠Kajanos on GitHub · 2026-11-26 00:07 UTC · original

Windows 11 / NVIDIA test run, head ab91aa4d64 merged onto main 63bcca43c6.

Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (dxil.dll from the SDK).

  • cargo test --locked -p victory-hle: 153 passed, 1 failed, 1 ignored.
  • The one failure is lifecycle::tests::showing_a_title_window_shows_its_stand_in, and it also fails on main in this run. The tests ran over SSH, i.e. in session 0 with no interactive desktop, so the window can't be shown. On the desktop session the same test passes on main (12/12 lifecycle). This PR doesn't touch lifecycle.

Not run: the retail title, clippy, and other crates.

AI-assisted (Claude Code)

**@⁠Kajanos** on GitHub · 2026-11-26 00:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2916#issuecomment-7178417446) **Windows 11 / NVIDIA test run**, head `ab91aa4d64` merged onto `main` `63bcca43c6`. Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (`dxil.dll` from the SDK). - `cargo test --locked -p victory-hle`: 153 passed, 1 failed, 1 ignored. - The one failure is `lifecycle::tests::showing_a_title_window_shows_its_stand_in`, and it also fails on `main` in this run. The tests ran over SSH, i.e. in session 0 with no interactive desktop, so the window can't be shown. On the desktop session the same test passes on `main` (12/12 `lifecycle`). This PR doesn't touch lifecycle. Not run: the retail title, clippy, and other crates. AI-assisted (Claude Code)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:22 UTC · original

Automated triage for the maintainers.

Merge candidate (a recommendation to look, not an approval). In modules/xmem.rs, map now maps straight over a placeholder that an earlier whole-view unmap left (Physical::holes). If that fails, for example because the title has joined placeholders since, it falls back to split-then-map. Section::commit_shown also skips committing section pages that are already committed through any view. I checked that a failed direct map falls through to the old split path and that the hole hint is dropped on any overlapping map. The tests cover joined placeholders and bytes surviving remaps. VICTORY_MAP_LEAN=0 restores the old calls. CI check passes. The in-world gain is not measured here (uncontended, about 6.5 to 5.0 µs per page). Related: #234 (commit bitmap) and #1224 (joining placeholders) overlap.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 02:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2916#issuecomment-7180751451) <!-- victory-triage v1 head=4dd9a4a123c9f09226d324b1474dba999c935710 verdict=merge-candidate at=2026-11-26T02:22:49Z --> Automated triage for the maintainers. **Merge candidate** (a recommendation to look, not an approval). In `modules/xmem.rs`, `map` now maps straight over a placeholder that an earlier whole-view unmap left (`Physical::holes`). If that fails, for example because the title has joined placeholders since, it falls back to split-then-map. `Section::commit_shown` also skips committing section pages that are already committed through any view. I checked that a failed direct map falls through to the old split path and that the hole hint is dropped on any overlapping map. The tests cover joined placeholders and bytes surviving remaps. `VICTORY_MAP_LEAN=0` restores the old calls. CI `check` passes. The in-world gain is not measured here (uncontended, about 6.5 to 5.0 µs per page). Related: #234 (commit bitmap) and #1224 (joining placeholders) overlap. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2916'
git switch 'github-bot/gh-2916'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2916'
git switch 'github-bot/gh-2916'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2916'
git switch 'main'
git merge --squash 'github-bot/gh-2916'
git switch 'main'
git merge --ff-only 'github-bot/gh-2916'
git switch 'main'
git merge 'github-bot/gh-2916'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2916
No description provided.