xmem: back physical pages with their section from the start #464

Merged
Jerkin42 merged 2 commits from upstream-pr/464 into main 2026-11-29 11:27:48 +00:00
Jerkin42 commented 2026-11-29 10:51:34 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-29T10:51:34Z.


Summary

Fixes #456.

Problem. Every mapping of a physical page is the same memory, and a title reads and writes through whichever mapping it likes. With private backing, a second mapping stays inaccessible until its first access promotes it. Promotion is refused (ERROR_BUSY) while a host import holds the page, so that first access kills the title. In ProjectScarlett this ended every run about 100-170 frames into the first story mission.

Change. Newly mapped pages go through their section (map_shared_page / map_contiguous). A second mapping then needs no promotion, and a hold can't block it. TUXBOX_XMEM_PRIVATE_VIEWS=1 restores private backing.

Two CopyPageMappingsX fixes that follow from it:

  • Held view at the destination. An unmapped held page keeps its section view for the import (DeferredKind::SectionPlaceholder). A later copy that maps a GPU alias over that address failed with ERROR_INVALID_ADDRESS, and the copy queue dropped every later batch (copy queue rejected a guest command-list batch (0x800701e7)). The queue drains its GPU work before the copy and retires the overlapping imports after it, so the copy now releases that view first.
  • Former private slot. A GPU alias slot that held private memory now takes a private copy of a section-backed page, as other GPU aliases do. Its imports resolve the token's backing.

Trade-off. Section-backed pages have no write watch (tracking.rs), so the d3d12 provider digests their textures instead. With #439, the run below kept that cost low.

Tested

  • The checks relevant to this change passed (xmem): only the type check and ProjectScarlett runs (below). The xmem suite hasn't been run.
  • Changed or new behaviour is covered by a Lanes scenario: no. Covered by unit tests in tests/physical_backing.rs instead:
    • the existing tests pin private mode through one shared lock (backing_mode);
    • a new test maps a held page a second time and checks both mappings are the same memory, with no promotion.
  • AMD and NVIDIA: AMD only. NVIDIA still needs to run the checks.

GPU, driver and backend: RX 9060 XT, RADV (Mesa), GE-Proton11-14, vkd3d-proton.

Commands run and their results:

cargo check --locked --target x86_64-pc-windows-msvc -p tuxbox-xmem --tests   # passes

The unit tests were compiled but not run: no link.exe on this host.

ProjectScarlett:

  • Before: main plus local patches, private backing. The run died at the mission start on alias ... write fault not promoted (error 170), or stalled on labels that the CPU never saw written.
  • After: the same build plus this change and #439. No alias faults, no copy-queue rejections, no label-hold timeouts, and the run reached the mission. It then stopped on a separate mesh-shader GPU fault.

Checks

No evidence JSON changed.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5549994745 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/464). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-29T10:51:34Z. --- ## Summary Fixes #456. **Problem.** Every mapping of a physical page is the same memory, and a title reads and writes through whichever mapping it likes. With private backing, a second mapping stays inaccessible until its first access promotes it. Promotion is refused (`ERROR_BUSY`) while a host import holds the page, so that first access kills the title. In ProjectScarlett this ended every run about 100-170 frames into the first story mission. **Change.** Newly mapped pages go through their section (`map_shared_page` / `map_contiguous`). A second mapping then needs no promotion, and a hold can't block it. `TUXBOX_XMEM_PRIVATE_VIEWS=1` restores private backing. **Two `CopyPageMappingsX` fixes that follow from it:** - **Held view at the destination.** An unmapped held page keeps its section view for the import (`DeferredKind::SectionPlaceholder`). A later copy that maps a GPU alias over that address failed with `ERROR_INVALID_ADDRESS`, and the copy queue dropped every later batch (`copy queue rejected a guest command-list batch (0x800701e7)`). The queue drains its GPU work before the copy and retires the overlapping imports after it, so the copy now releases that view first. - **Former private slot.** A GPU alias slot that held private memory now takes a private copy of a section-backed page, as other GPU aliases do. Its imports resolve the token's backing. **Trade-off.** Section-backed pages have no write watch (`tracking.rs`), so the d3d12 provider digests their textures instead. With #439, the run below kept that cost low. ## Tested - [ ] The checks relevant to this change passed (`xmem`): only the type check and ProjectScarlett runs (below). The `xmem` suite hasn't been run. - [ ] Changed or new behaviour is covered by a Lanes scenario: no. Covered by unit tests in `tests/physical_backing.rs` instead: - the existing tests pin private mode through one shared lock (`backing_mode`); - a new test maps a held page a second time and checks both mappings are the same memory, with no promotion. - [ ] AMD and NVIDIA: AMD only. NVIDIA still needs to run the checks. GPU, driver and backend: RX 9060 XT, RADV (Mesa), GE-Proton11-14, vkd3d-proton. Commands run and their results: ```text cargo check --locked --target x86_64-pc-windows-msvc -p tuxbox-xmem --tests # passes ``` The unit tests were compiled but not run: no `link.exe` on this host. **ProjectScarlett:** - **Before:** `main` plus local patches, private backing. The run died at the mission start on `alias ... write fault not promoted (error 170)`, or stalled on labels that the CPU never saw written. - **After:** the same build plus this change and #439. No alias faults, no copy-queue rejections, no label-hold timeouts, and the run reached the mission. It then stopped on a separate mesh-shader GPU fault. ## Checks No evidence JSON changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NickStallman commented 2026-11-29 12:30:09 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T12:30:09Z.


NVIDIA evidence (RTX 5090, 620.70.10, GE-Proton11-14), one run each of the same build (main d2eb99ed + #462, #463, #455, #461, #441 and diagnostics), same warm caches:

default (section-backed) TUXBOX_XMEM_PRIVATE_VIEWS=1
After the first story load ran about 440 s, then Xid 109 (GPU timeout) ended after about 100 s
Ending no title or provider access violation at the end access violation in XCRDAPI.dll (worker thread)
Xid 13 memory fault none none

The access violation came in the private run only, which fits the "held page not promoted" fault #456 describes, but I didn't decode the address, so it is consistent with it, not proven. Two runs can't say more.

On cost: placed-texture pages now show as section-backed (median 8 GiB/s, up to 41 GiB/s, of section texture memory in the watch line, against 0 with private views). That didn't show up as a clear difference in frames per 20 s between the two runs (both fell to a few frames per 20 s within about 60 s of the story), but I'd not call it measured: the runs differ in what they reached.

<!-- greyfinch-sync:brcly/TuxBox:comment:7255857784 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/464#issuecomment-7255857784). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T12:30:09Z. --- NVIDIA evidence (RTX 5090, 620.70.10, GE-Proton11-14), one run each of the same build (`main` `d2eb99ed` + #462, #463, #455, #461, #441 and diagnostics), same warm caches: | | default (section-backed) | `TUXBOX_XMEM_PRIVATE_VIEWS=1` | |---|---|---| | After the first story load | ran about 440 s, then Xid 109 (GPU timeout) | ended after about 100 s | | Ending | no title or provider access violation at the end | access violation in `XCRDAPI.dll` (worker thread) | | Xid 13 memory fault | none | none | The access violation came in the private run only, which fits the "held page not promoted" fault #456 describes, but I didn't decode the address, so it is consistent with it, not proven. Two runs can't say more. On cost: placed-texture pages now show as section-backed (median 8 GiB/s, up to 41 GiB/s, of section texture memory in the watch line, against 0 with private views). That didn't show up as a clear difference in frames per 20 s between the two runs (both fell to a few frames per 20 s within about 60 s of the story), but I'd not call it measured: the runs differ in what they reached.
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
brcly/TuxBox!464
No description provided.