Skip to content

kernelx: preserve null scatter unmaps with physical aliases - #3074

Open
ZekkJJ wants to merge 6 commits into
xcl-dev:mainfrom
ZekkJJ:codex/physical-alias-null-scatter
Open

ZekkJJ wants to merge 6 commits into
xcl-dev:mainfrom
ZekkJJ:codex/physical-alias-null-scatter

Conversation

@ZekkJJ

@ZekkJJ ZekkJJ commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2307, which carries #2293 and #2294 by @adiologydev. Review the final commit, 785d7dc5533edc8577c9a8e8e221acd40d980d23, against the clean integration parent 3878609d850826fa51813477ffa7482081fb2383. The prerequisite commits are the original upstream commits. Focused diff

On main, #495 by @notdxbi treats a null XMemMapPhysicalPagesScatter array as an unmap for each address. Integrating #2307 onto current main preserves the legacy branch's null handling, but the section-backed branch still advances the null pointer. Starting at the second entry, map_aliased tries to read a page number at address 0x8. An archived retail crash with matching PDBs resolves to map_aliased <- XMemMapPhysicalPagesScatter.

What is in it

  • Pass the null page array through unchanged in the alias branch. The existing map_aliased path already interprets it as an unmap.
  • Exercise two null scatter entries, shared contents through surviving aliases, remapping in reverse order, and final page-ID release.

Tested

  • Windows 11 build 26200, Ryzen 7 8845HS, 16 GiB RAM, NVIDIA RTX 4060 Laptop GPU 8 GiB, driver 32.0.16.1656, Rust 1.98.1 MSVC.

  • On 785d7dc5533edc8577c9a8e8e221acd40d980d23 with XCL_PAGE_ALIAS=1, the focused filters for kernelx alias, sections and guards, DirectStorage physical pages, and concurrent-decommit texture reads gave 23 passed, 0 failed, 0 ignored, 0 capability skips.

  • The existing byte-exact GPU mirror upload fixture passed in conventional mode. Alias mode fails its write-watch setup assertion before readback, matching the prior Windows report on the prerequisite. Prerequisite test report

  • After building the test-title fixtures with cargo build --workspace, cargo test --workspace --no-fail-fast -- --test-threads=4 exited 0. The harness reported 1,486 pass statuses, 0 failures, and 47 ignored. It emitted 27 explicit skip notices separately (21 missing wave64, 3 unsupported per-lane forms, 1 Developer Mode requirement, 1 missing heap-window capability, and 1 default-mode skip of the new opt-in test, which passed separately).
    Regression run

The clean release builds are main 6089122a1c96dff16e93b6fdf04c8ed20cfb6102 and candidate 785d7dc5533edc8577c9a8e8e221acd40d980d23. No fresh smoke block was generated. The clean Series S preflight expired at 3205 MiB free RAM and 13200 MiB free commit. The guarded runner requires 6,600 MiB RAM and 18,000 MiB free commit at startup. The last idle check still showed 4129 MiB RAM and 13941 MiB free commit. Series X was deferred.

Historical evidence from a different integration, using the same executable in both Series S modes, reached 4,200 DirectStorage requests and 262 MiB with zero storage errors in both. System commit growth was 9,426 MiB in conventional mode and 1,985 MiB with section aliasing, a difference of 7,441 MiB. Both runs later crashed. The conventional crash was a texture read during concurrent decommit. The alias crash was the null scatter path covered here. This historical measurement belongs to the alias architecture and accompanying integration.

Not tested

  • Alias-mode GPU readback remains blocked at fixture setup. World entry and sustained gameplay remain unverified.
  • AMD and Intel GPUs, or Wine.

AI use

Codex (GPT-6 family, exact runtime variant unavailable) recovered and compared the patches, wrote the follow-up and regression test, ran local validation, and drafted this description.

adiologydev and others added 6 commits November 25, 2026 16:39
…addresses

On the console a physical page mapped at several addresses is one page. XCL
keeps a page at one address at a time and copies it when the title maps it
elsewhere (`move_away`), so the other addresses go stale; a retail title maps
its streamed pages into a pool, into the CPU view of a 24 GB reservation and
into that reservation's GPU view (xcl-dev#1031).

`kernelx::sections` is the base for real aliasing: a block of physical pages
is one pagefile-backed SEC_RESERVE section, and a page is mapped as a view of
its 64 KiB slice into a placeholder (MapViewOfFile3 with
MEM_REPLACE_PLACEHOLDER). Every view of a slice is the same memory and a page
takes commit once, when it is committed through any view. Unmapping leaves a
placeholder for the next view. Ordinary reserved memory (write-watched if
asked) can replace part of a placeholder and go back to one.

Nothing calls it yet. Measured in a standalone program on Windows 11 26200
over 200 000 pages: map 2.2 us, unmap 2.75 us, commit 0.9 us a page.
GetWriteWatch refuses a range that holds a view (error 87), and one call
cannot span two neighbouring reservations either.
The upload of title memory to video memory (`d3d12x::sparse`) and the
textures kept in step with title memory learn what the CPU wrote from the
write watch, and a view of a section (`kernelx::sections`) cannot be
write-watched: GetWriteWatch refuses any range that holds one.

`kernelx::guards` keeps the views of a physical page read-only. The first
write through any of them faults; a vectored handler makes that view
writable, notes the page and lets the write go on. `take_dirty` hands over
the pages of every view of each page written – a write through one view is
a write to all of them – and guards those views again before their bytes are
read, so a later write is caught again and an earlier one is in what is read.

Kernel calls do not fault into the handler, they fail: `lazy::ensure`, which
XCL already calls before a kernel call or its own code writes title memory,
opens the guards there first and counts the write. A view committed by the
lazy handler is writable and counts as written. Both take no lock until a
view has been watched.

Nothing watches a view yet.
… fault

A guarded view of a physical page (`kernelx::guards`) is read-only until it
is written. Code of XCL's own that writes there faults into the guard and
goes on, but a kernel call does not fault: ReadFile into such a view fails.
`lazy::ensure` opened the views first, yet the submit thread's `take_dirty`
could guard them again before the write – between DirectStorage's check of
its destination and the copy, or before the kernel wrote a ReadFile buffer.

`guards::open` now returns `Opened`, which keeps its views writable until it
is dropped; `take_dirty` uploads a pinned view but does not guard it again,
and the end of the write counts as a write. `lazy::ensure` returns it and its
callers hold it across their write: the routed ReadFile for a synchronous
read, and the destination checks of DirectStorage and the CPU-side
bottom-of-pipe writes. An overlapped ReadFile writes after the call returns:
its views stay open until its OVERLAPPED is no longer STATUS_PENDING, which
`take_dirty` reads without faulting (the title may free it once done). A
retail title reads 271 MB that way into the CPU view of its 24 GB
reservation 8.5 s after start.

`guards::written` counts a page as written through all its views when XCL
writes it by page number.

Nothing watches a view yet, so nothing changes without views.
…s mapped at

Without it XCL keeps a physical page at one address at a time and copies it
when the title maps it elsewhere; the console shows the page at every
address it is mapped at. A retail title maps its streamed pages into a pool,
into the CPU view of a 24 GB reservation and into that reservation's GPU
view (xcl-dev#1031).

With `XCL_PAGE_ALIAS=1` (`kernelx::alias`):
- a block of physical pages is a section (`kernelx::sections`) with a view
  of its own, through which XCL reads and writes pages by number
  (DirectStorage); the title never maps a page there;
- the title's reservations of 64 KiB pages with no commit (its CPU view, GPU
  view and pool) are placeholders, and a page mapped there is a view of its
  slice, guarded (`kernelx::guards`) so that a write through one view is
  uploaded at all of them; `title_textures` adds those pages to what the
  write watch found;
- a page mapped anywhere else (a placeholder region the title made in a
  sparse window) is moved there and back with its bytes, as before.

Pages are committed on first use as before (`kernelx::lazy`); whether a page
is committed is a bit per page: asking Windows walked the rest of a fresh
block, and a title mapping 100 000 new pages one at a time took 20 s longer
to its first frame.

Measured in a traced run of a retail title: 3 blocks (11 360, 2 960 and
99 776 pages), 131 072 map calls in 150 s, nearly all single pages into its
plain reservations, none at a page's home, no commit inside them.
The alias path must forward a null page array as an unmap, as the conventional path does after xcl-dev#495. Advancing the null pointer makes the second entry look like an array at address 0x8.

Test a two-entry scatter unmap, surviving aliases, swapped remapping, and release through the section-backed path from xcl-dev#2307.

Assisted-by: Codex (model version not exposed)
@grahamster2

Copy link
Copy Markdown
Collaborator

Retail world test of #3074 + #3075 with XCL_PAGE_ALIAS=1: it reaches the world, ran the full 720 s without a crash, and uses much less memory.

Setup

Results

alias off (run 93) XCL_PAGE_ALIAS=1 (run 99)
Presents per 2 s in the world (last 12 samples) 5–6 19–26
Peak process commit 33.4 GB 20.9 GB
Process private at the end 34.2 GB 21.1 GB
System commit at the end 49.7 GB 44.0 GB
D3D12 driver write-combined/uncached private 13.8 GB 9.1 GB
Device removed / panic none none

Caveats

  • This is one run each, so treat it as a single A/B pair, not a benchmark.
  • On this NVIDIA setup main renders a grey picture in the world either way. I can't say anything about rendering correctness in alias mode, only that the world loads, the title keeps submitting and presenting, and nothing crashed.
  • Free physical RAM still went down to about 2.5 GB near the end. The aliased pages count as shared rather than private, so process private understates how much RAM the run used. System commit (−5.7 GB) is the fairer comparison for that.

@ZekkJJ

ZekkJJ commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@bmjask mind reviewing this when you get a chance? We've got independent retail validation now, with noticeable rendering and stability improvements.

jessenic pushed a commit to jessenic/xcl that referenced this pull request Nov 28, 2026
The queue's CopyPageMappingsBatchX maps pool pages into GPU views; on the
console a GPU-view page then shows the physical page mapped at its pool page
at the time of the call. xcl-dev#1055 decodes the calls and keeps a record of them;
with physical pages aliasing (`kernelx::alias`) the GPU view is a reservation
of views, so the decoded mappings are made for real: each GPU-view page
becomes a view of the physical page mapped at its pool page now, or is
unmapped (kind 2, or nothing mapped at the pool page). Textures in the GPU
view then read the page at their own address (`title_textures` prefers an
address with a physical page mapped), and a write through any view of the
page is uploaded at all of them.

Without the switch nothing changes: the call is recorded as in xcl-dev#1055.

(cherry picked from commit 64ad64c)

Lab port: fitted onto the follow-ups of xcl-dev#3074/xcl-dev#3075, which this commit's parent (xcl-dev#2307) did not have: apply_page_mappings holds the mapping lock for the call and passes it to map_one (now a Result), with the pool page looked up under it; a pool page whose view outlived its freed page counts as an empty pool page instead of ending the call midway (test added). The textures on the mapped pages are named to title_textures through the lab's per-page changed list (mirrors::note_changed, after the pages are in place) instead of upstream's note_gpu_view_mapping, which bumps the generation and has every texture's source read again: the title's calls come by the hundred.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
jessenic added a commit to jessenic/xcl that referenced this pull request Nov 28, 2026
… stand down, and the log says which is at work

Lab port of the upstream alias stack (xcl-dev#2293, xcl-dev#2294, xcl-dev#2307, xcl-dev#2308, xcl-dev#3074,
xcl-dev#3075). The lab's two stopgaps for a physical page at more than one address
keep the page at ONE address and move it (bring_page / bring_range,
XCL_PAGE_BRING) or its video memory (sparse::share_page, XCL_PAGE_SHARE=1).
With real aliases a page is at every address the title mapped it at, outside
the sparse windows, and an address it is not at was unmapped by the title:
both stand down when XCL_PAGE_ALIAS=1. With the switch not set they are as
they were.

One line at start-up (the first time the switch is asked) names which of the
three is at work; with aliases, a line at the first view and at each power
of two from 1024 on says how many pages are shown at how many addresses and
how many of them at more than one (guards::view_counts).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@brainhay5

Copy link
Copy Markdown

Triage note: this no longer merges with current main (mergeable=false), so it cannot be built or tested as it stands.

Why I am asking rather than just noting it: we have run fifteen mergeable candidates on the retail title on an RTX 5070 Ti, and every one still stops presenting at 50–80 s (device removed, surfacing ~88 s later on the next allocation). The PRs whose descriptions actually match that symptom are the ones that no longer apply — this is one of them. A rebase would make it testable again, and we will run it and report the numbers.

If it has been superseded by merged work, saying so is enough and it can be closed.

AI use: an agent posted this triage note.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 785d7dc

Stacked on #2307 (section-backed physical page aliases, still open); only the top commit 785d7dc belongs here. #3075 is stacked on this PR and contains it, which is not a duplicate.
The fix in kernelx.rs:XMemMapPhysicalPagesScatter passes a null page array through to map_aliased, which already treats it as an unmap, instead of advancing the null pointer; scatter_without_pages_unmaps_only_the_listed_aliases covers it (only with XCL_PAGE_ALIAS=1, otherwise skipped). No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 785d7dc, diff read, not a merge-check; conflicts with main, PR description red: no smoke blocks):

Fine: the fix itself (kernelx.rs ~1529-1533). A null array reaches map_aliased as page 0, and map_one unmaps it. Aliasing is off by default and read once. The archived retail crash stack (map_aliased <- XMemMapPhysicalPagesScatter) backs the bug. #3075 is stacked on it.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

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