Repository navigation
xmem: make page runs cheaper under Wine - #2911
JohnConnorNPC wants to merge 35 commits into
Conversation
The region query reports placeholders with Flags bit 0x100 on Windows. Wine leaves it 0, so alias_placeholders refused every split or coalesce and queue slot 31 batches failed with ERROR_INVALID_ADDRESS whenever a run was not exactly one placeholder. Probe once: if the bit is missing and VirtualFree with MEM_PRESERVE_PLACEHOLDER refuses a plain reservation and leaves it whole, offer any reserved region to the split. A plain one then fails the split instead of being released. Where the bit is reported nothing changes.
…get control xmem_placeholder_split maps two pool pages into the middle of an XMem reservation through X2WMapPageBatch and checks the bytes, a write through the destination and the reserved neighbours. A batch onto a committed page in the same reservation must fail and keep its bytes. xmem_placeholder_split_control disables the fallback and passes only when the split step fails; it skips where the OS reports the placeholder bit.
Add x2w_xmem_copy_to_destination. It checks that the whole destination capacity is committed and writable, and copies the data, both under memory.mutex. A run break (unmapping a page of a shared run and mapping its other pages again) also runs under that mutex, so it can neither make the check see a transient reservation nor start during the copy. Lazily mapped pages of both ranges are committed before the mutex is taken. A fault under the mutex is passed on: the lazy commit handler now skips mapping threads, as retry_remapped_page already did. The region walk moves from XCRDAPI's destination_writable to x2w_local::committed_writable, so both DLLs share one implementation.
A plain-memory destination is now checked and written by xmem.dll under
its mapping mutex when the export is there. Before, the VirtualQuery
pre-check could run while an XMem run break had the destination's page
unmapped for a moment, and refuse a destination that was mapped before
and after. Without xmem.dll the check and the copy run in XCRDAPI as
before.
A copy that faults on its source now fails the request ("copy faulted
(source not readable)") instead of raising in the stand-in.
startup_dstorage_break_window holds an unmap of page 5 of an 8-page run in the window where the run is apart (the xmem test-controls build's X2W_XMEM_TEST_HOLD_WINDOW), checks that page 2 reads MEM_RESERVE there, and submits a memory-source request into page 2. The request must not complete within the 1000 ms hold, then complete with S_OK with every byte in place after the release. It also covers a request with no break and a read-only destination refused on the xmem path. startup_dstorage_break_window_control builds XCRDAPI with the export lookup's name changed, so it judges the destination with its own VirtualQuery inside the window. It must report "refused while the run was broken".
A map into the middle of a larger placeholder always fails first, so every single-page XMemMapPhysicalPages call made two MapViewOfFile3 attempts. Under Wine each attempt is a server round trip whose cost grows with the view count. Split first when the target is not an exact placeholder; fall back to the map-first path if the split or the map fails. X2W_XMEM_TEST_MAP_FIRST=1 keeps the old order for tests. x2w_xmem_map_counts reports the attempts.
With X2W_XMEM_SHARED_VIEWS=1, unmapping a page inside a run unmaps the whole run and maps its other pages again. A touch of those pages in between is retried by the fault handler, but a region query or a kernel copy does not fault: it reads the pages as reserved, or fails. x2w_xmem_stable_call(fn, context) runs fn when no break begins or ends around it, else again under the mapping mutex. XMemVirtualQuery, and through x2w_local::outside_run_breaks the stand-ins' x2w_local::writable, measure_placed_buffer (slot 133) and snapshot_samplers, now answer that way. Without shared views no break begins, so fn runs once as before. xmem_run_break_readers holds a break open with the test-controls build and checks that each reader waits for it and then sees the page committed; its control build runs the stand-in readers directly and they answer inside the window.
The title queries its own pages through its VirtualQueryEx import. With X2W_XMEM_SHARED_VIEWS=1 xmem.dll now points that import at a wrapper that runs the query through x2w_xmem_stable_call, so a page of a run that is being taken apart is not reported as reserved. The module is pinned only when an import was changed (the pin is undone with the import if it is refused), so a main module without the import can still unload the shim before its first mapping call. xmem_run_break_readers checks the wrapped import of its own executable inside a held break.
retry_remapped_page names the break a fault belongs to as seen | 1. When the handler reads the generation after the break has ended (even), that names the next break, so a fault on the same page in that next break is not retried and the access violation ends the process. Name the break that just ended instead: (seen - 1) | 1. Back-to-back breaks over one page made this show up: with a reader on page 20 and page 21 toggled, the hold-ignored child of xmem_page_runs_check.py crashed in 6 of 6 runs once map calls also open a break, and passed 6 of 6 with this. Test build: X2W_XMEM_TEST_HOLD_RETRY=<name> holds the handler before it reads the break. xmem_run_break_readers gets a case that faults in break A, is held until A ends, and faults on the same page in break B. The xmem_run_break_readers_next_break_control test runs it without the hold.
…after a break Without X2W_XMEM_SHARED_VIEWS, every unmap still counts in the break generation (begin_break is not gated on the switch), so x2w_xmem_stable_call made default-mode readers wait for memory.mutex. Each page has a view of its own there, and no break takes a page away from a reader, so stable_call now runs fn directly until shared views are on. The comment, and the message of "xmem: answer non-faulting readers outside run breaks", saying no break begins without the switch were wrong. XMemVirtualQuery and the VirtualQueryEx import wrapper answered into the caller's buffer inside stable_call. On its mutex path the lazy-commit handler passes faults on, so a buffer in an uncommitted mapped slot was not committed there. Both now answer into a local copy and write it out after the call. A refused pin of the VirtualQueryEx wrapper is logged with its error and the restore count. measure_placed_buffer keeps the query count of a pass that ran again. The docs describe stable_call and the load-time read of the switch. "xmem: answer the main module's VirtualQueryEx outside run breaks" said the title queries its own pages through VirtualQueryEx. An import scan shows only that the executable under test imports it. How often it is called was not measured. Checks in xmem_run_break_readers: a break that begins while fn runs makes it run again under the mutex (pins the after-check); default mode answers inside an unmap (xmem_run_break_readers_default); lazy commit with the output in an uncommitted slot (xmem_run_break_readers_lazy); the reader's 300 ms now count from its start.
Start-up maps nearly every page with a call of its own (45595 of 45602 runs had one page), and under Wine each map costs more the more views the process has. With X2W_XMEM_SHARED_VIEWS=1, a mapping call whose pages form one run now joins the recorded run that ends at its address. It joins only when its first page is the next slot of the section behind that run's last page, and both lie in one reservation of the shim. The new pages' range is split to a placeholder of its own, the run is unmapped inside a break (begin_break, as for an unmap), the two placeholders are joined, and one view is mapped over both. A refused step before the unmap changes nothing. After it, the run is mapped again as it was (map_recorded) and the new pages get a view of their own. If the run cannot be restored, its pages are forgotten and the call fails, as in an unmap. Default mode is unchanged. Test build: X2W_XMEM_TEST_NO_MERGE=1 turns the merge off; X2W_XMEM_TEST_FAULT stages 4 (joined map) and 5 (joining the placeholders) refuse a step. xmem_cross_call_merge covers 32 single-page calls -> one view, an unmap in the middle, slots in reverse order (32 views), a reader held in the window, both refused steps, and two reservations. xmem_cross_call_merge_control keeps the old one-view-per-call layout under NO_MERGE. xmem_cross_call_merge_deployed shows the deployed shim ignores that switch. xmem_cross_call_merge_default covers default mode. xmem_page_runs_check.py expected "Mapping the page again does not join the pieces: three views". The page now joins the lower piece (two views). The three-view layout stays asserted by xmem_cross_call_merge_control. xmem_page_runs_device_check maps the upper view first and the single pages in reverse slot order, so its view boundaries stay.
An unmap inside a run takes the whole run apart and maps its other pages again, and a cross-call merge does the same to the run it joins. Nothing bounded the joined run, so after loading every title unmap inside a run of thousands of pages cost one long break: 46-72 ms each in a gate run under Wine, with readers waiting 63 s in all and presents at 2.4/s. merge_with_previous now leaves a page on its own when the joined run would be longer than max_merged_run_pages (64); the next pages join that one. The test build's X2W_XMEM_TEST_MERGE_CAP replaces the cap for a timing mode. Measured under Wine with every byte of the run written (xmem_cross_call_merge_check timing, median of 5): an unmap inside a run of 64 pages takes 0.28 ms, of 512 pages 2.1 ms, of 4096 pages 13 ms; joining a page to a run of 63 takes 1.5 ms, about what a page mapped on its own costs (1.4 ms). The fixture process has a few views, the title process tens of thousands. xmem_cross_call_merge gets a capped case: 192 single-page calls make three views of 64 pages, and an unmap held in its window in the middle one takes apart 64 pages while the outer two stay mapped. The control, deployed and default modes now print their pass line at the end of main, only with no failed check.
begin_break replaced the recorded ranges, so retry_remapped_page saw only the last break. A handler that ran after a later break on another run had begun found its address outside those ranges and passed the fault on. Joins made that the normal case: one permissive XMemMapPhysicalPages call joins the CPU run and then its GPU mirror run under one memory.mutex hold, and each map call opens a break of its own. RemapWindow now keeps the ranges of the last 64 breaks with their id (the odd generation). The handler names the newest break whose ranges hold the address, so a fault in a later break of the same page is still retried once more. xmem_run_break_readers_two_runs faults in break A on run 1 and holds the handler until break B on a disjoint run 2 is held open. xmem_run_break_readers_mirror does the same across the CPU join and the GPU mirror join of one call (X2W_XMEM_PERMISSIVE, X2W_XMEM_GPU_MIRROR). With one kept break both end the process with an access violation (exit 5). The RemapWindow and hold_window comments now also name the merge.
…e buffer Inside a run break a kernel copy into or out of a page of the run fails at once, with no fault to retry. Measured under Wine with the break held open (xmem_run_break_readers ReadFile_import/WriteFile_import, before this change): ReadFile fails with ERROR_NOACCESS and leaves the file position at 0, WriteFile fails with ERROR_INVALID_USER_BUFFER. With X2W_XMEM_SHARED_VIEWS=1 at load, the main module's ReadFile and WriteFile imports go through a wrapper. A synchronous call that fails with one of those errors while a break was in progress, or began or ended around it, and whose buffer lies in a run, waits for memory.mutex and runs again, at most 4 times in all. Other failures return at once as before: a read into a reserved page in no run fails at once (io_outside_runs). With lazy commit the ReadFile wrapper calls read_file_committed inside (lazy_read_file). Overlapped I/O, a call that a break cuts short after part of the copy, and I/O from other modules stay uncovered.
…lines at the end XMemVirtualQuery copied all 64 bytes of the caller's buffer before the query and wrote all 64 back after it. era_query writes 49 (the MBI and the tail byte at 0x30), so bytes 49-63 were read and rewritten where they never were before, and a buffer of 49-63 bytes that ends at a page end could fault. The caller's buffer is no longer read; on success tail_offset + 1 bytes go back, on failure none. xmem_run_break_readers_default prints its pass line at the end of main, only with no failed check, so a crash after the cases does not read as a pass. xmem_page_runs_device_check prints a check_failed line before the map-order returns, which were silent and looked like a refused device.
…g's edge The cap of 64 pages (max_merged_run_pages) is checked only where a page joins the run before it (merge_with_previous). A run mapped by one call (map_run in map_pages_locked) is not capped, and neither are the survivors map_recorded maps again after an unmap inside such a run. Both are as long as before the cap; a single large call is the title's own choice and was not the regression. The comment above the cap and docs/startup-runtime.md said the cap bounds every later break of a run; they now say it bounds the runs that joining builds, and name the two uncapped paths. xmem_run_break_readers_ring_edge holds a fault in break A before its handler reads the breaks, ends A, then makes 63 or 64 later breaks (map and unmap a lone page). After 63, A is still recorded and the fault is retried; after 64, A's slot (RemapWindow::kept) holds the newest break and the fault is passed on, which the reader's own __except catches.
|
Tested on Windows 11 (D3D12 hardware backend) with the switches from "How to test", plus
All three builds also carried local diagnostics and input automation that are not part of this PR. This comment was AI-assisted. |
|
Review of the head Two existing tests fail on this head and pass on Windows test runWindows 11 build 26300.9974, x64. MSVC 19.44.35230, cmake --preset dev
cmake --build --preset dev --target xmem_shim xmem_shim_test_controls startup_stub_xcrdapi startup_stub_xcrdapi_break_window_control xmem_run_break_readers_check xmem_run_break_readers_control xmem_cross_call_merge_check xmem_placeholder_split_check xmem_map_split_first_check startup_dstorage_break_window_check startup_dstorage_destination_check startup_dstorage_file_read_check xmem_page_runs_device_check linear_buffer_backing_check
ctest --preset dev --no-tests=error -R '^xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first|page_runs)|^xmem_shim_(page_runs|mapped_pages)$|^startup_dstorage_|^linear_buffer_backing_' -E '_hardware$' -V
ctest --preset dev --no-tests=error -R '^(xmem_page_runs_device|linear_buffer_backing_.*)_hardware$' -VThe build had no errors or warnings. The first
Pull-request CI covers almost none of this. On a pull request the Windows job builds and runs the The two failures
A page gets its section slot when it is first mapped (
At The Review points
Smaller things
Measured here: the test results above, on one machine and one GPU. Not measured: points 2 and 4, which come from reading the code, and any start-up run in this pass. Edited once, to add the AI-assisted (Claude Code). |
Same change as f602024 in R0Y00#2918.
|
@pigalot Thanks for the Windows runs of Noted from your table (Windows 11, D3D12 hardware backend):
Whether joins should stay on under This comment was AI-assisted. |
|
@Not-Saii Thanks for the review and for the Windows test run of Both failures are valid at
Fixture changes:
I checked your four review points and the smaller ones against the code at This comment was AI-assisted. |
Same change as 27778f4 in R0Y00#2918.
#2931) This reverts commit ee76dfa. Those are the 17 XMem commits of #2911, which is still under review against main, plus two fixture changes. Keeping them off cpp-migration keeps the branch to the native compiler work. When #2911 lands on main, merging main into cpp-migration brings in the reviewed version. Every file #2918 touched is restored to its state at cd752a8. The later #2917 touches none of them. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…runs.cmake The three blocks this branch added to CMakeLists.txt move verbatim into a fragment (tests/cmake/README.md), so CMakeLists.txt is main's again. The fragment is included after every target and helper it names. The configured tests (names, commands, properties) and the compile and link commands of the moved targets are the same before and after. The break-window fixture's comment names the fragment for its negative control.
The R0Y00#1199 comment had ended up above x2w_xmem_map_counts. The cross-call merge fixture's comments now say what the timing mode prints instead of pointing at notes outside the repository. Comments only.
A mapping call joins the shared view that ends at its address only with X2W_XMEM_JOIN_CALLS=1, read once with X2W_XMEM_SHARED_VIEWS by the first mapping call; without shared views it does nothing. It is off by default, so the layout with shared views alone is main's again (one view per call). run.sh sets it beside X2W_XMEM_SHARED_VIEWS, where the joins were measured; run.ps1 -LazyMemory does not. With the switch off and no test changes, these fail under Wine and now set it: xmem_cross_call_merge, xmem_cross_call_merge_deployed and xmem_run_break_readers_mirror; xmem_shim_page_runs is main's check again (three views). Every mode of the branch's fixtures sets or clears the switch itself. New: xmem_cross_call_merge_no_join (deployed shim, shared views, no join switch: one view per call) and xmem_page_runs_device_join_warp (the view boundaries hold with joins on). startup_run_sh_check checks the export.
X2W_XMEM_TEST_MAP_FIRST and X2W_XMEM_TEST_NO_PLACEHOLDER_FALLBACK are read only under X2W_XMEM_TEST_CONTROLS; the deployed xmem.dll no longer contains either name and behaves as if both were unset. xmem_map_split_first_control and xmem_placeholder_split_control now run against xmem_shim_test_controls. New xmem_map_split_first_deployed and xmem_placeholder_split_deployed set the switch for the deployed shim and must give the default result (the placeholder one skips with 77 where the OS reports the placeholder bit, as its control does). Each mode of both check programs sets or clears its switch itself, so the CTest entries no longer pass it.
Where the region query does not report the placeholder bit (Wine), alias_placeholders accepted a view after one VirtualQuery at the start of each allocation and then skipped to the allocation's end. It now walks every VirtualQuery region the view covers and requires each to be reserved. New xmem_placeholder_split_partial (test-controls build, shared views): two pages of the XMem reservation become a private reservation whose second page is committed and tagged, and a batch maps a two-page view there. With the old walk under Wine (Proton Experimental) the batch succeeded: alias refusals 0, one placeholder release tried, and the committed page became a mapped view reading the pool page (0x53 instead of the 0x7a tag). With the new walk the view is refused (alias refusals 2, one release: the per-page retry maps the reserved page alone and the rollback unmaps it), the batch fails with 0x80070057 and the committed page keeps its tag. The new x2w_xmem_alias_counts export (@27) counts alias_placeholders refusals and placeholder releases on the X2WMapPageBatch path in the test-controls build; the deployed build returns FALSE. Where the OS reports the bit the case skips (77).
…eak history retry_remapped_page retried a fault only while the break that took the page apart was among the last 64 recorded. A handler that ran after 64 later breaks on other runs passed the fault on although the page was mapped again, which xmem_run_break_readers_ring_edge asserted. Each recorded view now keeps the id of the break inside which it was mapped (0 outside breaks): the survivors map_recorded maps again after an unmap, a joined run, and the views of a page batch. The handler reads that stamp under memory.mutex, after the break in progress, and retries once per page and stamp per thread, so the id never expires while the view lasts. The ring and its ranges are gone; the generation stays for x2w_xmem_stable_call and the ReadFile/WriteFile retry. Because the handler is registered first and now needs the mutex for the lookup, faults that cannot be the transient one skip it: with the generation even before and unchanged after a VirtualQuery of the page and no mapped view there, the fault is passed on at once (faults on lazily committed memory take this path). Any other fault waits for the mapping call, as the ring lookup's hits did. xmem_run_break_readers_ring_edge becomes xmem_run_break_readers_stamps: 63, 64 and 200 later breaks (under Wine 3, 4 and 10 ms), all retried; the 64th used to be passed on. New in the same mode: a page made no-access faults once on a run no break mapped (passed on at once) and twice after a break mapped it (one retry), counted by a first-chance handler.
The ReadFile/WriteFile wrappers ran a synchronous call again after a run break whenever it failed with ERROR_NOACCESS or ERROR_INVALID_USER_BUFFER into or out of a run. On a pipe, socket or console the failed call may already have consumed or sent data, so they now do that only when GetFileType reports FILE_TYPE_DISK, asked only on that failure path. New window case ReadFile_pipe in xmem_run_break_readers: an anonymous pipe with two 4096-byte messages queued, read into the unmapped page. Under Wine (Proton Experimental) the read fails there with ERROR_NOACCESS and leaves both messages queued. Before this change the wrapper waited for the break and ran the read again, which failed as well: under Wine a pipe read into a mapped page of a run fails with ERROR_INVALID_USER_BUFFER even outside a break (into a VirtualAlloc buffer it reads the first message). Now the read fails inside the window; the case also checks that its error is one the wrapper retries on a disk file, so answering at once is not vacuous.
…uches a run x2w_xmem_copy_to_destination held memory.mutex for every copy and judged the destination with the region walk alone, so with xmem.dll loaded the working-set check from R0Y00#2685 never ran and every copy waited for, and blocked, the mapping calls. With shared views on, a short hold of the mutex now looks up whether the destination or the source overlaps a recorded run. Only then do the check and the copy run under the mutex, as before. Otherwise, and always with shared views off (each page has a view of its own and no unmap takes a neighbour away), both run without it. Both paths check resident read-write pages first and fall back to the region walk, as XCRDAPI does without xmem.dll; resident_read_write moves from xcrdapi.cpp to src/startup_stubs/resident_pages.h, which both include. A run can appear over a range only through a mapping call on those addresses during the copy, which is the caller's race. New x2w_xmem_copy_counts (@24) counts copies made with and without the mutex in the test-controls build; the deployed build returns FALSE. New startup_dstorage_break_window_plain: a VirtualAlloc destination copies without the mutex (0 with, 1 without) and a destination in the run with it (1, 0); startup_dstorage_break_window_views_off: with shared views off a destination in an XMem page copies without it (0, 1). The break-window case and its control are unchanged.
A copy that x2w_xmem_copy_to_destination did not complete was logged as "copy faulted (source not readable)" for every error but ERROR_NOACCESS. XCRDAPI now names each: ERROR_NOACCESS "destination not writable", ERROR_INVALID_ADDRESS "copy faulted (part of the destination may be written)", ERROR_INVALID_PARAMETER "invalid copy request", any other "copy failed (error N)". The StorageFailure causes are unchanged. The export's comment says that ERROR_INVALID_ADDRESS also covers a destination page that stopped being writable during the copy. New startup_dstorage_break_window_outcomes: the test-controls build's X2W_XMEM_TEST_COPY_ERROR=<code> fails the copy with that code before anything is written; for 998, 487, 87 and 31 the request fails, its destination keeps its bytes and the logged line carries the text above (the check points the standard error handle at a temporary file).
…tures to the pr preset docs/experiments.md is main's again. Its xmem_placeholder_split paragraph moves unchanged to docs/experiments/xmem-page-runs.md, with short sections for the split-first, cross-call join, run-break and DirectStorage fixtures and the X2W_XMEM_JOIN_CALLS switch, each with what was measured under Wine and its ctest command. The README row keeps its -R line and links the note next to the command. The pr build preset also builds xmem_shim_test_controls, the two XCRDAPI builds and the fixtures' check programs, including xmem_page_runs_device_check and linear_buffer_backing_check. Its test include adds the xmem_run_break_readers, xmem_cross_call_merge, xmem_placeholder_split, xmem_map_split_first and startup_dstorage_break_window families, xmem_page_runs_device(_join)_warp and linear_buffer_backing_share_warp: 28 tests that the pr include did not match before, every add_test of tests/cmake/xmem_page_runs.cmake plus the two named outside it. startup_run_sh stays out: it skips on Windows, and the Linux Python job runs tests/startup_run_sh_check.py.
…for MEM_REPLACE_PLACEHOLDER allocations xmem_placeholder_split_partial now checks that the two pages start as one allocation, prints where each page's allocation starts after the batch, and asserts that the first page is still one reserved page whose allocation base is its own address. Under Wine (Proton Experimental) the batch's per-page retry releases the reserved first page and the rollback unmaps it again, which cuts that page out of the caller's allocation: the committed page's allocation starts at +0 pages before the batch and at +1 after it. The fallback cannot tell a reserved page of a private allocation made with VirtualAlloc2(MEM_REPLACE_PLACEHOLDER) from a placeholder, because Wine does not refuse the release for that kind of allocation. The comment above alias_placeholders said the OS refuses the release for a plain reservation. That holds for VirtualAlloc and not for this kind, so it now names both and the limit, and so does the note in docs/experiments/xmem-page-runs.md.
… is measured docs/startup-runtime.md gave "the failed call may already have consumed or sent data" as the reason a pipe, socket or console call is not run again, followed by a Wine measurement that shows the data was left queued. It now states the Wine result on its own and says that whether Windows consumes or sends data in such a failed call is unmeasured. The comment above the ReadFile/WriteFile wrappers gets the same sentence.
…by its stamp lookup The header of tests/xmem_run_break_readers_check.cpp and the comments in next_break_case, two_runs_case and mirror still said the handler "reads the generation" or "the breaks", the wording from when it looked breaks up in a history of recent ones. They now say what it does: it finds the page mapped again and looks up the stamp the break left on the run. The next-break-control line printed by the fixture and one comment in tests/cmake/xmem_page_runs.cmake follow. Comments and one log line only.
…xture's usage comment The Usage comment at the top of tests/xmem_cross_call_merge_check.cpp lacked the no-join mode that the header describes and the usage line printed by main lists. Comment only.
…row's first link The README row for queue slot 31 carried the link to docs/experiments/xmem-page-runs.md after the ctest command in its second column. It now sits next to the experiments.md link in the first column. Layout only.
|
The branch is now at @MasterDomino Thanks for the lazy-off runs on #2918 (comment 7204145940), and for labelling the token null difference as a hint.
Windows fixture run: could a reviewer with Windows run these on cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^(xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first|page_runs_device|shim_page_runs)|startup_dstorage_break_window|linear_buffer_backing_share)' -V
Measured here, on Linux under Proton Experimental (wine-11.0) with a clang-cl cross build at
Not measured: a Windows run of this head outside CI's This comment was AI-assisted. |
R0Y00
left a comment
There was a problem hiding this comment.
Independent Windows integration run at 104617d6 with current main c09145a7 (8c7bdd99 locally). Both Debug and Release /O2 built the listed fixtures. ctest --preset <dev|release> --no-tests=error -V -R '^(xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first|page_runs_device|shim_page_runs)|startup_dstorage_break_window|linear_buffer_backing_share)' gave 28 passes and zero failures in each preset. The three Wine-oriented placeholder controls (control, deployed, partial) skipped with 77 because Windows reports the placeholder bit.
The DirectStorage break fixture waited and copied all bytes, and the negative control reported a refusal during the break. The prior review's page-runs and linear-buffer-sharing fixtures passed on both WARP and RTX 4060 Laptop, including the WARP join variant. Windows 11 build 26200.9974, WARP driver 10.0.26100.9818 and RTX driver 32.0.16.1656, debug layer off for these D3D12 cases. Hosted Windows and Linux checks are green.
This run covers the Windows fixture matrix. The PR's original-executable and Wine evidence is from earlier heads. Can the Wine tester repeat a current-head run with the default run.sh joining behavior and add the matching control run with X2W_XMEM_JOIN_CALLS=0? The final-head startup performance and the Wine-only placeholder branches are the remaining evidence gaps from this run.
|
Thanks for the independent Windows run and for the adapter and driver details. Fixture-level Wine evidence at These are fixture results only. They are not a start-up run and say nothing about start-up performance at this head. Once the Wine test machine is free, I'll repeat the start-up run at the current head with This comment was AI-assisted. |
|
Correction: the branch runs' "first archive" times in the Evidence table (69.8, 71.5, 79.3 and 53.3 s) came after what appears to have been hand controller input in the menus: button reads before the script's A, direction-pad presses, and a controller visible to the executable. The body did not say this, so those times are not start-up timings and are not comparable between rows. I've edited the body to say so. New measurement at This comment was AI-assisted. |
|
Start-up runs under Wine for the joining switch, as asked in the last review. Two parts are measured. The current head is not yet. Measured:
Not measured yet: the current head. Found along the way, outside this PR: on Linux, This comment was AI-assisted. |
How to test
Fixtures, on Windows with the
devpreset:xmem_page_runs_device_hardwareandlinear_buffer_backing_share_hardwareneed a physical GPU. The three
_warptests need WARP.xmem_placeholder_split_control,_deployedand_partialskip (77) where the OS reports the placeholder bit.prpreset now builds these programs and runs 28 of these tests that it did not run before: the five fixturefamilies and the three
_warptests. The_hardwaretests stay out of it.Start-up run:
cmake --preset devandcmake --build --preset dev. On Linux, use the clang-cl cross build indocs/non-windows-hosts.md.tools/startup/run.ps1 <usual exe/data/log arguments> -Seconds 0 -MemoryGiB 40 -FakeUser -Render -Translate -GpuMirror -HostCpu -StartupBelow40 -LazyMemory.-LazyMemorysetsX2W_XMEM_LAZY_COMMIT,X2W_XMEM_LAZY_STARTUPandX2W_XMEM_SHARED_VIEWS. It does not setX2W_XMEM_JOIN_CALLS, so joins across mapping calls stay off unless you set it yourself.tools/startup/run.sh ... --seconds 0 --memory-gib 40 --fake-user --render --translate --gpu-mirror --host-cpu --startup-below-40, withX2W_XMEM_LAZY_COMMIT=1 X2W_XMEM_LAZY_STARTUP=1in the environment.run.shsetsX2W_XMEM_SHARED_VIEWS=1andX2W_XMEM_JOIN_CALLS=1unless they are already set.X2W_DEVICE_TYPE=6 X2W_PRESENT_COMPOSITE=1 X2W_D3D12_RELEASE_RETIRED=1 X2W_D3D12_RELEASE_RETIRED_VIEWS=1 X2W_XAPU_TYPED_COMPLETIONS=1.X2W_D3D12_BUDGET=1and used an input script that answers the account prompt once. In thebranch runs in Evidence, the menus also appear to have been driven by hand with a controller (see Evidence).
x2w-d3d12 heartbeat: N frames presentedcount kept rising past about170 s. In our like-for-like runs, main stopped presenting at 15-16.5 s and hit the executable's start-up
watchdog at 52-56 s.
undetermined cause.
4a43a173with the lazy and shared-views switches on ended in a write accessviolation in the executable, with and without this PR (Evidence). With the switches off, the run with this PR
reached the 900 s cap.
XMem pages are mapped from 64 KiB sections. With
X2W_XMEM_SHARED_VIEWS=1, pages that are adjacent in theaddress space and adjacent slots of one section share one view, called a run. Unmapping one page of a run takes
the run apart and maps its other pages again (a run break). A console executable under test maps nearly every
page with its own call: 45595 of 45602 recorded runs had one page. Under Wine each
MapViewOfFile3is a serverround trip. In one run its cost rose from 0.04 ms to 0.92 ms per call as the view count grew, so start-up spent
most of its time mapping.
This PR has one aim: XMem page runs under Wine are cheaper to build, and code that reads those pages sees them
committed while a run changes. Groups 1 to 3 are the first 17 commits, in commit order. The 17 review commits after
them are listed under "Review changes". Each group below describes the final head and names the review commit that
changed it.
Switches on the final head:
X2W_XMEM_SHARED_VIEWS=1) gate group 3's reader waits and its import wrappers.run.ps1 -LazyMemorysets it.
X2W_XMEM_JOIN_CALLS=1.run.shsets it andrun.ps1does not.Group 1: slot 31 placeholder splits under Wine (3 commits)
xmem: split slot 31 placeholders when the OS hides the placeholder bit.0x100region flag. As a result, every queue slot 31 split orcoalesce whose run was not exactly one placeholder failed with
ERROR_INVALID_ADDRESS.1615efc5), and its known limit is in Known limits(
f9391cca).xmem_placeholder_split.xmem_placeholder_split_control, turns the fallback off in the test-controls build and passesonly when the split step fails.
_deployedsets the same switch for the deployed DLL, which ignores it(
cb8cc808)._partialwas added in1615efc5. All three skip (77) where the OS reports the bit.docs/experiments/xmem-page-runs.mdand the README row (0cfdd607).Group 2: DirectStorage copies through xmem.dll (3 commits)
xmem: copy DirectStorage destinations under the mapping mutexandstartup: copy DirectStorage data through x2w_xmem_copy_to_destination.VirtualQuerypre-check could run while a break had the destination page unmapped for a moment.It then refused a destination that was mapped both before and after.
f19890e4, they run undermemory.mutexonly when sharedviews are on and the destination or the source overlaps a recorded run. Otherwise, and always with shared views
off, they run without the mutex.
to the region walk.
302618bd, XCRDAPI logs the outcome by error code.startup_dstorage_break_window.MEM_RESERVEinside it. The requestmust wait for the hold, then complete with every byte in place.
startup_dstorage_break_window_control, builds XCRDAPI without the export lookup and mustreport "refused while the run was broken".
_plain,_views_off(f19890e4) and_outcomes(302618bd) are described under Review changes.Group 3: page runs (11 commits)
Fewer map calls:
xmem: split an owned placeholder before mapping a page into it.single-page call makes one
MapViewOfFile3attempt instead of two. If the split or the map fails, the oldorder runs.
xmem_map_split_first: 8 maps for 8 pages. Its control,xmem_map_split_first_control(
X2W_XMEM_TEST_MAP_FIRST=1, test-controls build sincecb8cc808), measures 2 maps per page.Readers outside run breaks. A touch of a page inside a break faults, and the fault handler retries it. A region
query or a kernel copy does not fault: it sees the page as reserved, or fails.
xmem: answer non-faulting readers outside run breaks.x2w_xmem_stable_call(fn, context). It runsfnonce when no break begins or ends around it,and otherwise runs it again under the mapping mutex.
XMemVirtualQuery, and in the stand-insx2w_local::writable,slot 133
measure_placed_bufferandsnapshot_samplers.xmem: answer the main module's VirtualQueryEx outside run breaks.VirtualQueryEximport goes through a wrapper that usesstable_call.xmem: run readers once without shared views, and write their answers after a break.stable_callcallsfndirectly.may be in a lazily committed page.
xmem: write back only what XMemVirtualQuery's query writes, and pass lines at the end: the write-back coversthe bytes the query writes and no more.
xmem: run title ReadFile/WriteFile again after a run break refused the buffer.ReadFileandWriteFileimports are wrapped.ERROR_NOACCESSorERROR_INVALID_USER_BUFFER, a break overlapped it, its buffer lies in a run and, since4f7d47de, thehandle is a disk file.
ReadFileinto the run failed with 998 and left the position as it was, andWriteFilefrom it failed with 1784. After it, the read gets all 4096 bytes.Fault retries across breaks:
xmem: retry a fault in the break after the one the handler saw endfixed a pre-existing bug. A handler thatread the break generation after the break ended named the next break instead. A fault on the same page in that
next break was then not retried. The hold-ignored child of
xmem_page_runs_check.pycrashed in 6 of 6 runsbefore the fix and passed 6 of 6 after it.
xmem: retry a fault from any of the last 64 breaks, not only the lastadded a 64-break history.c8391709replaces both mechanisms. Each run now keeps the id of the break inside which it was mapped, andthe handler retries a fault on such a page once per break and thread, however many breaks follow on other runs.
Joins:
xmem: join a page mapped on its own call to the view before it. Sinced4f1344ethis needsX2W_XMEM_JOIN_CALLS=1as well as shared views.reservation.
restored.
xmem: stop a joined run at 64 pages.xmem: say the run cap bounds joined runs only, and test the break ring's edge.together, can still be longer, as before this PR.
xmem_run_break_readers_stampsinc8391709.Tests and changed expectations:
xmem_run_break_readers, with_control,_next_break_control,_default,_lazy,_two_runs,_mirrorand
_stamps.page committed. The readers cover
ReadFileandWriteFiletoo. A pipeReadFilemust fail inside thewindow without being run again.
xmem_cross_call_merge, with_control(one view per call underX2W_XMEM_TEST_NO_MERGE=1),_deployed(the deployed shim ignores that switch),
_default(no shared views) and_no_join(shared views without thejoin switch: one view per call). Its
cappedcase covers the 64-page cap.xmem_page_runs_check.pyis main's again (three views), because joins are off by default.xmem_page_runs_device_check.ad1980cb(runtime: bring XMem page-run fixes into cpp-migration #2918'sf6020249, same patch-id) maps the single pages from highto low addresses.
d4f1344emaps the upper 8-page call first. No call then has a view that ends at itsaddress, so with the join switch every call still keeps its own view. New
xmem_page_runs_device_join_warpruns it with
X2W_XMEM_JOIN_CALLS=1. The earlier description said this test's view boundaries were the sameas before. That was wrong at
4a43a173, as @Not-Saii's Windows run showed.linear_buffer_backing_check.238ed78a(runtime: bring XMem page-run fixes into cpp-migration #2918's27778f4f, same patch-id) maps the upper page of thesplitbuffer first. The fixture also clears the join switch.Review changes (17 commits)
These answer @Not-Saii's review of
4a43a173and our own audit, in commit order:ad1980cb,238ed78a: the two fixture fixes above.14a9589f: the page-run test registrations move verbatim totests/cmake/xmem_page_runs.cmake.CMakeLists.txtis main's again.e9e0b441: the slab accounting comment is back abovex2w_xmem_slab_stats, and the fixture comments no longerpoint at notes outside the repository.
d4f1344e: joins across mapping calls needX2W_XMEM_JOIN_CALLS=1(review point 3).xmem_cross_call_merge_no_joinandxmem_page_runs_device_join_warp.cb8cc808:X2W_XMEM_TEST_MAP_FIRSTandX2W_XMEM_TEST_NO_PLACEHOLDER_FALLBACKare read only in thetest-controls build. The deployed xmem.dll contains neither name. New
_deployedrows.1615efc5: the placeholder fallback checks every region a view covers, not only the first of each allocation(review point 4).
xmem_placeholder_split_partial.0x53instead of the
0x7atag). With the new walk it is refused and the page keeps its tag.c8391709: each run carries the break that mapped it, which replaces the 64-break history (review point 2).xmem_run_break_readers_stamps: a fault held through 63, 64 and 200 later breaks is retried each time (underWine the later breaks took 3, 4 and 10 ms).
4f7d47de: theReadFile/WriteFileretry applies to disk files only.ReadFile_pipe. Under Wine the pipe read fails withERROR_NOACCESSand both messages stayqueued.
f19890e4: a DirectStorage copy takes the mapping mutex only when it touches a run, and checks resident pagesfirst (review point 1).
x2w_xmem_copy_countsexport, test-controls build only.startup_dstorage_break_window_plain: aVirtualAllocdestination copies without the mutex, and a rundestination copies with it.
startup_dstorage_break_window_views_off: with shared views off, an XMem page destination copies withoutthe mutex.
302618bd: XCRDAPI logs each copy outcome by its error code: "destination not writable", "copy faulted (part ofthe destination may be written)", "invalid copy request", or "copy failed (error N)".
startup_dstorage_break_window_outcomes, which uses the test-controls build'sX2W_XMEM_TEST_COPY_ERROR.0cfdd607: the note moves todocs/experiments/xmem-page-runs.md, anddocs/experiments.mdis main's again.prpreset builds the fixture programs and runs 28 of these tests that it did not run before.startup_run_shstays out of it: it skips on Windows, and the Linux Python job runs its check.f9391cca: states the placeholder fallback's limit (Known limits).f4cc2900: says which half of the pipe retry reason is measured.863c0459,bf9e448f: comments only.0c6be971: README link layout.Switches
stable_callwaits, theVirtualQueryEx/ReadFile/WriteFilewrappersX2W_XMEM_SHARED_VIEWS=1(run.ps1 -LazyMemoryandrun.shset it)X2W_XMEM_SHARED_VIEWS=1andX2W_XMEM_JOIN_CALLS=1(run.shsets it,run.ps1does not)X2W_XMEM_TEST_*(MAP_FIRST, NO_MERGE, MERGE_CAP, HOLD_WINDOW, HOLD_RETRY, FAULT, NO_PLACEHOLDER_FALLBACK, COPY_ERROR)X2W_XMEM_TEST_string.Test
Host: Linux, cross-built with clang-cl 19 and xwin. Tests ran under Proton Experimental (wine-11.0) with a runner
that applies each test's ctest properties.
python-linuxcommand)WILL_FAILsays. Therewere 0 such tests.
d3d12.dllstart.4a43a173run, 79 rows changed:3 of them (
unified_buffer_paths_*_control) as passes.compute_heap_view_controlsfailed there with a Wine client error. It was the earlier description's flake.startup_storage_directory_batchfailed there with anAssertionError, which was not investigated.startup_local_log_reopen_control(below).xmem_page_runs_device_join_warpis new and fails: there is no WARP here._ring_edgebecame_stamps.xmem_startup_below_40_mutant_no_limittimed out (60 s) in the full run and passes alone.xmem_lazy_commit_offis unmeasured under Wine. Its commit-charge reading moves with host load, and italready failed at
238ed78a, before any review commit. Its earlier passes are not results.startup_local_log_reopen_controlpassed once in the full run. It fails alone and in every other run (base,4a43a173, the review head), so the pass is not a change.ninja -k 0ends with the same 419 failed targets on base and on this head: the MASM fixtures andthe generator-driven targets, which the cross toolchain cannot build. Those tests did not run here.
_no_join,xmem_shim_page_runs);xmem_cross_call_merge), and therun.shcheck's "no join calls" mutant;_deployed);_partial);MEM_PRESERVE_PLACEHOLDER(_partial);later_breaks_64/_200);persistent_fault);xmem_run_break_readers,_stamps);ReadFile_pipe);_plain,_views_off), and run lookup without the shared-viewsgate (
_views_off);_outcomes).4a43a173:stable_callnever retries;ReadFile/WriteFilewrapper returns 0, or retries with no bound.They were not run again on the final head. The ring mutations no longer apply, because the ring is gone.
AllocationBase/RegionSizeclauses ofxmem_placeholder_split_partial. The unmap mutation failsthat check, but it also changes the page state. No mutation was found that changes only the base or the size.
c8391709pre-check, which is a performance change only.ReadFileandVirtualQueryExwrappers. Wine writes into an uncommitted mapped slotwithout faulting, so their mutations do not fail here. They are unmeasured on Windows as well.
Windows CI on this head:
Build and test on Windowsjob ran theprpreset on0c6be971(run 45921712354, imagewindows-2025-vs2026). It ran 68 tests, and all of them passed.xmem_placeholder_split_control,_deployedand_partial, because Windows reports the placeholder bit.xmem_page_runs_device_warp,xmem_page_runs_device_join_warpandlinear_buffer_backing_share_warp._hardwarevariants have no result on this head. runtime: bring XMem page-run fixes into cpp-migration #2918 reportedf6020249passing on WARP and on a GTX 1080 Ti.Evidence from a running title
Local runs of a console executable under test on Linux under Wine/Proton. These runs are of the branch up to its
third round commit (
ReadFile/WriteFile), not of the final head. Each run had no timeout, and each configurationwas run once unless a count is given. Switches: 40 GiB, render, host CPU rewrites, GPU mirror, a fake user,
start-up blocks below 2^40, lazy commit and
X2W_XMEM_SHARED_VIEWS=1. Joins were on, because that branch had nojoin switch.
Like for like: the same launcher, environment and arguments, with only the build different. Main already
honours all three memory switches, but its shared views are the basic version.
ReadFile/WriteFileretry turned off15 s, and no frame follows in the 37-40 s before the watchdog fires.
presenting until 168-243 s before it fires. What the watchdog waits for in the branch runs is not determined.
The branch runs' menus appear to have been driven by hand as well: each run read an A 12-21 s before the script's,
the runs without the menu-skipping change read 4-6 direction-pad presses before loading began, and a controller is
visible to the executable. So the archive times likely show when someone picked a menu item, not how fast start-up
ran, and they are not comparable between rows. Main never reached a point that reads input.
and skips the menus:
watchdog fired at 52.2 s.
file during the run. It behaved like the other branch run, and main had the same environment, storage and
driver state. So neither the shader cache nor that shared state separates the two builds.
dialog after the menu.
older main did not show them. This PR changes no D3D12 code. Hypothesis, not tested: they come from main.
Other controls:
start-up hang (1064 s and 408 s), with 54545 and 54549 joins and 0 lost.
Windows runs by reviewers. These are the first Windows measurements of this work, and all of them are of earlier
heads:
4a43a173.devpreset (Debug). WARP and an RTX 4090 (driver 32.0.16.1088), withthe debug layer off.
_hardwaretests: 7 passed and 2 failed.xmem_page_runs_deviceandlinear_buffer_backing_share, in both variants. All of them passat
6ee878d8.ad1980cband238ed78aaddress them._warpvariants pass in CI (Test). The_hardwarevariants have not been run.4a43a173, Windows 11 with the D3D12 hardware backend, 900 s cap.(4706 frames). Main without this PR, same switches: the same kind of fault at 250.0 s (5410 frames), at a
different address.
release, debug layer off. Builds: runtime: bring XMem page-run fixes into cpp-migration #2918's head27778f4f, which carries the same change as this PR at238ed78a, againstcpp-migration40365770.noise.
f19890e4takes no mutex and no run lookup for a DirectStorage copy, which is the pathhe named. That has not been measured.
Measured vs not
prpreset run of the final head.prpreset, including the_hardwarevariants;xmem_lazy_commit_offpasses on this head under Wine. Host noise decides it here;f19890e4changes the token null count in lazy-off runs;VirtualQueryEx(it imports it, but the calls were not counted);VirtualAlloc2(MEM_REPLACE_PLACEHOLDER)from a placeholder, because Wine does not refuse the release for that kind of allocation.
allocation: the committed page's allocation then started one page later.
ReadFile/WriteFileretry.files are retried.
ReadFileandWriteFileimports are wrapped. Not wrapped:ReadFileEx/WriteFileEx,scatter/gather,
DeviceIoControl, sockets, I/O from other modules and I/O throughGetProcAddress.after each later break that maps the page again.
heuristic, and
MEM_PRIVATEheap paths.