XMemAllocDefault: big blocks from write-watched memory (VICTORY_ALLOC_WATCHED_KB) #10

Manually merged
github merged 43 commits from github-bot/gh-10 into main 2026-12-04 02:41:31 +00:00 AGit
Owner

@⁠luannzin on GitHub · 2026-12-02 01:29 UTC · original
luannzin:xmem-watched-default-alloc → main · +85 −0 · 1 files · 1 commits · merged 2026-12-04 02:38 UTC

What this changes

XMemAllocDefault can take its big blocks from write-watched virtual memory below 2^40 instead of the host heap. Only crates/victory-hle/src/modules/xmem.rs changes, and nothing changes unless the new switch is set.

  • VICTORY_ALLOC_WATCHED_KB=<n>: blocks of n KiB and more, aligned to 2 MiB at most, come from XMemVirtualAlloc (reserved and committed, graphics flags), which already asks for MEM_WRITE_WATCH and keeps to the console's address range. Unset or 0: every block from the host heap, as before.
  • Such a block is remembered by its address and freed through title_virtual_free, so the notes the GPU side keeps of its memory go with it. Other blocks keep their header and the host heap.
  • A block the host refuses falls back to the host heap.

Why

The host heap's memory is not write-watched, so a title buffer that lies in it is compared whole wherever a refresh looks for what the CPU wrote. Committed resources take their memory from the title's allocator (resource.rs, Memory::for_resource), and here that ended in XMemAllocDefault: the log had "a GPU address above 40 bits ... backing=committed" for it.

In the first gameplay room of the prologue one such buffer of 21 MB (at 0x16aede50000 in one run, 0x1caa1020000 in the next) was looked at twice a frame: 42 to 44 MB and 11 to 12 ms of the refreshing threads, for 0.15 MB that had changed ("copied from" in the log, and the traffic line). It was the longest refresh of the flushes the submitting thread waits for: about 12 ms of the 16 ms it waited.

The comment above the host-heap path already said what to do if such memory came to matter ("Sub-allocate from a reservation below 2^40 if one does"). This takes whole allocations instead of sub-allocating, which is why it starts at a size and is off by default.

Measured

Xeon E5-2680 v4 (14 cores, 28 threads), Radeon RX 7600 8 GB, 16 GB, Windows 10 22H2 with the Agility SDK 1.621, Series S profile, diag build of 925ac0a, -Fast -Stream -SoftPages, standing in the same room, two runs one after the other, per frame:

Without VICTORY_ALLOC_WATCHED_KB=1024
The submitting thread worked 66 to 71 ms 56 to 59 ms
Refreshes, of the lists' steps 22.1 to 23.1 ms 13.9 to 14.8 ms
Waiting for the refresh flushes 15.8 to 16.5 ms (longest refreshes 11.9 to 12.6) 12.3 ms (8.7)
Copies in the card's memory 5.3 to 5.8 ms 2.4 to 2.7 ms
The 21 MB buffer twice, 42 MB, 10.7 to 11.3 ms once, 21 MB, 3.1 ms (now at 0xa4e0b0000)
Frames a second 13.2 at 4,700 draws 14.4 to 15.5 at 4,600 draws

The first run is play-20261201-212215, the second play-20261201-213614, both with VICTORY_LEGACY_MUL=data and the other switches of my preset for this PC. The scene is not the same from run to run, so the frame rate says less than the refresh lines do.

Not tested

  • The Series X profile, a long session, and Wine.
  • Sizes other than 1024. Each block is its own reservation, on the host's 64 KiB grid, so a small threshold would cost address space and commit for nothing.
  • Whether the title ever frees such a block while a list still reads it: none was freed in these runs.

Checks

cargo clippy -p victory-hle --all-targets --all-features -- --no-deps -D warnings passes. The workspace clippy does not pass on main today on the pinned toolchain (victory-loader, victory-shader, victory-gpu), with or without this change.

This touches the same file as #3 but not the same functions (#3 is in the physical page allocations).

🤖 Generated with Claude Code

**@⁠luannzin** on GitHub · 2026-12-02 01:29 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/10) `luannzin:xmem-watched-default-alloc` → `main` · +85 −0 · 1 files · 1 commits · merged 2026-12-04 02:38 UTC ## What this changes `XMemAllocDefault` can take its big blocks from write-watched virtual memory below 2^40 instead of the host heap. Only `crates/victory-hle/src/modules/xmem.rs` changes, and nothing changes unless the new switch is set. - `VICTORY_ALLOC_WATCHED_KB=<n>`: blocks of `n` KiB and more, aligned to 2 MiB at most, come from `XMemVirtualAlloc` (reserved and committed, graphics flags), which already asks for `MEM_WRITE_WATCH` and keeps to the console's address range. Unset or `0`: every block from the host heap, as before. - Such a block is remembered by its address and freed through `title_virtual_free`, so the notes the GPU side keeps of its memory go with it. Other blocks keep their header and the host heap. - A block the host refuses falls back to the host heap. ## Why The host heap's memory is not write-watched, so a title buffer that lies in it is compared whole wherever a refresh looks for what the CPU wrote. Committed resources take their memory from the title's allocator (`resource.rs`, `Memory::for_resource`), and here that ended in `XMemAllocDefault`: the log had "a GPU address above 40 bits ... backing=committed" for it. In the first gameplay room of the prologue one such buffer of 21 MB (at `0x16aede50000` in one run, `0x1caa1020000` in the next) was looked at twice a frame: 42 to 44 MB and 11 to 12 ms of the refreshing threads, for 0.15 MB that had changed ("copied from" in the log, and the traffic line). It was the longest refresh of the flushes the submitting thread waits for: about 12 ms of the 16 ms it waited. The comment above the host-heap path already said what to do if such memory came to matter ("Sub-allocate from a reservation below 2^40 if one does"). This takes whole allocations instead of sub-allocating, which is why it starts at a size and is off by default. ## Measured Xeon E5-2680 v4 (14 cores, 28 threads), Radeon RX 7600 8 GB, 16 GB, Windows 10 22H2 with the Agility SDK 1.621, Series S profile, diag build of 925ac0a, `-Fast -Stream -SoftPages`, standing in the same room, two runs one after the other, per frame: | | Without | `VICTORY_ALLOC_WATCHED_KB=1024` | |---|---|---| | The submitting thread worked | 66 to 71 ms | 56 to 59 ms | | Refreshes, of the lists' steps | 22.1 to 23.1 ms | 13.9 to 14.8 ms | | Waiting for the refresh flushes | 15.8 to 16.5 ms (longest refreshes 11.9 to 12.6) | 12.3 ms (8.7) | | Copies in the card's memory | 5.3 to 5.8 ms | 2.4 to 2.7 ms | | The 21 MB buffer | twice, 42 MB, 10.7 to 11.3 ms | once, 21 MB, 3.1 ms (now at `0xa4e0b0000`) | | Frames a second | 13.2 at 4,700 draws | 14.4 to 15.5 at 4,600 draws | The first run is `play-20261201-212215`, the second `play-20261201-213614`, both with `VICTORY_LEGACY_MUL=data` and the other switches of [my preset for this PC](https://github.com/luannzin/revictory-rx7600). The scene is not the same from run to run, so the frame rate says less than the refresh lines do. ## Not tested - The Series X profile, a long session, and Wine. - Sizes other than 1024. Each block is its own reservation, on the host's 64 KiB grid, so a small threshold would cost address space and commit for nothing. - Whether the title ever frees such a block while a list still reads it: none was freed in these runs. ## Checks `cargo clippy -p victory-hle --all-targets --all-features -- --no-deps -D warnings` passes. The workspace clippy does not pass on `main` today on the pinned toolchain (`victory-loader`, `victory-shader`, `victory-gpu`), with or without this change. This touches the same file as #3 but not the same functions (#3 is in the physical page allocations). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The host heap is not write-watched, so a title buffer in it is compared whole
at every refresh. With VICTORY_ALLOC_WATCHED_KB=<n>, blocks of n KiB and more
come from XMemVirtualAlloc (write-watched, below 2^40) and are freed through
title_virtual_free. Unset: as before.

One 21 MB committed buffer was compared twice a frame, 42 MB and 11 ms, for
0.15 MB that changed. With 1024 the submitting thread works 56-59 ms a frame
where it worked 66-71 (Xeon E5-2680 v4, Series S profile).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 01:30:43 +00:00
github-bot force-pushed github-bot/gh-10 from 326b5607c8 to 5386b892eb 2026-12-04 02:41:30 +00:00 Compare
github manually merged commit 4d4c0eaacb into main 2026-12-04 02:41:31 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.