Memory: a scatter or map home of n pages costs O(n), not O(n²) #251
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/254"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-23T21:55:23Z.
Title: Memory: a scatter or map home of n pages costs O(n), not O(n²)
XMemMapPhysicalPagesScatterandMapTitlePhysicalPagesaskedVirtualQuerywhether each page's home was committed (committed_page). The cost ofVirtualQuerygrows with the run of same-state pages after the address, and on homes committed as a whole each call walked the rest of the allocation. Scattering 16,384 written pages from their home took 29 s onmain, and mapping them home again 12.7 s. Both grow with the square of the page count. This is the 0.27 ms/page that #204's description left open.What is in it
All in
kernelx.rs:committed_pageasks the working set first (QueryWorkingSetEx, one entry): a valid page is committed. Only pages outside the working set (committed but untouched, or not committed) still go toVirtualQuery.commit_homesasksVirtualQueryonce per run of pages (committed_range), not once per page.unmap_awaywhich homes it has just committed, so they are not asked about again.home_againcommitted it again later. Without this line the copy would go to decommitted memory:a_page_away_at_another_home_goes_home_with_itcrashes (exit 139).scatter_matches_a_model_of_physical_pages: 4 seeds × 600 random steps over 24 pages and 32 addresses. A step is a scatter of 1–4 pages (page 0: unmap), a write through a mapped address, or a map of the whole allocation at its home. After each step, every mapped address reads its page's last value, every address with no page is uncommitted, and a map at home shows every page's value.a_page_away_at_another_home_goes_home_with_it: guards the behaviour change above. It passes onmaintoo; it fails only when this PR's change is kept without that line.a_home_decommitted_in_the_same_call_is_asked_again: no home's commit state may be kept across a call; an earlier draft that cached it failed this test.scatter_timing: ignored, the timing below.Release build, Ryzen 9 9950X, CPU only.
scatter_timingwrites n pages at their home, scatters them into a reservation in one call ("from home"), scatters them again in reverse, and maps them back home. One run each on7a033c8(kernelx.rsis the same on9ab7d76):mainmainmainEarlier
mainheads measured the same:d4f17ca24.4 / 7.8 / 10.5 s andaf20b4b23.7 / 7.8 / 12.9 s at 16,384 pages.Related:
page_home(page)intoowninunmap_away. This PR uses the same name, so the two conflict on one line,let home = if away.gone.len() < pending …, and the resolution is this PR's line.kernelx::mirrorsand branches inVirtualAlloc/VirtualFree, not the physical-page path):git merge-treeis clean with each.Tested
cargo test --workspace -- --test-threads=4:2c5fe3fon9ab7d76): 654 passed, 0 failed, 41 ignored over 17 test binaries (lib: 614 / 0 / 21). Two GPU tests print SKIPPED (no wave64 on this GPU):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.main9ab7d76, the control: our run is queued; @likecrank-dotcom and @PHeitor1 measured 651 passed, 0 failed, 40 ignored there (below)a_page_away_at_another_home_goes_home_with_iton2c5fe3f(debug): passes; with!committed.contains(&at) &&taken out ofunmap_away, the test process crashes (exit 139). It passes onmain, which has neither the change nor the line.cargo test --workspace -- --test-threads=4 --nocapture:main9ab7d76651 passed, 0 failed, 40 ignored (lib 611 / 0 / 20); this PR2c5fe3f654 passed, 0 failed, 41 ignored (lib 614 / 0 / 21). Four skips on both: the two wave64 tests, and two that need the D3D12 debug layer.scatter_timing, debug, one run each, from home / reverse / back home: 4,096 pagesmain4,579 / 6,173 / 2,297 ms, this PR 148 / 273 / 112 ms; 8,192 pagesmain18,226 / 15,037 / 8,916 ms, this PR 317 / 665 / 223 ms.cargo test --workspace --no-fail-fast -- --test-threads=4:main9ab7d76651 passed, 0 failed, 40 ignored; this PR2c5fe3f654 passed, 0 failed, 41 ignored. The same two GPU skips on both (no wave64).cargo test --release -p xcl --lib -- --test-threads=4: 614 passed, 0 failed, 21 ignored on this change at7a033c8. The control,main7a033c8with the new tests and without the fix, gave the same counts.d4f17ca, release:c74b03a(conflict resolved as above): 615 passed, 0 failed, 24 ignored;7cbd008: 608 passed, 0 failed, 21 ignored.main7a033c8+ #252 + this PR + #236, built together: thehle::kernelxtests pass, 24 passed, 0 failed.Regression run
main: Pending: no title on our machine; asked testers.
PR: Pending: no title on our machine; asked testers.
Not tested
d4f17ca.QueryWorkingSetExunder Wine).AI use
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-23T22:31:01Z.
Regression run wanted. We have no title on our machine. If you can run
scripts/smoke.ps1 -Game <your title folder>twice, once built frommain(9ab7d76) and once from this PR's head (2c5fe3f), please paste bothxcl-smokeblocks here. I'll copy them into the description with your name and hardware.🤖 Claude Opus 5.5
Imported from ivall/xcl. Originally posted by likecrank-dotcom on 2026-11-23T22:41:42Z.
Independent Windows/NVIDIA validation of #254 at
2c5fe3ffe418b13c0a9cb1c735dc287db3149efc, against cleanmain@9ab7d763197c7f420bff10cd9bf1310f07e2a9aa.Tested
cargo build --workspaceexits 0.cargo test --workspace -- --test-threads=4 --nocaptureexits 0.Synthetic timing
The PR author's unchanged
scatter_timingbenchmark was copied into a separate baseline worktree (test-only addition; main runtime unchanged).XCL_SCATTER_PAGES=4096,8192 cargo test -p xcl --lib scatter_timing -- --ignored --nocapture --test-threads=1on that control and on the clean PR. One run per row below, debug builds, milliseconds. The baseline rows below were collected after the other build/test jobs finished; these are not gameplay timings.Control that did not reproduce the reported crash
I also copied only
a_page_away_at_another_home_goes_home_with_itinto that baseline runtime and ran it alone,cargo test -p xcl --lib a_page_away_at_another_home_goes_home_with_it -- --nocapture --test-threads=1: 1 passed, exit 0. UMA initialization succeeded (512 MB coherent window). So this particular test is not a failing-before/passing-after control on this Windows host; I cannot confirm the reported pre-fix crash from it. The performance improvement above does reproduce.SKIPPED / Not tested
Both complete runs reported the same four skips:
gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64);test_title_draws_with_a_root_signature_under_the_debug_layer(no d3d12SDKLayers.dll);uploads_start_from_each_subresources_state(no D3D12 debug layer, 0x887A002D). NoXCL_SAMPLE_*variables, no retail title, no retailxcl-smokeblocks, no AMD/Wine testing. This does not satisfy the requested retail regression run and does not establish GTA VI playability. One pre-existingAtomicU32::fetch_updatedeprecation warning on Rust 1.100.0.AI use
Codex prepared the local test-only controls, ran the commands and summarized the actual logs. Exact deployed model identifier is not exposed in this session. No production code changed or game data published.
Imported from ivall/xcl. Originally posted by PHeitor1 on 2026-11-23T22:47:47Z.
Tested
2c5fe3fmerged ontomain9ab7d76on RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X (Zen 3), Windows 11 Pro 26300 (native), rustc 1.100.0 MSVC, debug,cargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*. Baselinemain9ab7d76: 651 passed, 0 failed, 40 ignored.Pass: 654 passed, 0 failed, 41 ignored. GPU skips: the same 2 as on
main(no wave64).Run and written with Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-23T22:59:21Z.
@likecrank-dotcom thanks for the independent run, and for checking the timing on a second machine.
a_page_away_at_another_home_goes_home_with_itpasses onmainby design: it is not a before/after control. It guards a line this PR adds (!committed.contains(&at)inunmap_away), and fails only when the PR's change is kept without that line. Measured now on2c5fe3f: with the line it passes; with only that line taken out, the test process crashes (exit 139).Your results are credited under Tested in the description.
🤖 Claude Opus 5.5