Skip to content

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

Open
Lyrnc wants to merge 1 commit into
trustno1-coder:mainfrom
Lyrnc:fix/xmem-no-block
Open

Lyrnc wants to merge 1 commit into
trustno1-coder:mainfrom
Lyrnc:fix/xmem-no-block

Conversation

@Lyrnc

@Lyrnc Lyrnc commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Since v2026.11.29.01 the Series S profile can hang at boot inside VirtualAlloc2. The process cannot be ended, tasklist hangs, 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 after title 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-constrained VirtualAlloc2 into 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:

largest_free_gap already 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 holds size (rounded to the host page) at alignment (at least 64 KiB) inside [lowest, highest], if there is one. The first 64 KiB are never room. The walk starts at the caller's hint (where room was found the last time) and comes round to lowest, so the common case reads a region or two. Only a request that fits nowhere walks the whole window.
  • reserve_in(space, ..., hint, reserve) calls reserve (the caller's own VirtualAlloc2, unchanged) only if room found a place. Otherwise it returns None without calling, with ERROR_NOT_ENOUGH_MEMORY as 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.
  • Windows still picks the address. The check only says that a fitting run exists, so placements are the same as before wherever there is room.
  • Space is a trait (Host = this process), so the tests can give it a fake address space.

In xmem.rs:

  • XMemVirtualAlloc's constrained path goes through place_in_window: ask (if there is room), and if that does not place it, give TITLE_SPARE back before Windows is asked again, then ask once more (again only with room). The "no room at first" line gains host_asked (false: Windows was not asked, no room).
  • watched_reservation: no room means no reservation, so the block comes from the host heap, as XMemAllocDefault already does when the reservation fails.
  • reserve_title_spare: through the same check.
  • largest_free_gap is room::largest_free now (same output: largest run, number of runs).

In upload.rs, allocate_in_window goes through room::reserve (no room: Err(8), which reserve_space, reserve_early and reserve already 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 (+0x1e6c284 for 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 inside place_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: VirtualAlloc2 never 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 at usize::MAX, the first 64 KiB.
    • the_host_walk_sees_a_hole_in_our_own_reservation: the real VirtualQuery walk. 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, and reserve_in refuses 128 MiB without calling, with error 8. No constrained VirtualAlloc2 is made.
  • cargo test -j 6 --locked -p victory-hle --lib modules::xmem::tests::: 45 passed, 1 failed, 1 ignored. The failure is a_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 --skip it: 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, as VICTORY_TEST_REFUSE_MB) still gets the spare.
    • The existing graphics_memory_types_are_title_graphics_memory, alloc_honours_alignment_and_frees and title_memory_stays_within_the_by_address_directory pass. 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 in room.rs or on a line this changes in xmem.rs, upload.rs or lib.rs (checked against git diff -U0 41adb551 b0416267). The first run flagged room.rs:60 (then → then_some), fixed in this commit.

NOT tested

  • No game run, on purpose: a hang here needs a hard power-off. Not run on the Series S profile, on Windows 11 26300 (where the reports are), or on any PC whose window is full.
  • No probe of the real hang. The tests never ask Windows for a reservation that cannot fit. The Host test only makes fixed reservations and placeholder splits of its own, then runs the walk over them. Whether the check removes every hang rests on rlenci99's table: every hang had no fitting run, every call with one returned in microseconds. If a constrained call can hang with a fitting run, this does not cover it.
  • The walk's cost in game is not measured. VirtualQuery is 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.
  • Others' reservations between the check and the call are not covered. Only our own searches take turns. The driver (nvcuda's 36 + 28 GiB in Regression in v2026.11.29.01 (#1041): start crash, 6.2 GB TileHeap no longer fits below 2^37 (RTX 4090, Windows) #2081) or another library reserving the same run in those microseconds would bring the old hang back.
  • v2026.11.29.04 hangs while walking the shader cache (never reaches the window; .03 starts on the same cache) #3273's stop in the shader-cache walk is not shown to be this. That process was idle (16 s of CPU in 3 minutes), not spinning in the kernel like the hangs above. XMem: the title's spare defaults to 6,300 MiB, a little more than its 6,236 MiB heap (#3273) #3353 (spare 6,300 MiB) is what fixed it there.
  • Exact repro once someone can risk a hard power-off (Windows 11 26300, Series S files): victory run <exe> --console series-s --execute, DLSS Performance at 1080p, frame generation off, the shader cache warm. Before: the log ends after title memory asked for as protection 0x4, kind 0x203000, flags 0x3: 4 times, 82 MB and 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=true and either the pool placed or XMemVirtualAlloc refused and the title's own crash, a process that can be ended.

Overlap

gh pr list --state open --search for "VirtualAlloc2", "xmem", "XMemVirtualAlloc", "spare", "free gap", "write-watch" (2026-11-30). git merge-tree of this branch with each PR head:

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

…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>
@biishop

biishop commented Nov 30, 2026

Copy link
Copy Markdown

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.
Build: local build of v2026.11.29.05 (41adb55) + #3787 (b041626) + #3353 (25ee3b4), clean merge, cargo build --release --locked -p victory. cargo test -p victory-gpu room: 25 passed.
Settings: Series S, scene 540p, DLSS performance, VICTORY_TITLE_SPARE_MB unset (so #3353's 6,300 MiB default applies).

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:

Run FG 3977 MB pool 1632 MB reservation Result
1 off 0x1b00000000 fit on the first try boot OK
2 off 0x1b00000000 largest free run 633 MB → refused, spare returned, placed at 0x1dcea10000 boot OK
3 2x (DLSS FG) 0x1b00000000 largest free run 178 MB → refused, spare returned, placed at 0x1deb1d0000 boot OK

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:

WARN victory_gpu::room: a placed reservation's look for room took long size=1711669248 regions=16960 ms=100 times=2
WARN victory_hle::modules::xmem: XMemVirtualAlloc: no room at first in the title's window size=1711669248 kind=0x42000 flags=0x23 error=(os error 8) host_asked=false largest_free_mb=178 free_runs=47 spare_given_back=true
INFO victory_hle::modules::xmem: title memory asked for as protection 0x2404, kind 0x42000, flags 0x23: 1 times, 1632 MB, last 0x1deb1d0000+0x66060000

host_asked=false: Windows was never asked for the reservation that could not fit. The spare from #3353 was then returned, and the retry succeeded right away. So the two PRs work together here: #3787 prevents the kernel hang, and #3353 makes sure there is room on the retry. Frame generation only takes up more of the window (633 → 178 MB largest free run); it is not the cause.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants