Skip to content

KernelX: a page mapped away moves to its next address directly, not by way of its home - #849

Merged
ivall merged 2 commits into
xcl-dev:mainfrom
Sr-0w:direct-page-moves-pr
Nov 24, 2026
Merged

ivall merged 2 commits into
xcl-dev:mainfrom
Sr-0w:direct-page-moves-pr

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

A physical page that is mapped at one address and that the title maps at another went back home first. Its home was committed again and the page copied there, then the old address was decommitted. After that, the home was copied to the new address and decommitted. In a sparse window, each of those commits and decommits is also a tile mapping (UpdateTileMappings + a signal), so every page move cost about four of them.

A retail game, after its first movie, moves tens of thousands of pages one at a time. Measured with a counter in MapTitlePhysicalPages (not in this PR):

  • 16384 calls took 6 s;
  • 32768 took 23 s, the cost per call growing with the mapped tiles;
  • the game's watchdog then ended the process.

The page is now copied from where it is to the new address, and the old address is given up; its home is not touched. A page that was never used where it was (lazy) still comes from its home, as before.

What is in it

  • crates/xcl/src/hle/kernelx.rs:
    • move_away, called from map_pages for a page already mapped away;
    • release_at, the decommit that unmap_away already did, factored out;
    • the test a_page_away_moves_on_without_going_home and a test-only counter of pages copied home.

Tested

  • AMD Radeon RX 7800 XT (driver 32.0.32029.2010), Ryzen 7 3700X, Windows 11 26300, rustc 1.100.0, release.
  • cargo test --release --workspace -- --test-threads=4: 661 passed, 3 failed, 21 ignored.
    • The 3 failures are placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory.
    • They fail the same way on main (e50836b) with --test-threads=4 and pass when run alone, on both.
    • No SKIPPED tests.
  • a_page_away_moves_on_without_going_home fails without the change ("the page went by way of its home") and passes with it.
  • scatter_timing (--ignored, XCL_SCATTER_PAGES=4096,16384), "reverse" being the pass that moves pages already mapped away:
pages reverse, main reverse, this PR
4096 203 ms 147 ms
16384 857 ms 588 ms
  • In the retail game the title screen and the loading screen after the first movie show as on main (below).

Regression run

main:

xcl-smoke v1
commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a
gpu: AMD  Radeon RX 7800 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 68390 MB

this PR:

xcl-smoke v1
commit: f1e2113a76246e766570c66dda69cf767f7b6931
gpu: AMD  Radeon RX 7800 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1545 (PresentX 1546)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 64780 MB

Not tested

  • NVIDIA / Intel GPUs.
  • The smoke run stops at the title screen, before the page moves this is about.
  • Past the loading screen, the game stops on main too (cross-queue Wait64BitValueX on values nothing writes); that is not addressed here.

AI use

  • Claude Code, Claude Opus 5.5: measured where the page mapping time goes, wrote the change and its test, ran the tests and the regression runs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA

…y way of its home

A physical page mapped at one address that the title maps at another went
back home first: its home was committed again, the page copied there, the
old address decommitted, then the home copied to the new address and
decommitted. In a sparse window each commit and decommit is also a tile
mapping. A retail game moving pages one at a time after its first movie spent
over 20 s in them, and its watchdog ended it.

The page is now copied from where it is to the new address and the old
address is given up; its home is not touched. A page never used where it was
(lazy) still comes from its home.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA
@badoomtch

badoomtch commented Nov 24, 2026 •

Copy link
Copy Markdown

The direct-move regression passed on native Windows at f1e2113a76246e766570c66dda69cf767f7b6931. The test initialised UMA, preserved the first and last words, and released the old address. Windows 11 build 26300, RTX 5080 (610.88), Core Ultra 7 265, Rust 1.96.0 MSVC, debug build.

cargo test --frozen -p xcl --lib a_page_away_moves_on_without_going_home -- --nocapture --test-threads=1 — 1 passed, 0 failed, 0 ignored.

One error path looks worth checking before merging. For an already materialised page, move_away removes old from away.at and the page from away.page before committing the new destination. If that commit fails, the function returns Err with the original bytes still at old but both lookup entries gone. Moving those removals after a successful destination commit, or restoring the entries on that error, would preserve the previous mapping for a retry. I checked the order in the source. The passing test covers successful moves only.

We also ran a longer offline retail pair on the same native Windows machine. Both used the same returning-player profile and learned memory-window setting, with a shared cache. The control was our integration build based on beaa245. The candidate added this PR's runtime change alone. The following are integration runs, separate from the exact-head test above.

Control With the direct page move
Last captured loading artwork frame 1,444 frame 1,579
First captured black frame after that artwork 1,449 1,583
Total presents 1,450 1,585
Time to the same title watchdog abort 111.469 s 120.684 s
Legacy Wait64 timeout messages 0 0

The extra 135 presents were almost entirely before the fade. Both runs stopped within two presents of the first captured black frame. Neither showed a world frame. These builds do not count direct page moves or time spent in them, so this comparison cannot attribute the extra frames to faster remapping.

On a second pair based on 1ec4c98cd (including #873), we counted move attempts and native tile-mapping calls in two-second windows. The only runtime difference between the arms was #849. Both started with separate, byte-identical copies of XCL's cache (582 compatible translations), the same profile and memory-window setting. The machine's driver cache persisted across the pair.

Control Direct moves
Away-to-away move attempts 107,773 107,017
Native tile-mapping calls (map / unmap) 28,844 / 0 29,093 / 0
First captured black frame after the artwork 1,362 1,339
Final presents 1,364 1,341
Time of the same title abort 108.910 s 107.226 s
Five-second sparse-queue warnings 0 0

Both arms peaked at 44,049 moves in a two-second window during early loading. In both, the last 14 complete windows before the abort recorded zero move attempts, tile-mapping calls and new presents. Direct moves did run, and the prolonged freeze remained. These counters measure calls, not their cost.

AI use: Codex (GPT-6) checked the source, ran the tests and summarised the local captures and logs.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head f1e2113 onto main beaa245, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 704 passed, 10 failed, 41 ignored. Failures are the known Wine-lane set from my #42 rows plus #718 trio members; nothing here fails because of your change. Kernel page-move tests green in the full suite run (no new failures anywhere).

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…#851, ivall#864, ivall#875-ivall#876 and Wine raw fences

Integrate clean upstream PRs on top of upstream/main (1ec4c98):
- ivall#849: direct move_away for remapped physical pages (avoids 4x sparse tile-mapping round-trips)
- ivall#838: FillMemoryWith*BitValueX uses list upload arena instead of leaked pattern buffers
- ivall#840: merge released ranges of the shared descriptor heap
- ivall#839: map queue-specific D3D12_BARRIER_LAYOUT values to legacy resource states
- ivall#841: preserve due frame-clock events when schedule changes at deadline
- ivall#851: split wrapped command lists before Wait64 GE after ordinary GPU work
- ivall#864: export XMemIsToolsMemAvailable returning 0 on retail
- ivall#875: tbuffer_load_format_* uses identity DST_SEL instead of V# DST_SEL
- ivall#876: implement IDXGIDevice2::EnqueueSetEvent

Also add real::create_raw_fence for internal fences (late_release and EnqueueSetEvent) so Wine/vkd3d-proton never receives a FenceProxy on unadopted internal queues or SetEventOnMultipleFenceCompletion, and wrap list_x test exec with UnadoptGuard.

Assisted-by: Antigravity (Google DeepMind)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
… Linux PRs ivall#867/ivall#871/ivall#877

Update fork README for upstream/main 1ec4c98 (fenced late_release and queue-wait diagnostics), newly integrated PRs (ivall#838-ivall#841, ivall#849, ivall#851, ivall#864, ivall#875, ivall#876), live gameplay audio progress, and our three open upstream Linux PRs (ivall#867, ivall#871, ivall#877).

Assisted-by: Antigravity (Google DeepMind)
Reported in review: move_away dropped both lookups of a page before
committing its destination, so a failed commit left its bytes at the old
address with nothing pointing at them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA
@Sr-0w

Sr-0w commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @badoomtch, you're right about the error path. Fixed in the latest commit on this branch: move_away now only drops the page's two lookups once the destination is committed. A lazy page is still released before the commit, as before.

New test: a_page_whose_move_fails_stays_mapped_where_it_was. It points a move at an address with nothing reserved there, then checks that the page keeps both lookups and its bytes. It fails on f1e2113 ("the page lost where it is") and passes now. The four kernelx page tests pass (release, RX 7800 XT, Windows 11 26300).

Thanks for the long paired runs too. They match what I see: direct moves run, but the freeze after the loading artwork does not come from page moves. On my side it is the title's watchdog while its threads wait in pso_async::resolve_wait on long driver compiles of compute programs (#505). #891 targets that, opt-in. @SlopTart, thanks for the Linux / RDNA3 run.

AI use: Claude Code (Claude Opus 5.5) wrote the fix, the test and this reply.

@eizispark

Copy link
Copy Markdown

Hardware check of 5b693e67524d63282911ce9cfacc7b980cbb04af (verified clean merge with main 077ce40): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 706 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none)
  • hle::kernelx unit tests (28 passed, 0 failed), including hle::kernelx::tests::a_page_away_moves_on_without_going_home and hle::kernelx::tests::a_page_whose_move_fails_stays_mapped_where_it_was

Regression run
main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (5b693e6):

xcl-smoke v1
commit: 5b693e67524d63282911ce9cfacc7b980cbb04af
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1659 (PresentX 1659)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14860 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay / world-load page moves past the 60 s menu window

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@badoomtch badoomtch left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s a second case in move_away on 5b693e675. A title can call VirtualAlloc(MEM_COMMIT) on part of a lazy page and write to it without going through the first-touch handler. The lazy marker is still set. When the title moves that page, lazy::unmark(old) succeeds and the new address loses those bytes.

I reproduced this on native Windows with a 64 KiB reservation. I committed two separate 4 KiB spans, filled them with 0x35 and 0xa9, then moved the page through XMemMapPhysicalPagesScatter. On this PR’s exact head the first mismatch was at offset 4096: expected 0x35, read 0x00. On our play build the same test verified all 65,536 bytes, including the zero-filled gaps.

I’ve put the direct-move change and regression on my fork. It reuses Babyhamsta’s committed-span reader from #934 and preserves the original mapping if reading the source or committing the destination fails. Six focused tests passed on the clean branch, including both #934 unmap tests and the failed-move retry. Patch against the combined PR heads

This establishes a page-content bug. Our integrated retail run still stopped after the loading artwork. Codex helped write the patch, run the tests and check the results.

@ivall
ivall merged commit 6bac4b4 into xcl-dev:main Nov 24, 2026
1 check failed
@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Merged (6bac4b4). Checked on an RX 9070 (RDNA4) on main 6bac4b4 together with #923 and #849: cargo test --workspace -- --test-threads=4 - 678 unit tests passed, 0 failed; the retail game plays its intro and menus at 30 fps and starts loading the world (the run then hits this machine's commit limit, not a crash). Picked over #531 (the same move without going home); #556 will need its run-dropping added to move_away when rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants