XMem: the title's reservations in its window go where our own walk of it finds room (#3765) #3767

Merged
sansj24k merged 1 commit from upstream-pr/3767 into main 2026-11-30 14:12:01 +00:00
sansj24k commented 2026-11-30 06:28:05 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by sansj24k on 2026-11-30T06:28:05Z.


Fixes #3765 (and likely #2737, the same white window on a second start).

What was wrong

The issue's reporter took a kernel dump of the hang. A constrained XMemVirtualAlloc (one with MEM_ADDRESS_REQUIREMENTS) leaves the address search to the kernel. On a second start with a saved pipeline library, thousands of pipelines start early beside the title's 3.9 GB placeholder. The search for that placeholder then ran for 27 s in nt!MiFindEmptyAddressRange/RtlFindClearBitsEx while holding the process's address-space lock. dxgmms2 waited on that lock while holding its recycle-heap mutex, other GPU allocations queued behind it, and the PC could not start new programs until it was powered off.

What this changes

In XMemVirtualAlloc, for constrained reservations only:

  • The window is walked with VirtualQueryEx. The walk stops at the first free region that holds the size from an aligned start (64 KiB, or 2 MiB when asked).
  • VirtualAlloc2 is given that address, with no address requirements, so the kernel has nothing to search.
  • If another thread takes the place in between, the next try starts past it, up to four tries. If nothing fits, the kernel's search runs as before, and so does the existing spare-release retry.
  • MEM_TOP_DOWN requests stay with the kernel.
  • The search never starts at 0. In the 32-bit window a null address would mean "anywhere"; the existing 32-bit tests caught this.
  • VICTORY_XMEM_OWN_SEARCH=0 restores the old behaviour. The setting is logged once at its first use.

The root cause, the dump and the fix are the reporter's. They tested the fix on their PC with the same reproduction: two second starts with saved caches (1844 and 2271 early pipelines) got through, where the unpatched build hung 3 of 3 times. This PR is that fix alone. It leaves out the other changes in their patch (watchdog default, priorities, job object, escape key, launcher hang watch), since those change defaults and are separate decisions.

Checks

  • Two new tests:
    • our_own_search_takes_the_first_aligned_room_in_the_window: the first-fit rules.
    • our_own_search_places_reservations_in_the_window: real reservations on this process.
  • Every existing null-base XMemVirtualAlloc test now goes through the new path and passes.
  • cargo test -p victory-hle: 424 pass. The one failure, a_read_by_range_waits_only_for_a_remapping_that_meets_it, is a timing test that fails the same way on main (#3621 moves it into its own process).
  • cargo clippy -p victory-hle --all-targets --no-deps -- -D warnings reports only the errors already on main, in gameinput.rs and lifecycle.rs.
  • I could not reproduce the hang itself; I don't have the game.

Overlap

#3738, #3126, #3242 and #2133 also edit XMemVirtualAlloc. Whichever lands second will need a small rebase around the allocate closure.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5560241211 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3767). Originally posted by [sansj24k](https://github.com/sansj24k) on 2026-11-30T06:28:05Z. --- Fixes #3765 (and likely #2737, the same white window on a second start). ### What was wrong The issue's reporter took a kernel dump of the hang. A constrained `XMemVirtualAlloc` (one with `MEM_ADDRESS_REQUIREMENTS`) leaves the address search to the kernel. On a second start with a saved pipeline library, thousands of pipelines start early beside the title's 3.9 GB placeholder. The search for that placeholder then ran for 27 s in `nt!MiFindEmptyAddressRange`/`RtlFindClearBitsEx` while holding the process's address-space lock. `dxgmms2` waited on that lock while holding its recycle-heap mutex, other GPU allocations queued behind it, and the PC could not start new programs until it was powered off. ### What this changes In `XMemVirtualAlloc`, for constrained reservations only: - The window is walked with `VirtualQueryEx`. The walk stops at the first free region that holds the size from an aligned start (64 KiB, or 2 MiB when asked). - `VirtualAlloc2` is given that address, with no address requirements, so the kernel has nothing to search. - If another thread takes the place in between, the next try starts past it, up to four tries. If nothing fits, the kernel's search runs as before, and so does the existing spare-release retry. - `MEM_TOP_DOWN` requests stay with the kernel. - The search never starts at 0. In the 32-bit window a null address would mean "anywhere"; the existing 32-bit tests caught this. - `VICTORY_XMEM_OWN_SEARCH=0` restores the old behaviour. The setting is logged once at its first use. The root cause, the dump and the fix are the reporter's. They tested the fix on their PC with the same reproduction: two second starts with saved caches (1844 and 2271 early pipelines) got through, where the unpatched build hung 3 of 3 times. This PR is that fix alone. It leaves out the other changes in their patch (watchdog default, priorities, job object, escape key, launcher hang watch), since those change defaults and are separate decisions. ### Checks - Two new tests: - `our_own_search_takes_the_first_aligned_room_in_the_window`: the first-fit rules. - `our_own_search_places_reservations_in_the_window`: real reservations on this process. - Every existing null-base `XMemVirtualAlloc` test now goes through the new path and passes. - `cargo test -p victory-hle`: 424 pass. The one failure, `a_read_by_range_waits_only_for_a_remapping_that_meets_it`, is a timing test that fails the same way on `main` (#3621 moves it into its own process). - `cargo clippy -p victory-hle --all-targets --no-deps -- -D warnings` reports only the errors already on `main`, in `gameinput.rs` and `lifecycle.rs`. - I could not reproduce the hang itself; I don't have the game. ### Overlap #3738, #3126, #3242 and #2133 also edit `XMemVirtualAlloc`. Whichever lands second will need a small rebase around the `allocate` closure.
victorious-gh commented 2026-11-30 06:31:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by victorious-gh on 2026-11-30T06:31:46Z.


My claude agent reviewed the pr and approved that this is the same fix it had applied for me. :) if someone else experiencing the issue could test it that would be great.

Yes, the PR is accurate, and in one place it's better than our version. It contains only the xmem.rs fix, built on 41adb55. It uses the same method, the same VICTORY_XMEM_OWN_SEARCH=0 switch and the same fallback to Windows' own search, and it also leaves MEM_TOP_DOWN requests to Windows. The launcher, priority, watchdog and crash-exit changes aren't in it, which is right for a focused PR.

It differs from our version in three ways:

It fixes a bug in our version. For the title's requests in the low 4 GB, the range starts at address 0. Our search could return 0 there, and passing 0 to Windows means "put it anywhere", so the low-4-GB limit was lost. Your logs show this happened. In the fixed run, the title's 185 MB request for low memory (flags=0x7) was placed at 0x22713690000. The unpatched build put it at 0xd350000, below 4 GB. The game still ran for 6 minutes, but the title asked for an address below 4 GB and may depend on getting one. The PR starts the search at 64 KB at the lowest (lowest.max(step)), which avoids this.
The region walk stops early. It reads memory regions one at a time and stops at the first that fits. Ours listed them all first. Same result, less work.
It adds a test on real memory. The test reserves actual memory, checks that it lands aligned inside the range, and checks that a second reservation doesn't overlap the first. I ran the PR's unit test for the search logic here and it passes. The real-memory test only runs on Windows.

One caveat for the PR description: the build you tested had our version, with the low-4-GB bug. So the PR's exact code hasn't been run on your PC yet. Worth saying so in the PR, and worth testing it yourself.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7270742580 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3767#issuecomment-7270742580). Originally posted by [victorious-gh](https://github.com/victorious-gh) on 2026-11-30T06:31:46Z. --- My claude agent reviewed the pr and approved that this is the same fix it had applied for me. :) if someone else experiencing the issue could test it that would be great. > Yes, the PR is accurate, and in one place it's better than our version. It contains only the xmem.rs fix, built on 41adb55. It uses the same method, the same VICTORY_XMEM_OWN_SEARCH=0 switch and the same fallback to Windows' own search, and it also leaves MEM_TOP_DOWN requests to Windows. The launcher, priority, watchdog and crash-exit changes aren't in it, which is right for a focused PR. > > It differs from our version in three ways: > > It fixes a bug in our version. For the title's requests in the low 4 GB, the range starts at address 0. Our search could return 0 there, and passing 0 to Windows means "put it anywhere", so the low-4-GB limit was lost. Your logs show this happened. In the fixed run, the title's 185 MB request for low memory (flags=0x7) was placed at 0x22713690000. The unpatched build put it at 0xd350000, below 4 GB. The game still ran for 6 minutes, but the title asked for an address below 4 GB and may depend on getting one. The PR starts the search at 64 KB at the lowest (lowest.max(step)), which avoids this. The region walk stops early. It reads memory regions one at a time and stops at the first that fits. Ours listed them all first. Same result, less work. It adds a test on real memory. The test reserves actual memory, checks that it lands aligned inside the range, and checks that a second reservation doesn't overlap the first. I ran the PR's unit test for the search logic here and it passes. The real-memory test only runs on Windows. > > One caveat for the PR description: the build you tested had our version, with the low-4-GB bug. So the PR's exact code hasn't been run on your PC yet. Worth saying so in the PR, and worth testing it yourself.
sdpiter commented 2026-11-30 14:59:05 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by sdpiter on 2026-11-30T14:59:05Z.


Tested this on GTA VI (b99f876b74d4a77f…), RTX 4070 Ti 12 GB, Ryzen 5700G, 32 GB, Windows 11 26300, driver 32.0.16.2140.

Built fix/xmem-own-search (0ee9f6cf) from source (rustc 1.100.1, release), then warmed the cache:
83881 pipelines known, 83881 made in 2094 s (1 have no host pipeline, 0 ended their process), fingerprint f13c3a2e45b330c0.

Two consecutive starts — no hang. First run reached the world, closed with WM_CLOSE, exit 0; second run started again on the saved pipeline cache (8847 lines of log, window up at 3 fps / ~300 ms, 14k draws), closed cleanly, exit 0. Before this patch the second start on this machine hung the whole desktop, so for us the fixed address-space search does what it says.

Two other things I hit on the way, both not from this patch:

  1. VICTORY_NATIVE_1440P=1 with run kills the title ~2 min in:
    unhandled exception 0x80000003 at victory-image-…dll+0x2219650 (breakpoint inside title code), right after display refresh rates … [60] / frame interval interval=33.333ms, then Breakpad uploads a 27 MB dump.
    Same crash with a control build of main (c71899d9, no patch, same env, same cache) → independent of #3767. Without the switch it boots fine (title sees 3840x2160).

  2. play --res 1440 (our F1 settings file has VICTORY_MENU_DLSS=quality, so DLSS ends up on) stalls at 1 draws/frame right after display 3440x1440 SDR, scene 2293x960 through the title's FidelityFX path: log stops dead (compile memory: process 9536 MB private), and the whole PC becomes unresponsive for minutes. That is the known DLSS freeze for us on this base, so it says nothing about the xmem fix — with DLSS off (as in the two runs above) repeated starts are fine.

Logs: warm + both starts + the 0x80000003 dump attempt, if useful. Cache fingerprint above; happy to retest any build you point at.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7282242192 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3767#issuecomment-7282242192). Originally posted by [sdpiter](https://github.com/sdpiter) on 2026-11-30T14:59:05Z. --- Tested this on GTA VI (b99f876b74d4a77f…), RTX 4070 Ti 12 GB, Ryzen 5700G, 32 GB, Windows 11 26300, driver 32.0.16.2140. Built `fix/xmem-own-search` (0ee9f6cf) from source (rustc 1.100.1, release), then warmed the cache: `83881 pipelines known, 83881 made in 2094 s (1 have no host pipeline, 0 ended their process)`, fingerprint `f13c3a2e45b330c0`. **Two consecutive starts — no hang.** First run reached the world, closed with WM_CLOSE, exit 0; second run started again on the saved pipeline cache (8847 lines of log, window up at 3 fps / ~300 ms, 14k draws), closed cleanly, exit 0. Before this patch the second start on this machine hung the whole desktop, so for us the fixed address-space search does what it says. Two other things I hit on the way, both **not** from this patch: 1. `VICTORY_NATIVE_1440P=1` with `run` kills the title ~2 min in: `unhandled exception 0x80000003 at victory-image-…dll+0x2219650` (breakpoint inside title code), right after `display refresh rates … [60]` / `frame interval interval=33.333ms`, then Breakpad uploads a 27 MB dump. Same crash with a control build of `main` (c71899d9, no patch, same env, same cache) → independent of #3767. Without the switch it boots fine (title sees 3840x2160). 2. `play --res 1440` (our F1 settings file has `VICTORY_MENU_DLSS=quality`, so DLSS ends up on) stalls at `1 draws/frame` right after `display 3440x1440 SDR, scene 2293x960 through the title's FidelityFX path`: log stops dead (`compile memory: process 9536 MB private`), and the whole PC becomes unresponsive for minutes. That is the known DLSS freeze for us on this base, so it says nothing about the xmem fix — with DLSS off (as in the two runs above) repeated starts are fine. Logs: warm + both starts + the 0x80000003 dump attempt, if useful. Cache fingerprint above; happy to retest any build you point at.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!3767
No description provided.