Repository navigation
XMem: a reservation we place in the title's window is asked of Windows only where a free run holds it (Series S boot hang that cannot be killed, #3234) - #3787
Conversation
…s only where a free run holds it A VirtualAlloc2 with MEM_ADDRESS_REQUIREMENTS whose range has no free run that holds the request does not always fail. On Windows 11 26300 the Series S title's 3977 MB pool (base 0, kind 0x42000, flags 0x23), asked for in [4 GiB, 128 GiB) whose largest free run was 2047 MB, never came back: 91.6 s of kernel time in 90 s, a process that cannot be ended, a restart (trustno1-coder#3234, trustno1-coder#3023). A game-free probe on 26200 did the same for ranges of 1 GiB and more with no run that fits (trustno1-coder#3234). Every call whose range had a run that fits returned in microseconds. .04's spare is given back only after a refusal, which such a call never reaches. victory_gpu::room walks the range's regions first (VirtualQuery, the walk starting at the caller's hint) and calls VirtualAlloc2 only if a run holds the request at its alignment; otherwise the request is refused there with ERROR_NOT_ENOUGH_MEMORY, as Windows refuses it when it does. Windows still picks the address. Our searches take turns on one lock. Through it: XMemVirtualAlloc's reservations of our placing (place_in_window: the title's spare is given back before Windows is asked again, not after), watched_reservation (no room: the block comes from the heap), reserve_title_spare, and upload.rs's allocate_in_window (the upload pool, the early pieces, the arenas). largest_free_gap is room::largest_free. Tests: a fake address space with trustno1-coder#3234's window and trustno1-coder#2081's, whose "kernel" never returns when asked for what cannot fit, run on threads with a 10 s limit; and the walk over a hole in a placeholder of our own. No reservation that cannot fit is asked of Windows in any test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
In-game test of #3787 (together with #3353): Series S boots, 3/3, no freeze Rig: RTX 4070 Ti 12 GB, driver 610.88, 64 GB RAM, Windows 11 26300, Streamline 2.14.16. Before: vanilla .05 with the same settings, FG off, hung twice the same morning (#2191/#3023 symptoms: white "Americas" window, one core at 100 %, process can't be killed, whole PC frozen, Kernel-Power 41 + WHEA after a reboot). With the two PRs:
Runs 2 and 3 hit exactly the case this PR describes: a constrained request with no free run big enough. Before, that call never came back from the kernel. Run 3 log excerpt:
Small side note: the room walk logs a "took long" warning at 64–164 ms over ~15–17k regions. It is harmless at boot, but worth knowing if it runs during gameplay. Logs available on request. |
Problem
Since v2026.11.29.01 the Series S profile can hang at boot inside
VirtualAlloc2. The process cannot be ended,tasklisthangs, and only a restart (often the power button) clears it (#3234 and #3023: RawTech with an RTX 3080 Ti, jhon17parizotto-byte with an RTX 3060, both on Windows 11 26300; #2963 by its title is the same kind of Series S start). The log stops a few ms aftertitle pipelines to start early, before the title's 3977 MB pool (protection 0x2004, kind 0x42000, flags 0x23) is logged.jhon17parizotto-byte put lines around the call (#3234, run 2): the call is
size=4170186752 base=0 kind=0x42000 flags=0x23 protect=PAGE_NOACCESS, so a placeholder reservation at an address of our choice (MEM_ADDRESS_REQUIREMENTS, [4 GiB, 128 GiB) since c71e16e). "before VirtualAlloc2" was logged, "after" never was. The thread had 91.6 s of kernel time 90 s later. Just before the call (run 3), the largest free run below 128 GiB was 2,047 MB. The request was 3,977 MB.rlenci99 reproduced it without the game on Windows 11 26200 (#3234,
vatest.c): an address-constrainedVirtualAlloc2into a range of 1 GiB or more where no free run holds the request (fully reserved, or with only a 1 MiB run free) was still in the kernel after 78 to 99 minutes, at 99.8 % privileged time. Small fully-reserved ranges (64 to 512 MiB) returned error 8 in microseconds. Every call whose range had a run that fits was placed in 4 to 13 µs.So the refusal we count on does not always come. .04's spare does not help here: it is given back only after a refused call, and a call that never returns never reaches the give-back (as jhon17parizotto-byte noted).
Root cause
We hand Windows searches it cannot satisfy. Every reservation we place with address requirements goes straight to
VirtualAlloc2, with no check that the range has room for it:crates/victory-hle/src/modules/xmem.rs:XMemVirtualAlloc: every request with no base of the title's (constrained), inaddress_range(flags)= [4 GiB, 2^37) (TITLE_TOP_BITS = 37, c71e16e), or the low 4 GiB for 32-bit ones. This includes the Series S pool, the 6.5 GB TileHeap, and everyXMemAllocDefaultgraphics block (virtual_alloc).watched_reservation: everyXMemAllocDefaultheap block of 1 MiB or more,MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, in the same window. Series S profile: boot hang in XMemVirtualAlloc since v2026.11.29.01 — caused by 78324212 (write-watch of title-placed reservations), confirmed by revert #3023 bisected the hang to 7832421 and booted with it reverted. That commit is the placed write watch (watch_placement), but it also moved these blocks off the host heap into reservations of their own, placed bottom-up, so into the low addresses the window is in (later limited toaddress_range). jhon17parizotto-byte's run withwatch_placement = falsestill hung (Series S boot hang:VirtualAlloc2never returns for the 3977 MB reservation when no gap below 128 GiB fits it (TITLE_TOP_BITS = 37) #3234), which fits the second part: a window that fills earlier. That reading is ours, not measured.reserve_title_spare(f72cec7): 8 GiB top-down in the window at start.crates/victory-gpu/src/upload.rs,allocate_in_window:reserve_space's 32 pieces of 64 MiB (top-down),reserve_early's 64 MiBMEM_WRITE_WATCHpieces (3,200 MB with the structure builder), andreserve's arenas. RTX 3090: ray tracing freezes the driver at frame 2 (process cannot be ended); the early low-memory reservation causes it, VICTORY_LOW_EARLY_MB=0 avoids it #2973's freeze at frame 2 with ray tracing (a process that could not be ended, 3 of 3 runs) went away withVICTORY_LOW_EARLY_MB=0(0 of 3), which fits a fuller window too; not shown to be this.largest_free_gapalready walked the free runs, but only for the log, after a refusal.Fix
A new module,
crates/victory-gpu/src/room.rs, used by every call above:room(space, lowest, highest, size, alignment, hint)walks the regions of the range (VirtualQuery; no search in the kernel). It returns the first place that holdssize(rounded to the host page) atalignment(at least 64 KiB) inside[lowest, highest], if there is one. The first 64 KiB are never room. The walk starts at the caller'shint(where room was found the last time) and comes round tolowest, so the common case reads a region or two. Only a request that fits nowhere walks the whole window.reserve_in(space, ..., hint, reserve)callsreserve(the caller's ownVirtualAlloc2, unchanged) only ifroomfound a place. Otherwise it returnsNonewithout calling, withERROR_NOT_ENOUGH_MEMORYas the thread's last error, which is what Windows gives when it does refuse. Our searches take turns on one lock (SEARCHES), so one of ours cannot take the run another has just seen. A walk over 20 ms is logged (first, then each power of two) with its region count.Spaceis a trait (Host= this process), so the tests can give it a fake address space.In
xmem.rs:XMemVirtualAlloc's constrained path goes throughplace_in_window: ask (if there is room), and if that does not place it, giveTITLE_SPAREback before Windows is asked again, then ask once more (again only with room). The "no room at first" line gainshost_asked(false: Windows was not asked, no room).watched_reservation: no room means no reservation, so the block comes from the host heap, asXMemAllocDefaultalready does when the reservation fails.reserve_title_spare: through the same check.largest_free_gapisroom::largest_freenow (same output: largest run, number of runs).In
upload.rs,allocate_in_windowgoes throughroom::reserve(no room:Err(8), whichreserve_space,reserve_earlyandreservealready handle).What the title then gets: the Series S pool and the TileHeap are refused (null) when nothing in the window holds them, even after the spare is given back. So a PC whose window is that full gets the title's own crash on the refusal (
+0x1e6c284for the TileHeap, #2081) instead of an unkillable process and a hard power-off. Getting such a PC to boot is a separate question: a fallback above 128 GiB (#2133) or a smaller spare (#3353). Both work with this: #2133's second call goes through the same check if it is placed insideplace_in_window.Verification
Windows 11 26200, rustc 1.98.1 (the pinned toolchain), Ryzen 7 9800X3D. On b041626:
cargo check -j 6 --locked -p victory-gpu -p victory-hle --all-targets: passes (the crates' existing warnings only).cargo test -j 6 --locked -p victory-gpu --lib room::: 7 passed, 0 failed.a_request_no_free_run_holds_is_refused_without_asking: Series S boot hang:VirtualAlloc2never returns for the 3977 MB reservation when no gap below 128 GiB fits it (TITLE_TOP_BITS = 37) #3234's window (free runs of 1,100 MB, 2,047 MB and 64 KiB, the rest taken in 64 MiB pieces with 64 KiB gaps). The 4,170,186,752-byte pool is asked for on a thread of its own through a fake "kernel" that never returns when nothing fits. It comes back refused within the 10 s limit, and the kernel was never asked.a_request_that_fits_is_asked_for_and_placed: 2,000 MiB goes to the 2,047 MB run, then 100 MiB to the 1,100 MB run (the walk comes round from the hint), each asked once.a_place_is_aligned_as_asked,the_walk_starts_at_the_hint_and_comes_round,free_runs_end_at_the_range_end,the_first_64_kib_are_never_room: alignment (64 KiB and 2 MiB), page rounding, the hint inside a used region, inside a free run and outside the range, runs clipped at the range's end, a range ending atusize::MAX, the first 64 KiB.the_host_walk_sees_a_hole_in_our_own_reservation: the realVirtualQuerywalk. A 256 MiB placeholder of our own (top-down, fixed by Windows, no requirements) is split and its middle 64 MiB released. The walk sees one free run of 64 MiB, places 32 and 64 MiB at the hole and not 64 MiB + 4 KiB, andreserve_inrefuses 128 MiB without calling, with error 8. No constrainedVirtualAlloc2is made.cargo test -j 6 --locked -p victory-hle --lib modules::xmem::tests::: 45 passed, 1 failed, 1 ignored. The failure isa_read_by_range_waits_only_for_a_remapping_that_meets_it("a read apart from the remapping had to wait", 7025 vs 0), the range-lock test known to fail beside the other tests (XMem tests: the range-lock read test runs alone against the tests that copy mappings (9 in 10 runs failed) #2439: 9 in 10 runs; XMem tests: the range lock's test runs in a process of its own #3621 moves it to a process of its own). It does no reservation of ours. Run alone (-- --exact): 1 passed. The rest with--skipit: 45 passed, 0 failed, 1 ignored. The new ones:the_title_heap_is_placed_after_the_spare_is_given_back_without_a_blind_search: Regression in v2026.11.29.01 (#1041): start crash, 6.2 GB TileHeap no longer fits below 2^37 (RTX 4090, Windows) #2081's window (two 24 GiB title pools, 36 + 28 GiB of the driver's at 60 and 96 GiB, the 2 GiB upload pool, the 8 GiB spare in the one run that holds it, 2 GiB left). The 6,538,919,936-byte heap (flags 0x23) on its own thread, fake kernel as above:First::NoRoom, the kernel not asked before the spare is given back, then placed where the spare was, asked once, within 10 s.a_reservation_with_no_room_and_no_spare_is_refused_at_once: the same with no spare: refused, never asked, the log figures right (largest run 2 GiB).a_reservation_that_fits_is_asked_for_and_a_refused_one_gets_the_spare: 1 GiB is placed at 124 GiB. One refused by "Windows" (refuse_first, asVICTORY_TEST_REFUSE_MB) still gets the spare.graphics_memory_types_are_title_graphics_memory,alloc_honours_alignment_and_freesandtitle_memory_stays_within_the_by_address_directorypass. They make real reservations through the new path in the test process's empty window.cargo clippy -j 6 --locked -p victory-gpu -p victory-hle --all-targets: finishes with warnings only. None is inroom.rsor on a line this changes inxmem.rs,upload.rsorlib.rs(checked againstgit diff -U0 41adb551 b0416267). The first run flaggedroom.rs:60(then→then_some), fixed in this commit.NOT tested
VirtualQueryis some microseconds a region. The window holds the title's placeholders and whatever they are split into (~700 ms synchronous process-memory walk every 5 s (93k regions) freezes the frame #3279 counted 93k regions in the whole process). With the hint, a request that fits reads a few regions. A request that does not fit walks the whole window once, and twice if the spare is given back. The 20 ms warning will show it if it matters.victory run <exe> --console series-s --execute, DLSS Performance at 1080p, frame generation off, the shader cache warm. Before: the log ends aftertitle memory asked for as protection 0x4, kind 0x203000, flags 0x3: 4 times, 82 MBand the process cannot be ended. After: within a second of that point,XMemVirtualAlloc: no room at first in the title's window size=4170186752 ... host_asked=false ... spare_given_back=trueand either the pool placed orXMemVirtualAlloc refusedand the title's own crash, a process that can be ended.Overlap
gh pr list --state open --searchfor "VirtualAlloc2", "xmem", "XMemVirtualAlloc", "spare", "free gap", "write-watch" (2026-11-30).git merge-treeof this branch with each PR head:VirtualAlloc2never returns for the 3977 MB reservation when no gap below 128 GiB fits it (TITLE_TOP_BITS = 37) #3234 (watch_placement = false) still hung, so it is not enough alone, and this does not replace it.allocate(kind), and it already conflicts with main there (1 hunk). Complementary: it is what lets a full window boot instead of being refused. Its second call should go throughplace_in_window/room::reservewith the console's top ashighest(that range is nearly empty, so the check is short).upload.rs::reserve): merges cleanly. Its backoff is inreserve; this is insideallocate_in_window.XMemVirtualAlloc): 1 conflict hunk, both rewritelet mut at = ...inXMemVirtualAlloc. Its deferred path is for title-placed commits (base given), so the two compose: take itsdeferredbranch first, then this branch'sif constrainedblock.PAGE_NOACCESS): merges cleanly.VirtualAlloc2never returns for the 3977 MB reservation when no gap below 128 GiB fits it (TITLE_TOP_BITS = 37) #3234 suggests exactly this check before every such call (watched_reservation,allocate_in_window), and names draft gpu: coalesce concurrent failed low-memory window searches #3293 forupload.rs. No open PR does it.AI use
Claude Code (Claude Opus 5.5) read the issues' text (no attachments), wrote the change and its tests, ran the checks listed above, and wrote this note. Nothing was run in game.
🤖 Generated with Claude Code