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. |
|
Independent desktop NVIDIA verification of PR #2307 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib hle::kernelx::alias:: -- --test-threads=1 --nocapture (default env, 3 runs) |
5 passed; 0 failed; 0 ignored; 1139 filtered out × 3 (0.02s × 3, 0 skipped: a_page_mapped_into_two_spaces_is_one_page_and_writes_reach_both, a_page_moved_outside_the_spaces_goes_and_comes_back_with_its_bytes, a_page_not_from_the_title_is_refused, pages_read_and_written_by_number_are_the_pages_the_title_sees, remapping_an_address_shows_the_new_page_and_keeps_the_old_one) |
cargo test --release -p xcl --lib hle::kernelx:: -- --test-threads=1 (default env, 3 runs) |
58 passed; 0 failed; 1 ignored; 1085 filtered out × 3 (1.15s, 1.14s, 1.15s, 0 skipped) |
XCL_PAGE_ALIAS=1 cargo test --release -p xcl --lib hle::kernelx:: -- --test-threads=1 (opt-in env, 3 runs) |
49 passed; 9 failed; 1 ignored; 1085 filtered out × 3 (0.97s, 0.98s, 0.98s; all 5 alias::, 8 guards::, 7 sections::, and 2 lazy:: tests pass; see note below on the 9 pre-existing UMA-home unit tests) |
cargo build --release -p xcl |
Clean build (1m 14s, exit 0, 0 new warnings in non-test build; inherits 1 unused_assignments #[cfg(test)] warning from stacked #2294 at crates/xcl/src/hle/kernelx/guards.rs:366:9) |
Observation on hle::kernelx:: under process-wide XCL_PAGE_ALIAS=1: All 58/58 tests pass 3/3 in the default environment. With XCL_PAGE_ALIAS=1 set process-wide, all 22 alias::/guards::/sections::/lazy:: tests pass 3/3, while 9 pre-existing UMA-home tests in hle::kernelx::tests:: fail deterministically (3/3): 7 (a_home_decommitted_in_the_same_call_is_asked_again, a_page_away_at_another_home_goes_home_with_it, a_page_away_from_home_is_committed_once, mapping_fresh_pages_does_not_query_each_page, mapping_lazy_pages_again_does_not_query_each_page, pages_mapped_again_at_another_address_keep_what_was_written, pages_mapped_again_at_the_same_address_keep_what_was_written) panic on page_home(...).unwrap() returning None (because XCL_PAGE_ALIAS=1 backs physical pages with section slices instead of UMA homes), and 2 (physical_pages_in_uma at kernelx.rs:2371 and scatter_matches_a_model_of_physical_pages at kernelx.rs:2624) expect MapTitlePhysicalPages(NULL, ...) to return a UMA-home address.
Paired quiet 60 s retail smoke (title: 29640639)
Exact parent & merge-base (568e7db7729c8fa6c8f0f4b32d798faaf11462bb, cached baseline on the same machine):
xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14527 MB
PR #2307 (f30ca3f037e474fe1ca1720835313db161b36004, default flags — XCL_PAGE_ALIAS unset):
xcl-smoke v1
commit: f30ca3f037e474fe1ca1720835313db161b36004
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14515 MB
PR #2307 (f30ca3f037e474fe1ca1720835313db161b36004, opt-in XCL_PAGE_ALIAS=1):
xcl-smoke v1
commit: f30ca3f037e474fe1ca1720835313db161b36004
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1558 (PresentX 1558)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13150 MB
Observations & limits of coverage
- Both default (
XCL_PAGE_ALIASunset) and opt-in (XCL_PAGE_ALIAS=1) 60 s retail smokes ontitle: 29640639exited0x0with0device removals,0crashes, and steady60 60 60presents per 2 s; underXCL_PAGE_ALIAS=1, peak process commit dropped from14515 MBto13150 MB(-1365 MB,-9.4%vs. default run on the same commitf30ca3f0). - Frame-count variance (
1558vs.1608) between single 60 s runs was not multi-run profiled; visual texture correctness under extended gameplay beyond the 60 s startup/streaming window was not separately inspected.
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
|
Independent test on Windows 11 build 26200, Ryzen 7 8845HS, RTX 4060 Laptop 8 GiB (driver 32.0.16.1656), 16 GiB RAM, Rust 1.98.1 MSVC. I integrated the exact #2307 head
Historical evidence from a separate earlier integration on this RTX 4060 Laptop at an exact matched Series S checkpoint (4,200 DirectStorage requests, 262 MiB, zero storage failures on both):
The system commit growth difference was 7,441 MiB. Both historical runs subsequently crashed in separate paths, one during a concurrent texture decommit and the other in the null scatter-unmap. World entry was unverified. These measurements belong to that integration. 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. AI use: Codex (GPT-6 family, exact runtime variant unavailable) recovered the private historical artifacts, compared sources, ran the focused tests, and drafted this comment. |
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) (cherry picked from commit 785d7dc) Lab port: applied unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The worker rereads late-filled destination lists, but the conventional liveness index never recognizes an alias allocation. Use section-backed IDs in alias mode and remember individual releases while their backing block remains open. Recover the liveness correction from the historical section-alias integration on top of xcl-dev#2307. Verify a partially released block and the existing late-filled DirectStorage request in alias mode. Assisted-by: Codex (model version not exposed) (cherry picked from commit cfe04f4) Lab port: applied unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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>
… 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>
|
Review finding for f30ca3f (#3211 workstream B), with a regression test that fails here and passes with a one-line fix. I tested it at #3075's head 4fdd282, where With
Test (alias.rs):
Results:
Patch (fix + test)@@ unsafe fn map_one(at: usize, page: usize, _mapping: &std::sync::MutexGuard<'_, (
if !committed(page) {
// a page never used: committed at its first touch here (or through its home)
lazy::mark(at);
+ } else {
+ // the address shows the page's bytes from now on: uploaded there like a write
+ guards::written(page);
}
return Ok(());
}
@@ mod tests {
+ #[test]
+ fn a_page_with_bytes_mapped_at_a_new_view_is_uploaded_there() {
+ let _g = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
+ let p = pages(2);
+ let s = reserve_space(3 * PAGE).unwrap();
+ unsafe {
+ assert!(map(s, &[p[0]]));
+ write64(s, 11);
+ assert!(write(&[p[1]], 0, &22u64.to_le_bytes()));
+ dirty();
+ // a second view of a page that holds bytes: that address now shows them
+ assert!(map(s + PAGE, &[p[0]]));
+ assert_eq!(read64(s + PAGE), 11);
+ assert!(dirty().contains(&(s + PAGE)), "the new view of a written page is uploaded");
+ // an address that showed one page shows another that holds bytes
+ assert!(map(s, &[p[1]]));
+ assert_eq!(read64(s), 22);
+ assert!(dirty().contains(&s), "a view remapped to a written page is uploaded");
+ free_space(s, 0, mem::MEM_RELEASE);
+ free(&p);
+ }
+ }Tested (RTX 2070 SUPER, Windows 11, debug, Whether this explains any of the zero-sampled textures in #505 is not established. This is a static finding plus a unit test, with no retail run. Not tested: retail title, AMD, GPU-side readback (the test checks what is handed to the upload, not what the GPU holds). AI use: Claude Code (Claude Opus 5.5) found the issue and wrote the test and fix; the comment was checked by @KOLESNiii before posting. |
|
On The
My reading of the code:
The mirrors code reached What I think a fix needs:
Not tested: a fix; AMD. RTX 5070 Ti, driver 621.40, Windows 11. |
|
Triage note: this no longer merges with current 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. |
|
Stacked on #2294 / #2293 (only
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
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