xmem: hold the 32-bit window [2 GiB, 4 GiB), tell a refused 2 MiB commit as the retry error, working-set statistics at the console's size (XMEM-LOW-WINDOW, XMEM-FALLBACK-STATS) #3444

Merged
leonida/mandy
MoonEyes merged 4 commits from fix/xmem-low-window into main 2026-12-04 11:32:09 +00:00

Pull request successfully merged and closed

Member

Two commits, one per item; each has its own switch.

What

  1. 32-bit window. title_range::keep now also holds the free places of [2 GiB, 4 GiB) with no access, at the same
    place as the title's range (before Streamline, DLSS and the drivers load). XMemVirtualAlloc places a request with
    the 32-bit flag and no base in it, the lowest place that fits; a request it cannot place goes to the host below 4 GiB
    as before, with a warning. If part of the window was taken before the start, the rest is held and one log line says
    how much. LEONIDA_XMEM_LOW_WINDOW=0 holds nothing there. Per console behaviour a 32-bit request gets an address in
    that window and nothing else of the process lies there; here images, heaps and drivers did (#3337: 185 MB refused with
    a 27.8 MiB free run left, then the title stopped). The window is plain reservations like the title's range, not one
    placeholder (the range's header says why a placeholder does not fit write-watched memory).
  2. Fallback error. A commit of 2 MiB pages the host refuses for lack of memory (8, 14, 1816) ends with error 1450;
    per console behaviour the title's allocator then retries with 64 KiB pages, where any other code is a failed
    allocation (the 0x8007000E players saw). The host's error is kept for every refused request (the logging after it
    changed it; a test read 0). LEONIDA_XMEM_FALLBACK_ERROR=0: as before.
  3. Statistics. XMemGetWorkingSetStatistics writes the 0x78 bytes of the console's structure (it wrote 0x50), reads
    the first argument as a mask of partitions (0x20000001: the title's), and the use is what the title holds (its
    commits, the host heap behind XMemAlloc, its physical pages), never more than the limit, instead of the whole
    process's commit. Peak, page count and kernel pool are told; the bandwidth-optimal limit and use are both zero.
    LEONIDA_XMEM_STATS_V2=0: the old 0x50 bytes and figures.
  4. Freeing physical pages that views still show is not changed; it is said once in the log.

In-game run

Game gate (scripts/game-gate.ps1) on a test branch that merges four changes over main a558375458: this PR together with the FFX jitter, XMem low window and descriptor-record changes and a periodic preload save. -SeriesS -PrecompileUsed, RTX 4060 8 GB, driver 32.0.16.1088, Windows 11, build with diagnostics. PASS, 314 s in the world, no device loss, median 17.7 fps, VRAM peak 6 390 MB for a 6 776 MB budget. Warning fault_after_stop (access violations in the runtime after the gate stopped the run, clean exit): the same 8 faults appear on a run of another branch, so most likely not from this change (not yet compared with main). cargo test --locked -p leonida-gpu -p leonida on that test branch: 742 + 62 + 5 passed, 0 failed.

Seen in the log: 32-bit window held: [2 GiB, 4 GiB) reserved ... held_mb=2048, and no 0x8007000E. Not measured yet: the statistics line before and after, and an AMD card.

Tested

  • cargo test -p leonida-hle --locked (286 passed, 2 ignored), cargo test -p leonida-gpu --locked title_range, cargo clippy clean on the touched files, python -I tests/test_d3d12_switches.py, switches.md regenerated, check_no_game_data.py on the touched files.
  • New tests fail with their switch at 0 (fallback error, statistics size) or do not compile without the change (the rest).

AI-assisted

Written with Claude Opus 5.5 (Claude Code); reviewed twice by a separate Claude Opus 5.5 reviewer instance (the used counter that never went down, among other points, is fixed). Two minor points left: a 0-size decommit not at the base removes 1 byte from the count, and the count drops even when VirtualFree fails, as before.

🤖 Generated with Claude Code

Two commits, one per item; each has its own switch. ## What 1. **32-bit window.** `title_range::keep` now also holds the free places of [2 GiB, 4 GiB) with no access, at the same place as the title's range (before Streamline, DLSS and the drivers load). `XMemVirtualAlloc` places a request with the 32-bit flag and no base in it, the lowest place that fits; a request it cannot place goes to the host below 4 GiB as before, with a warning. If part of the window was taken before the start, the rest is held and one log line says how much. `LEONIDA_XMEM_LOW_WINDOW=0` holds nothing there. Per console behaviour a 32-bit request gets an address in that window and nothing else of the process lies there; here images, heaps and drivers did (#3337: 185 MB refused with a 27.8 MiB free run left, then the title stopped). The window is plain reservations like the title's range, not one placeholder (the range's header says why a placeholder does not fit write-watched memory). 2. **Fallback error.** A commit of 2 MiB pages the host refuses for lack of memory (8, 14, 1816) ends with error 1450; per console behaviour the title's allocator then retries with 64 KiB pages, where any other code is a failed allocation (the `0x8007000E` players saw). The host's error is kept for every refused request (the logging after it changed it; a test read 0). `LEONIDA_XMEM_FALLBACK_ERROR=0`: as before. 3. **Statistics.** `XMemGetWorkingSetStatistics` writes the 0x78 bytes of the console's structure (it wrote 0x50), reads the first argument as a mask of partitions (0x20000001: the title's), and the use is what the title holds (its commits, the host heap behind `XMemAlloc`, its physical pages), never more than the limit, instead of the whole process's commit. Peak, page count and kernel pool are told; the bandwidth-optimal limit and use are both zero. `LEONIDA_XMEM_STATS_V2=0`: the old 0x50 bytes and figures. 4. Freeing physical pages that views still show is not changed; it is said once in the log. ## In-game run Game gate (`scripts/game-gate.ps1`) on a test branch that merges four changes over main `a558375458`: this PR together with the FFX jitter, XMem low window and descriptor-record changes and a periodic preload save. `-SeriesS -PrecompileUsed`, RTX 4060 8 GB, driver 32.0.16.1088, Windows 11, build with diagnostics. **PASS, 314 s in the world, no device loss**, median 17.7 fps, VRAM peak 6 390 MB for a 6 776 MB budget. Warning `fault_after_stop` (access violations in the runtime after the gate stopped the run, clean exit): the same 8 faults appear on a run of another branch, so most likely not from this change (not yet compared with main). `cargo test --locked -p leonida-gpu -p leonida` on that test branch: 742 + 62 + 5 passed, 0 failed. Seen in the log: `32-bit window held: [2 GiB, 4 GiB) reserved ... held_mb=2048`, and no `0x8007000E`. Not measured yet: the statistics line before and after, and an AMD card. ## Tested - `cargo test -p leonida-hle --locked` (286 passed, 2 ignored), `cargo test -p leonida-gpu --locked title_range`, `cargo clippy` clean on the touched files, `python -I tests/test_d3d12_switches.py`, `switches.md` regenerated, `check_no_game_data.py` on the touched files. - New tests fail with their switch at 0 (fallback error, statistics size) or do not compile without the change (the rest). ## AI-assisted Written with Claude Opus 5.5 (Claude Code); reviewed twice by a separate Claude Opus 5.5 reviewer instance (the used counter that never went down, among other points, is fixed). Two minor points left: a 0-size decommit not at the base removes 1 byte from the count, and the count drops even when `VirtualFree` fails, as before. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Per console behaviour a 32-bit request gets an address in [2 GiB, 4 GiB) and nothing else of
the process lies there. Here the images, heaps and drivers take it first: the title's 185 MB
32-bit reservation was refused with a 27.8 MiB free run left (#3337). title_range::keep now also
holds the free places of that window, before Streamline, DLSS and the drivers load, and
XMemVirtualAlloc places 32-bit requests in it; what it cannot place goes to the host below 4 GiB
as before, with a warning. A shortfall at the start is kept as held and said in one line.
LEONIDA_XMEM_LOW_WINDOW=0 turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A commit of 2 MiB pages that the host refuses for lack of memory now ends with error 1450 (not
enough system resources), which per console behaviour makes the title's allocator retry with
64 KiB pages; the host's error is kept for every refused request instead of whatever the logging
left. LEONIDA_XMEM_FALLBACK_ERROR=0 turns it off.

XMemGetWorkingSetStatistics writes the 0x78 bytes the console gives, reads the first argument as
a mask of partitions, counts as use only what the title holds (its commits, the host heap behind
XMemAlloc and its physical pages, never more than the limit) and tells the peak, the page count
and the kernel pool; the optimal-bandwidth limit and use stay zero together. LEONIDA_XMEM_STATS_V2=0
gives the old 0x50 bytes and the process's commit back. Freeing physical pages that views still
show is unchanged and said once in the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title's "used" figure kept commits by address and never came down: a decommit of size 0, a
decommit across several commits and a recommit were counted wrong. It is now a map of committed
ranges: a recommit counts once, a decommit or release takes what lay in its range and cuts a range
at its edges, and a size of 0 is the whole allocation. The 0x78 bytes go only to a caller that
passes a partition mask (0x20000000 set), else 0x50. The optimal-bandwidth limit is told again,
its use the title's up to that limit. LEONIDA_XMEM_STATS_V2=0 counts nothing. Also: the string
continuations in title_range, a test that places a 32-bit request in a held window, and
descriptions of the two switches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Member

Merging, with Moon's written OK as maintainer (two maintainers only: the CONTRIBUTING rule against merging one's own PR is waived for this series). Branch updated with main 5238ce44fb, no conflict. The merged tree (cce2dde5) is the one tested locally: cargo test --locked -p leonida-gpu -p leonida -p leonida-hle all passed, tests/test_d3d12_switches.py OK, check_no_game_data.py clean. In-game gate in the description (PASS, 314 s, no device loss, 32-bit window held). AI-assisted (Claude Opus 5.5).

Merging, with Moon's written OK as maintainer (two maintainers only: the CONTRIBUTING rule against merging one's own PR is waived for this series). Branch updated with main `5238ce44fb`, no conflict. The merged tree (`cce2dde5`) is the one tested locally: `cargo test --locked -p leonida-gpu -p leonida -p leonida-hle` all passed, `tests/test_d3d12_switches.py` OK, `check_no_game_data.py` clean. In-game gate in the description (PASS, 314 s, no device loss, 32-bit window held). AI-assisted (Claude Opus 5.5).
Sign in to join this conversation.
No description provided.