xmem: make page runs cheaper under Wine #2911
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2911"
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 R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-26T19:23:45Z.
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(#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(#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.
6ee878d84a43a1730c6be971python-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. #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.
6ee878d8ReadFile/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:
6ee878d8without shared views: no frame was presented, and start-up stopped on the same watchdog.52905a32): hang at about 47 s in 2 of 2 runs.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: #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.Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-26T20:22:24Z.
Tested on Windows 11 (D3D12 hardware backend) with the switches from "How to test", plus
X2W_D3D12_BUDGET=1and fresh storage for each run. Each run was capped at 900 s. In all three runs the executable got past the account prompt the same way.X2W_XMEM_LAZY_COMMIT/LAZY_STARTUP/SHARED_VIEWS6ee878d8+ this PR (4a43a173)6ee878d8+ this PR (4a43a173)6ee878d8, without this PRdestination capacity exceeded. The newcopy faulted (source not readable)message never appeared.All three builds also carried local diagnostics and input automation that are not part of this PR.
This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T20:29:32Z.
Review of the head
4a43a173, with a Windows run of the tests this PR adds or touches.Two existing tests fail on this head and pass on
mainon the same machine, in their WARP and their hardware variants, both because single-page calls now join. Every new test passes on Windows. After the test report there are four review points and some smaller ones.Windows test run
Windows 11 build 26300.9974, x64. MSVC 19.44.35230,
devpreset (a Debug build). The WARP tests ran on Microsoft Basic Render Driver 10.0.26100.9818 with the D3D12 debug layer off. The_hardwaretests ran on an NVIDIA GeForce RTX 4090 (10de:2684), driver 32.0.16.1088, also with the debug layer off. Head4a43a173, controlmain6ee878d8, both built in the same build directory.The build had no errors or warnings. The first
ctestline selects 46 tests: 43 passed, 2 failed and 1 skipped (77). The second selects the 9_hardwarevariants: 7 passed, 2 failed and none skipped.xmem_page_runs_device_warp,linear_buffer_backing_share_warp, and the_hardwarevariant of each. All four pass at6ee878d8: the two WARP tests with-R '^(xmem_page_runs_device_warp|linear_buffer_backing_share_warp)$'(2 of 2), and the whole secondctestline (9 of 9).xmem_placeholder_split_control, as expected, because Windows reports the placeholder bit.xmem_run_break_readers*tests, the fourxmem_cross_call_merge*tests,xmem_placeholder_split,xmem_map_split_firstand its control,startup_dstorage_break_windowand its control,startup_dstorage_destination, the twostartup_dstorage_file_read*tests,xmem_shim_page_runs,xmem_shim_mapped_pages, and the other 21linear_buffer_backing_*tests of the first line. On hardware, the other sevenlinear_buffer_backing_*_hardwaretests.Pull-request CI covers almost none of this. On a pull request the Windows job builds and runs the
prpreset only. That preset buildsxmem_shimbut none of the new test programs, and of the tests above its filter matches onlyxmem_shim_mapped_pages. So where the description says Windows CI is the first real check, that check only happens onmainafter a merge.The two failures
xmem_page_runs_device_warp, which I also reported on #2905:A page gets its section slot when it is first mapped (
section_for, called frommap_pages_locked), not whenXMemAllocatePhysicalPagesreturns its token. Mappingsingle[7 - i]therefore still takes consecutive slots in call order, and each call joins the one before it. Thereversedcase oftests/xmem_cross_call_merge_check.cpphandles this by mapping all the pages through one view first. This test needs the same step.xmem_page_runs_device_hardwarefails with the same line.linear_buffer_backing_share_warp, in itssplitcase:At
6ee878d8the same row passes withshare 0x80070057.allocate_splitmapsalloc_pages - 1pages and then one more page with a second call, and expects a view boundary inside the buffer. The second call now joins the first, so sharing is no longer refused withE_INVALIDARG.linear_buffer_backing_share_hardwarefails on the same row with the same values. The description lists this family as not measured.The
pinrow of the same test changes too. It is measured, not asserted.OpenExistingHeapFromAddressat the address of a mapping call returns0x80070057on this head and0x00000000at6ee878d8. The likely reason is that the address is no longer the base of a view once the call has joined its neighbour, but I have not confirmed that.Review points
With xmem.dll loaded, a DirectStorage copy skips the check from #2685 and holds the mapping mutex during the region walk.
x2w_xmem_copy_to_destination(src/xmem_mapped_pages.cpp:1864) judges the destination withx2w_local::committed_writablealone, which is theVirtualQuerywalk. #2685 addedresident_read_write, aQueryWorkingSetExcheck, because that walk cost about 10 ms per request. It is now reached only without xmem.dll. The walk and the copy both run undermemory.mutex, so mapping calls, lazy-commit faults and break retries wait behind them. The start-up runs in my comment on #2905 fit this: one 16-byte copy held the mutex for 69.7 ms, and the longest holds (24.8 to 102.3 ms) belonged to copies of 16 bytes to 450 KiB. Could the resident check run first, and the mutex be taken only when the destination or the source overlaps a run?Is a history of 64 breaks enough now that a joining call is a break?
retry_remapped_pageretries a fault only while its break is still inRemapWindow::recent. Before this PR breaks were rare. Now every single-page call that joins is one, or two with a GPU mirror, so the history spans 32 to 64 map calls. Take a thread that faults during the join that fills a run. If its handler only runs after 64 later joins on the next run, the access violation is passed on although the page is mapped.xmem_run_break_readers_ring_edgeasserts that outcome. With lazy commit on,lazy_commit_faultretries once per page and hides the first miss. With shared views alone, nothing does. I have not reproduced this. Stamping each run with the generation that last remapped it, and comparing that undermemory.mutex, would give a test that does not expire.Joins are active on native Windows too, because
run.ps1 -LazyMemorysetsX2W_XMEM_SHARED_VIEWS. Every single-page call that continues a run now unmaps and remaps up to 63 live pages. The description's own timing puts a join at the cap at about the cost of a separate map under Wine (1.515 ms against 1.392 ms), so the gain there comes from having fewer views. Nothing measures a gain on Windows, and the two failures above show that the layout change reaches code outside xmem. The Windows start-up runs so far, the one reported above by pigalot and mine on #2905, got as far asmaindid with the switches on. So I see no breakage from the joins on Windows, and no measured benefit either. Would a separate switch for joins make sense, so that-LazyMemoryon Windows keeps the layout it had?Under Wine, the placeholder fallback checks one page per allocation. I read this from the code and did not reproduce it. In
alias_placeholders(src/xmem_mapped_pages.cpp:1365) the fallback accepts an allocation when the page ataddressreadsMEM_RESERVE, then skips the whole allocation. The probe shows that the OS refuses a reservation that was never a placeholder. A block that replaced a placeholder is a different case, sinceVirtualFree(MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)is the documented way to free one back to a placeholder. Suppose the title commits a block at an address inside an XMem reservation and later decommits part of it. Is a slot 31 batch that names that part refused under Wine? On Windows the bit check refuses it.Smaller things
X2W_XMEM_TEST_MAP_FIRST(src/xmem_mapped_pages.cpp:395) andX2W_XMEM_TEST_NO_PLACEHOLDER_FALLBACK(line 1332) are read by the deployed xmem.dll, and their controls run againstxmem_shim. The Switches table lists both as test-controls build only.X2W_XMEM_TEST_NO_MERGEis guarded and has a_deployedtest.ReadFile/WriteFileretry does not look at the handle type. On a pipe or an append handle the failed call may already have consumed or written bytes. Limiting the retry toFILE_TYPE_DISKwould keep it to the case that was measured.src/startup_stubs/xcrdapi.cpp:954logs every error exceptERROR_NOACCESSas "copy faulted (source not readable)". That includesERROR_INVALID_PARAMETERand a fault on the destination.x2w_xmem_map_countswas inserted between the slab-accounting comment andx2w_xmem_slab_stats, so that comment now sits on the wrong export (src/xmem_mapped_pages.cpp:1767).tests/xmem_cross_call_merge_check.cpprefers to "ready.md's table" (line 329) and "the review notes" (line 13). Neither is in the repository.CMakeLists.txt, wheretests/cmake/README.mdasks for atests/cmake/<family>.cmakefragment. Thexmem_placeholder_splitnote went intodocs/experiments.md, where AGENTS.md says new notes go indocs/experiments/<topic>.md. AGENTS.md also asks for one reviewable behavior per pull request, and the description names three groups. The slot 31 fallback and the fault-retry fix look independent of the joins and could land on their own.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
_hardwarevariants.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-26T21:13:36Z.
@pigalot Thanks for the Windows runs of
4a43a173.Noted from your table (Windows 11, D3D12 hardware backend):
mainwith the switches on gets well past the point where it stops under Wine (52-56 s in our runs), and these runs show no gain from this PR there.destination capacity exceededfailure per run, and nocopy faulted (source not readable)line.Whether joins should stay on under
-LazyMemoryon Windows is being considered together with the review points below.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-26T21:13:37Z.
@Not-Saii Thanks for the review and for the Windows test run of
4a43a173.Both failures are valid at
4a43a173, and the description was wrong about the device test:xmem_page_runs_device: a page gets its section slot at its first map (section_for, called frommap_pages_locked). The single-page calls therefore take consecutive slots in call order, and each call joins the view before it. The description said this test's view boundaries were the same as before. That came from reading the code, not from a run, and it was wrong. So was the test's comment about reverse slot order.linear_buffer_backing_share: the second call inallocate_splittakes the next slot at the next address, so underX2W_XMEM_SHARED_VIEWS=1it joins the first call, and sharing is no longer refused withE_INVALIDARG.d3d12.dllcould not start in our test prefix, and all four of these exited 53 there, onmainand on this head alike. Our suite therefore counted them among the failures both sides share.Fixture changes:
xmem_page_runs_device:ad1980cbtakes #2918's changef6020249as it is (same patch-id): it maps the single pages from high to low addresses, so no call has a view ending at its address. It has not been run here. #2918 reports it passing on WARP and on a GTX 1080 Ti.linear_buffer_backing_share,splitrow: a fix along the lines of #2918's27778f4f(map the upper page first) is being considered together with the review points. The cause of thepinrow change is not confirmed yet.I checked your four review points and the smaller ones against the code at
4a43a173, and each matches it as you describe. I have not reproduced points 2 and 4. How to address them is being considered: the DirectStorage copy path, the break history, a separate switch for joins, the placeholder fallback, the CI coverage, where the test registrations and notes live, and the scope of this PR.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T01:28:07Z.
The branch is now at
0c6be971, 34 commits onmain6ee878d8. The description lists each commit and what it changes. The 17 commits after4a43a173address @Not-Saii's review points 1 to 4 and the smaller ones (see "Review changes"), and they carry #2918'sf6020249and27778f4fasad1980cband238ed78a(same patch-ids).@MasterDomino Thanks for the lazy-off runs on #2918 (comment 7204145940), and for labelling the token null difference as a hint.
f19890e4. With shared views off, a DirectStorage copy through xmem.dll now takes no mapping mutex and no run lookup. It checks resident read-write pages first and then falls back to the region walk, as XCRDAPI does without xmem.dll (#2685). With shared views on, it takes the mutex only when the destination or the source overlaps a recorded run.startup_dstorage_break_window_views_off: with shared views off, an XMem page destination was copied 0 times with the mutex and once without it.startup_dstorage_break_window_plain: aVirtualAllocdestination was copied without the mutex, and a run destination with it.27778f4f, which held the mutex for every copy. If you can, a re-run of the same lazy-off pair on0c6be971would test your hypothesis: does the token null count follow that path? We cannot run it, because our host has no Windows.Windows fixture run: could a reviewer with Windows run these on
0c6be971?xmem_page_runs_device_hardwareandlinear_buffer_backing_share_hardwareneed a physical GPU._warptests need WARP.xmem_placeholder_split_control,_deployedand_partialshould skip (77) where the OS reports the placeholder bit.prCI preset now runs 28 of them, all but the_hardwaretwo andxmem_shim_page_runs.Build and test on Windowsjob ran theprpreset on0c6be971(run 45921712354, imagewindows-2025-vs2026). It ran 68 tests and all of them passed. Of the 28 above, 25 passed and 3 skipped (77):xmem_placeholder_split_control,_deployedand_partial.xmem_page_runs_device_warp,xmem_page_runs_device_join_warpandlinear_buffer_backing_share_warp.xmem_page_runs_deviceandlinear_buffer_backing_sharefailed at4a43a173.xmem_page_runs_device_hardware,linear_buffer_backing_share_hardwareandxmem_shim_page_runs, and every test on a physical GPU.Measured here, on Linux under Proton Experimental (wine-11.0) with a clang-cl cross build at
0c6be971:_warptests failed because there is no WARP here, and the two_hardwaretests skipped (77).xmem_lazy_commit_offis unmeasured under Wine, because host load decides it.Not measured: a Windows run of this head outside CI's
prpreset, and any start-up run of this head. Nothing here claims that a title runs.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T07:04:22Z.
Review: COMMENTED
Independent Windows integration run at
104617d6with currentmainc09145a7(8c7bdd99locally). Both Debug and Release/O2built 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.shjoining behavior and add the matching control run withX2W_XMEM_JOIN_CALLS=0? The final-head startup performance and the Wine-only placeholder branches are the remaining evidence gaps from this run.Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T07:14:06Z.
Thanks for the independent Windows run and for the adapter and driver details.
Fixture-level Wine evidence at
104617d6: under Proton Experimental's Wine on Linux (test binaries cross-built with clang-cl 19 against the Windows SDK, our CTest-driven Wine runner, 2 jobs), all four placeholder-split rows pass:xmem_placeholder_split,xmem_placeholder_split_control,xmem_placeholder_split_deployedandxmem_placeholder_split_partial. Thepartialrow's result line: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
run.sh's default joining, plus the matching control run withX2W_XMEM_JOIN_CALLS=0. For each run I'll post the commit, the command, the environment and the end line or first mismatch.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T10:33:52Z.
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
0c6be971with the input script only (one A, no hand input), under Wine: the executable reads the A at 49 s and then opens no archive after the menus before we stopped the runs at about 6.5 min (3 runs). With the local menu-skipping change, which is not in this PR, it opens that archive at 67.3 s (1 run).This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T10:55:46Z.
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:
0c6be971(this PR's head before mergingmain) with the local menu-skipping change. That change is not in this PR. It lets a script-only run read a save and skip the menus. Without it, the menus need input the script doesn't give: the runs read the script's one A at about 49 s and then wait in the menu (3 runs, stopped at about 6.5 min).tools/startup/run.sh --seconds 0 --memory-gib 40 --continue-asserts 1000 --fake-user --render --translate --gpu-mirror --host-cpu --startup-below-40, an input script that presses A once,X2W_XMEM_LAZY_COMMIT=1 X2W_XMEM_LAZY_STARTUP=1, and the switches listed in the body.X2W_TITLE_ID/X2W_STORAGE_MBwere set by hand (see below).run.sh's defaults, soX2W_XMEM_SHARED_VIEWS=1andX2W_XMEM_JOIN_CALLS=1. C: the same withX2W_XMEM_JOIN_CALLS=0. In the executable's environment, that is the only difference.Not measured yet: the current head.
main's #2979 changes the shader key revision from 28 to 29, so every earlier translation misses. A current-head run first needs those shaders translated again. So far the start-up path has asked for 1855 rev-29 requests. 3 graphics requests translated; the rest were refused, mostly compute. That run is next, once the test machine is free.Found along the way, outside this PR: on Linux,
run.shlooks forMicrosoftGame.config, and this package shipsMicrosoftGame.Config, so the manifest's title ID and storage size are not read.run.shalso needs a desktopDISPLAYin its environment.This comment was AI-assisted.