kernelx: a page moving between addresses is copied there, not via home #531

Closed
github-bot wants to merge 1 commit from gh-pr/531/head into gh-pr/531/base
Owner

@⁠Vaximous on GitHub · 2026-11-24 01:27 UTC · original
Vaximous:kernelx-direct-page-moves → main · +91 −5 · 2 files · 1 commits · closed without merging

A physical page mapped at one address and then at another (MapTitlePhysicalPages, one page a call) went through its home: unmap_away committed the home again and copied the page there, map_pages copied it from the home to the new address, and the home was given back at the end of the call. In a sparse window every commit and decommit is a tile mapping (UpdateTileMappings, 0.12–0.15 ms each in the NVIDIA driver here), so a moved page cost four of them, two of them for the home.

The retail title moves pages this way, one per call, on the thread that presents, in the loading phase after its menus. Timing probes in that phase: about 1,400 calls a second at ~0.68 ms each, 96% of that thread's time; symbolized thread dumps put it in nvwgf2umx → D3D12Core under sparse::State::map_tiles / unmap_tiles. When presents stop for more than about 30 s the title's own stall watchdog ends it (#232).

A page that is mapped somewhere and was used there is now copied straight from its old address to the new one; the old address is given back the way unmap_away gives it back (now decommit_away). This is a speed change: what every address holds afterwards is the same as before.

  • at sparse and old not, or the reverse: each address is handled on its own. at is committed with VirtualAlloc (unless it is in a coherent UMA window) and told to the sparse windows with sparse::committed if it is sparse; old goes through decommit_away, which calls sparse::decommitted only if old is sparse and leaves an old in a coherent UMA window committed, as unmap_away did.
  • If committing at fails, the call returns ERROR_INVALID_ADDRESS before away is touched: the page stays mapped at old. (What was at at before had already been unmapped, as on the old path.)
  • away.gone with the home skipped: a home still in away.gone from earlier in the same call stays there and is given back at the end of the call, the same net effect as before; a home already given back stays given back (before, it was committed and given back again). A home that is not lazy is no longer written with a copy the page itself does not need.
  • A page that is mapped but was never used (still marked lazy) takes the old path: there is nothing to copy.

Overlaps: #254 (merged) speeds up committed_page's VirtualQuery; it does not touch the move path, and merged on the same tree it made no difference to this phase (pause 30, 30, 30 s, all three runs ended by the watchdog). #232 is the watchdog that ends the title in the pause. #236 (open) moves sparse commits and decommits under the sparse lock (commit_initialized / decommit); this PR only calls the existing sparse::committed / decommitted, so whichever lands second needs its calls renamed. A second PR, Memory: decommitted sparse tiles stay mapped until the next submit, removes most of the remaining tile mappings of this pattern; the two do not depend on each other.

What it does not achieve: the title still does not reach gameplay. With this change (and the second PR) on a local tree the loading phase no longer stalls and the title keeps loading, but its memory keeps growing (peak commit 44 GB at 300 s, still rising; local video memory 19.4 GB on a 12 GB card): memory growth as in #248 is the next stop (that tree carries an earlier form of #288).

What is in it

  • kernelx: a page moving between addresses is copied there, not via home (crates/xcl/src/hle/kernelx.rs, crates/xcl/src/hle/kernelx/lazy.rs): the direct path in map_pages, decommit_away split out of unmap_away, lazy::marked, and the test a_page_moved_between_addresses_is_copied_there. The test moves a used page from one address to another and checks that its home is not given back again by the move (that is, the home was not committed for it), that a lazy home stays uncommitted, and that the data, a lazy neighbour reading zeros, a move back and mapping the whole allocation home all still hold. It fails on main ("its home is not given back after the move").

Tested

  • NVIDIA GeForce RTX 4070 Ti 12 GB, driver 617.42 (32.0.16.1742), 32-lane waves; AMD Ryzen 9 7900X; 64 GB; Windows 11 Pro build 26300; rustc 1.100.0; tests in debug, game runs in release. The PC was in use for other work during the runs.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on b545ae2: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • Retail title, menus walked with XCL_PRESS_A_AT=14,17,21,40,60,66,72, 150 s runs, the loading pause measured as the longest stretch with 0 presents (XCL_ACTIVITY lines, 2 s windows):
    • On this branch's base (main at 2997c9a), back to back, two runs each: main and this branch never reach the phase within 150 s. In all four runs the title spends about 110 s at 7–9 presents per 2 s with no DirectStorage requests (an intro / logo screen), then loads at 60 presents per 2 s; longest gap with 0 presents 2 s (main), 4 s and 2 s (this branch); 22,701–22,708 DirectStorage requests; no crash; peak commit 16.4 GB in all four.
    • On a local tree of main plus other open PRs (#254 among them), which gets into the phase about 36 s in, back to back, two runs each: without this change the pause was 22 s and 22 s (1,478 and 1,522 frames in 150 s); with it 12 s and 10 s (1,813 and 1,933 frames). No run crashed. Earlier runs of the same tree without the change had pauses of 24 s and 30 s or more, three of those four ended by the watchdog.
    • The same tree with both this change and the second PR: pause 10 s and 10 s, no crash; in a 300 s run no crash, 70,348 DirectStorage requests, 1,720 frames.

Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60, no input, release builds; main at 2997c9a (this branch's base).

main:

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: NVIDIA GeForce RTX 4070 Ti
title: 9a60a330
seconds: 60
exit: 0x0
frames shown: 1464 (PresentX 1464)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14470 MB

this PR:

xcl-smoke v1
commit: b545ae2debc8555bd6a9b734046ed7e9752e0019
gpu: NVIDIA GeForce RTX 4070 Ti
title: 9a60a330
seconds: 60
exit: 0x0
frames shown: 1476 (PresentX 1476)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14458 MB

Not tested

  • AMD GPUs and GPUs with 64-lane waves; titles other than the retail title.
  • The loading phase on this branch built from main alone: main does not get there within 150 s (above), so the pause figures are from the local tree.
  • Gameplay: the title does not reach it with or without this change (memory growth, #248).

AI use

  • Claude Code. Claude Opus 5.5: the diagnosis (timing probes, symbolized thread dumps), the code, the tests and this description. Claude Fable 5.2: planning and review of the diff.
**@⁠Vaximous** on GitHub · 2026-11-24 01:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/531) `Vaximous:kernelx-direct-page-moves` → `main` · +91 −5 · 2 files · 1 commits · closed without merging A physical page mapped at one address and then at another (`MapTitlePhysicalPages`, one page a call) went through its home: `unmap_away` committed the home again and copied the page there, `map_pages` copied it from the home to the new address, and the home was given back at the end of the call. In a sparse window every commit and decommit is a tile mapping (`UpdateTileMappings`, 0.12–0.15 ms each in the NVIDIA driver here), so a moved page cost four of them, two of them for the home. The retail title moves pages this way, one per call, on the thread that presents, in the loading phase after its menus. Timing probes in that phase: about 1,400 calls a second at ~0.68 ms each, 96% of that thread's time; symbolized thread dumps put it in `nvwgf2umx` → `D3D12Core` under `sparse::State::map_tiles` / `unmap_tiles`. When presents stop for more than about 30 s the title's own stall watchdog ends it (#232). A page that is mapped somewhere and was used there is now copied straight from its old address to the new one; the old address is given back the way `unmap_away` gives it back (now `decommit_away`). This is a speed change: what every address holds afterwards is the same as before. - `at` sparse and `old` not, or the reverse: each address is handled on its own. `at` is committed with `VirtualAlloc` (unless it is in a coherent UMA window) and told to the sparse windows with `sparse::committed` if it is sparse; `old` goes through `decommit_away`, which calls `sparse::decommitted` only if `old` is sparse and leaves an `old` in a coherent UMA window committed, as `unmap_away` did. - If committing `at` fails, the call returns `ERROR_INVALID_ADDRESS` before `away` is touched: the page stays mapped at `old`. (What was at `at` before had already been unmapped, as on the old path.) - `away.gone` with the home skipped: a home still in `away.gone` from earlier in the same call stays there and is given back at the end of the call, the same net effect as before; a home already given back stays given back (before, it was committed and given back again). A home that is not lazy is no longer written with a copy the page itself does not need. - A page that is mapped but was never used (still marked lazy) takes the old path: there is nothing to copy. Overlaps: #254 (merged) speeds up `committed_page`'s `VirtualQuery`; it does not touch the move path, and merged on the same tree it made no difference to this phase (pause 30, 30, 30 s, all three runs ended by the watchdog). #232 is the watchdog that ends the title in the pause. #236 (open) moves sparse commits and decommits under the sparse lock (`commit_initialized` / `decommit`); this PR only calls the existing `sparse::committed` / `decommitted`, so whichever lands second needs its calls renamed. A second PR, `Memory: decommitted sparse tiles stay mapped until the next submit`, removes most of the remaining tile mappings of this pattern; the two do not depend on each other. What it does not achieve: the title still does not reach gameplay. With this change (and the second PR) on a local tree the loading phase no longer stalls and the title keeps loading, but its memory keeps growing (peak commit 44 GB at 300 s, still rising; local video memory 19.4 GB on a 12 GB card): memory growth as in #248 is the next stop (that tree carries an earlier form of #288). **What is in it** - `kernelx: a page moving between addresses is copied there, not via home` (`crates/xcl/src/hle/kernelx.rs`, `crates/xcl/src/hle/kernelx/lazy.rs`): the direct path in `map_pages`, `decommit_away` split out of `unmap_away`, `lazy::marked`, and the test `a_page_moved_between_addresses_is_copied_there`. The test moves a used page from one address to another and checks that its home is not given back again by the move (that is, the home was not committed for it), that a lazy home stays uncommitted, and that the data, a lazy neighbour reading zeros, a move back and mapping the whole allocation home all still hold. It fails on main ("its home is not given back after the move"). **Tested** - NVIDIA GeForce RTX 4070 Ti 12 GB, driver 617.42 (32.0.16.1742), 32-lane waves; AMD Ryzen 9 7900X; 64 GB; Windows 11 Pro build 26300; rustc 1.100.0; tests in debug, game runs in release. The PC was in use for other work during the runs. - `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4` on b545ae2: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - Retail title, menus walked with `XCL_PRESS_A_AT=14,17,21,40,60,66,72`, 150 s runs, the loading pause measured as the longest stretch with 0 presents (`XCL_ACTIVITY` lines, 2 s windows): - On this branch's base (main at 2997c9a), back to back, two runs each: main and this branch never reach the phase within 150 s. In all four runs the title spends about 110 s at 7–9 presents per 2 s with no DirectStorage requests (an intro / logo screen), then loads at 60 presents per 2 s; longest gap with 0 presents 2 s (main), 4 s and 2 s (this branch); 22,701–22,708 DirectStorage requests; no crash; peak commit 16.4 GB in all four. - On a local tree of main plus other open PRs (#254 among them), which gets into the phase about 36 s in, back to back, two runs each: without this change the pause was 22 s and 22 s (1,478 and 1,522 frames in 150 s); with it 12 s and 10 s (1,813 and 1,933 frames). No run crashed. Earlier runs of the same tree without the change had pauses of 24 s and 30 s or more, three of those four ended by the watchdog. - The same tree with both this change and the second PR: pause 10 s and 10 s, no crash; in a 300 s run no crash, 70,348 DirectStorage requests, 1,720 frames. **Regression run** `scripts/smoke.ps1 -Game <game folder> -Seconds 60`, no input, release builds; main at 2997c9a (this branch's base). main: ``` xcl-smoke v1 commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21 gpu: NVIDIA GeForce RTX 4070 Ti title: 9a60a330 seconds: 60 exit: 0x0 frames shown: 1464 (PresentX 1464) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14470 MB ``` this PR: ``` xcl-smoke v1 commit: b545ae2debc8555bd6a9b734046ed7e9752e0019 gpu: NVIDIA GeForce RTX 4070 Ti title: 9a60a330 seconds: 60 exit: 0x0 frames shown: 1476 (PresentX 1476) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14458 MB ``` **Not tested** - AMD GPUs and GPUs with 64-lane waves; titles other than the retail title. - The loading phase on this branch built from main alone: main does not get there within 150 s (above), so the pause figures are from the local tree. - Gameplay: the title does not reach it with or without this change (memory growth, #248). **AI use** - Claude Code. Claude Opus 5.5: the diagnosis (timing probes, symbolized thread dumps), the code, the tests and this description. Claude Fable 5.2: planning and review of the diff.
A physical page mapped at one address and then mapped at another
(XMemMapPhysicalPages / MapTitlePhysicalPages, one page a call) went home
first: unmap_away committed its home again (home_again) and copied the
page there, then map_pages copied it from home to the new address and
gave the home back at the end of the call (move_home_away). In a sparse
window each of those commits and decommits is a tile mapping
(UpdateTileMappings), about 0.12-0.15 ms each on an RTX 4070 Ti: two of
the four a moved page cost were the home's.

A retail title moves tens of thousands of pages this way after its menus,
one per call, on the thread that presents. Timing probes in that phase:
about 1,400 calls a second at ~0.68 ms each, 96% of the thread's time,
and thread dumps put it in the driver under map_tiles / unmap_tiles. With
the presents stopped for more than 30 s the title's own stall watchdog
ended it.

A page that is mapped somewhere (and was used there) is now copied
straight to its new address, and the old address is given back as
unmap_away gives it back (decommit_away). Its home stays as it was: a
home given back stays given back, and one still pending in away.gone is
given back at the end of the call as before. A page mapped but never used
(lazy) still takes the old path, which has nothing to copy.

Assisted-by: Claude Code (Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:47 +00:00
github-bot closed this pull request 2026-11-26 04:24:47 +00:00
Author
Owner

@⁠brothernog on GitHub · 2026-11-24 01:57 UTC · original

Tested b545ae2 on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug:

  • cargo test -p xcl --lib hle::kernelx: 25 passed, 0 failed, 1 ignored.
  • Negative control: with the new move path in map_pages disabled (so every move takes the old unmap-and-remap route), a_page_moved_between_addresses_is_copied_there fails at kernelx.rs:2225.
  • The branch is on 2997c9a; git merge-tree against main 508a0c7 is clean.

Not tested: the full suite, a GPU whose UMA window is sparse (the sparse branch of the new path doesn't run here), the performance claim.

This review was AI-assisted.

**@⁠brothernog** on GitHub · 2026-11-24 01:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/531#issuecomment-7119614722) Tested `b545ae2` on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug: - `cargo test -p xcl --lib hle::kernelx`: 25 passed, 0 failed, 1 ignored. - Negative control: with the new move path in `map_pages` disabled (so every move takes the old unmap-and-remap route), `a_page_moved_between_addresses_is_copied_there` fails at `kernelx.rs:2225`. - The branch is on 2997c9a; `git merge-tree` against `main` 508a0c7 is clean. Not tested: the full suite, a GPU whose UMA window is sparse (the sparse branch of the new path doesn't run here), the performance claim. This review was AI-assisted.
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 03:12 UTC · original

Test run of b545ae2debc8555bd6a9b734046ed7e9752e0019 on AMD RDNA4. I merged it onto current main dd2ae9a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 691 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 651 passed, 0 failed, 21 ignored
  • 0 SKIPPED; a_page_moved_between_addresses_is_copied_there passes.

Review: The page is copied to its new address before its old one is decommitted, and the sparse bookkeeping (sparse::committed / decommitted) follows. I checked the case of a page mapped again at the address it already has: unmap_away(away, at, ..) runs first for each at and sends that page home, so away.page no longer has it and the new branch is skipped, which is correct (the slower path, as before). I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

**@⁠MesshM** on GitHub · 2026-11-24 03:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/531#issuecomment-7120867008) Test run of `b545ae2debc8555bd6a9b734046ed7e9752e0019` on AMD RDNA4. I merged it onto current `main` `dd2ae9a` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **691 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 651 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `a_page_moved_between_addresses_is_copied_there` passes. **Review:** The page is copied to its new address before its old one is decommitted, and the sparse bookkeeping (`sparse::committed` / `decommitted`) follows. I checked the case of a page mapped again at the address it already has: `unmap_away(away, at, ..)` runs first for each `at` and sends that page home, so `away.page` no longer has it and the new branch is skipped, which is correct (the slower path, as before). I found nothing to change. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Author
Owner

@⁠ivall on GitHub · 2026-11-24 09:32 UTC · original

Closing as superseded by #849 (merged in 6bac4b4), the same change (a moved page is copied to its next address, not via its home), with the error path fixed after review. Thanks for the measurements!

**@⁠ivall** on GitHub · 2026-11-24 09:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/531#issuecomment-7127545494) Closing as superseded by #849 (merged in 6bac4b4), the same change (a moved page is copied to its next address, not via its home), with the error path fixed after review. Thanks for the measurements!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.