Repository navigation
kernelx: XCL_PAGE_ALIAS=1 shows a physical page at every address it is mapped at - #2307
adiologydev wants to merge 4 commits into
Conversation
…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.
|
Tested: head Default (switch off): With
On the #2308 branch, which carries these same alias tests unmodified apart from one added test, flag-off runs also fail at real assertion lines ( Not tested: native Windows CI behavior (upstream CI presumably sees these green, so the delta is lane-specific); retail titles (no title data on this lane, counts only). AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting. |
|
Native Windows check of Tested
Not tested A mirror readback using an alias-aware fixture, Wine, retail smoke, and the full workspace suite. AI use OpenAI Codex (GPT-6.2 Sol) ran the checks and wrote this report. |
|
Tested: PR #2307 at head Setup
Results (MB unless noted; times are seconds from the start of the run; "process commit" = the
All six: 0 device removals, 0 crashes, 0 driver events, no ERROR lines. Peak private working set (not in the table): A 16317 / 15400 / 17122, B 11315 / 11595 / 12091. Not a measure of "world entry": the title never got past loading in any run. All six stop presenting between about 66 and 74 s and show 0 presents for the rest of the 300 s. I use the first ListX Log content: the same 25 to 26 WARN types in every run, no type present only in A or only in B. Counts: 80 / 77 (cut at 156 s) / 79 WARN lines in A, 77 / 79 / 77 in B. 40 "mesh pipeline ... refused" lines in each run. DirectStorage "request failed" lines: A 3 / 0 / 2, B 0 / 2 / 0 (different files each run). No log line mentions the switch; the 16 "CreatePlacedResourceX ... aliases an earlier resource" lines are in A and B alike. Reading
Frames: I looked at the frame dumps of all six runs ( Not tested
Run and written with Claude Code (Claude Fable 5.2 and Claude Sonnet 5.5). |
…sing stack) Integrates upstream PR stack xcl-dev#2293 -> xcl-dev#2294 -> xcl-dev#2307 -> xcl-dev#2308 (opt-in real section-slice physical page aliasing across virtual views via XCL_PAGE_ALIAS=1).
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
@adiologydev a data point from the retail title on an RTX 5070 Ti that may point at this PR. With What the Its caller fixes up a pointer that sits inside a loaded resource. Its value should be a resource-relative address:
So the resource's bytes are not what was read from the file when the title walks them. Either they were never written, or they were written where the CPU is not looking. Our game crash logs put it during the intro's streaming ("Prestream"). The A/B. The tree is
Without the switches, the over-budget video memory went into system RAM. I stopped the run at 265 s with 0.4 GB of RAM free; a repeat was stopped at 134 s at 35 GB. With the switches the run is over budget too, but system RAM held: a later run lasted 304 s. The earlier runs with the same Update: a later run with What I have not checked:
If you have a trace switch for "a page shown at an address got new contents through another mapping", I can run it. AI-assisted. |
Stacked on #2294; only the top commit (
f30ca3f) belongs here. Third part of the plan on #1031: behindXCL_PAGE_ALIAS=1(off by default), a physical page shows at every address the title maps it at.Measured in a traced run of a retail title first (local logging, not in the PR): it allocates 3 blocks of physical pages (11 360, 2 960 and 99 776 pages), and in 150 s makes 131 072 map calls, nearly all single pages, into its plain reservations of 64 KiB pages (the CPU view of its 24 GB pair and its 6.2 GB pool) – never at a page's home, and it never commits memory of its own inside them. 5 calls (2 960 pages) go into a placeholder region it made in a sparse window.
What is in it (
f30ca3f)crates/xcl/src/hle/kernelx/alias.rs(new), withXCL_PAGE_ALIAS=1:crates/xcl/src/hle/kernelx.rs: the switch inVirtualAlloc/VirtualFree(Ex),Allocate/Free/MapTitlePhysicalPages,XMemMapPhysicalPagesScatter,read/write_physical_pages,physical_page_at; a commit inside such a reservation is refused (never seen) with a warning.d3d12x/title_textures.rs: the guarded pages join what the write watch found.lazy.rs: a view the lazy handler commits sets its bit.sections.rs:release_all.Tested
NVIDIA GeForce RTX 5090 32 GB (driver 621.40), AMD Ryzen 9 7950X, 64 GB RAM, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2609 (
XCL_DXC_DIR), debug tests, release runs.cargo test --workspace -- --test-threads=4onf30ca3f: 1114 passed, 4 failed, 26 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(CreateComputePipelineState→E_OUTOFMEMORYon this card, DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905);main568e7db fails the same 4 here (1094 passed, 4 failed, 26 ignored). SKIPPED (23, the same onmain): 20 need 64-lane waves ("no wave64"), 3 per-lane f16 refusals inlower_dxil::tests::{f16,f32}_programs_on_the_gpu.The retail title with
XCL_PAGE_ALIAS=1, againstmain568e7db, the same route into its world (pad A at the account prompt, A A at the title screen), 240 s each, runs interleaved (the pipeline cache warms with every run):XCL_PAGE_ALIAS=1(f30ca3f)main568e7dbmain568e7dbXCL_PAGE_ALIAS=1(f30ca3f)About 7 GB less peak commit with the switch; frames and the time of the last frame are within the run-to-run spread (an earlier single pair showed more frames with the switch; it did not hold up here).
Regression run (the switch off, as the PR checks run it)
scripts/smoke.ps1 -Game <retail title> -Seconds 60, no input,mainfirst, same machine (each run'sxcl.exebuilt from a clean checkout of its commit):Not tested
AI use