Repository navigation
Memory: a scatter or map home of n pages costs O(n), not O(n²) - #254
Conversation
VirtualQuery's cost grows with the run of pages in one state that follows the address: on homes written as a whole it took 0.25 ms or more a call. map_pages asked it about each page's home, and the walk was the rest of the allocation, so scattering 16,384 pages from their home took 24 s, and mapping them home again 10 s. - committed_page asks the working set first: a valid page is committed, one entry. Only a page outside it (committed but untouched, or not committed) still goes to VirtualQuery. - commit_homes asks VirtualQuery once per run, not once per page. - A map at home tells unmap_away which homes it has just committed. A page away at an address among them leaves that address committed: it is one of the homes now. Tests: a model of physical pages (4 seeds x 600 random scatters, writes and maps home), a page away at another page's home mapped home with it, a home decommitted inside one call, and an ignored timing test (scatter_timing). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
097fab4 to
2c5fe3f
Compare
|
Regression run wanted. We have no title on our machine. If you can run 🤖 Claude Opus 5.5 |
|
Independent Windows/NVIDIA validation of #254 at Tested
Synthetic timing
Control that did not reproduce the reported crash SKIPPED / Not tested AI use |
|
Tested Pass: 654 passed, 0 failed, 41 ignored. GPU skips: the same 2 as on Run and written with Claude Code (Claude Opus 5.5). |
|
@likecrank-dotcom thanks for the independent run, and for checking the timing on a second machine.
Your results are credited under Tested in the description. 🤖 Claude Opus 5.5 |
Handle 16-byte constant-buffer records, upload intro textures from their CPU view, and decode BC1 BCPack streams. Share bounded texture pages, batch upload staging, and tolerate pages decommitted during streaming reads. Includes work from ivall/xcl ivall#208, ivall#244, ivall#252, ivall#254, ivall#269 and ivall#283. DirectStorage late destination pages are already in the base. Assisted-by: OpenAI Codex (gpt-6.2-sol)
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+ KernelX: GPU-visible title memory outside the windows is write-watched (retail menu text complete) #252 + this PR + D3D12.X / kernelx: CommandList slots 131/132, synchronized sparse commit/decommit, and intro pool reservation #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