GPU: remember guarded title blocks, keep the #141 crash fix #208

Closed
github-bot wants to merge 1 commit from github-bot/gh-208 into main AGit
Owner

@⁠TheRifai on GitHub · 2026-12-02 12:33 UTC · original
TheRifai:liveguard-known-view → main · +46 −4 · 2 files · 1 commits · closed without merging

What

Follow-up to #171, where the maintainer isolated the drop to #141 (77a61b9) and asked what the sending waits look like in my logs. They do step up with #141 (6 → 53-61 ms/s in my bisect runs), and the cause is the shape they suggested: live_protect calls is_view for every block it guards, and a faulted block is guarded again thousands of times a second.

This PR remembers the blocks is_view accepted in a new Guards::known_view set. A re-guard of a known block skips the Windows query. The two ways a block can stop being title memory (title_memory_unmapping, title_memory_freed) clear the note, so a reused address is asked about again and #141's crash fix stays in force. Refused blocks were already counted in LIVE_NOT_TITLE and are never remembered — no switch, no fallback, no change to which blocks are guarded.

Evidence

Answer to the maintainer's question, from my earlier matched bisect (1 s stats windows): 31c20c7 had 8 sending waits/s, 6 ms/s and ~8k blocks guarded again/s; 77a61b9 (#141) had 14/s, 53 ms/s and ~13k/s; d59b4f8 had 14/s, 61 ms/s and ~14k/s. slot_reads at Execute stayed ~7 ms per slow frame, so the pause is on the sending path, not descriptor resolution. Evidence: /home/shlong/Documents/VKtory-capture/bisect-{old,current}/, /home/shlong/Documents/VKtory-capture/bisect{77,7c3209,1befc3}/.

A/B/B/A of this patch against main da2c3b1 (same code as d59b4f8 apart from a docs commit), RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, warm store, house save rt3:

Runs Build Mean fps Sending waits ms/s Frames >=50 ms
A1/A2 main 27.15 / 26.93 45.1 / 51.5 183 / 177
B1/B2 patched 28.99 / 29.43 37.2 / 32.7 112 / 100

110 s per run with W/I/K/J at 20/45/70/95 s. Static (no keys), 90 s per run: main 28.51 / 27.68 fps, 50.8 / 48.0 ms/s waits; patched 29.21 / 29.18 fps, 42.4 / 37.6 ms/s. LIVE_NOT_TITLE stayed at 16 in every run — the same Wine stack blocks at 0x100000000, so the filter still declines them. Validation-layer runs were not used for timing. Evidence: /home/shlong/Documents/VKtory-capture/liveguard-{ab,static}-{A1,B1,B2,A2}/.

Checklist (docs/AGENTS.md)

  • One topic; docs/TASKS.md not edited (rules 29/31)
  • No fallback, constant, switch, queue, unsafe or translator output changed (rules 2/9b/33/35/36/27)
  • Comments say what is true now (rule 3)
  • No game content as evidence; only counters, fps and guard counts
  • cargo check -p victory-gpu --features diagnostics and cargo test -p victory-gpu --features diagnostics pass; tools/build.sh exit 0
  • Windows-only tests in watch/live.rs extended to assert the note is made and cleared; they cannot execute on this Linux host
**@⁠TheRifai** on GitHub · 2026-12-02 12:33 UTC · [original](https://github.com/vktory6/VKtory/pull/208) `TheRifai:liveguard-known-view` → `main` · +46 −4 · 2 files · 1 commits · closed without merging ## What Follow-up to #171, where the maintainer isolated the drop to #141 (`77a61b9`) and asked what the sending waits look like in my logs. They do step up with #141 (6 → 53-61 ms/s in my bisect runs), and the cause is the shape they suggested: `live_protect` calls `is_view` for every block it guards, and a faulted block is guarded again thousands of times a second. This PR remembers the blocks `is_view` accepted in a new `Guards::known_view` set. A re-guard of a known block skips the Windows query. The two ways a block can stop being title memory (`title_memory_unmapping`, `title_memory_freed`) clear the note, so a reused address is asked about again and #141's crash fix stays in force. Refused blocks were already counted in `LIVE_NOT_TITLE` and are never remembered — no switch, no fallback, no change to which blocks are guarded. ## Evidence Answer to the maintainer's question, from my earlier matched bisect (1 s stats windows): `31c20c7` had 8 sending waits/s, 6 ms/s and ~8k blocks guarded again/s; `77a61b9` (#141) had 14/s, 53 ms/s and ~13k/s; `d59b4f8` had 14/s, 61 ms/s and ~14k/s. `slot_reads at Execute` stayed ~7 ms per slow frame, so the pause is on the sending path, not descriptor resolution. Evidence: `/home/shlong/Documents/VKtory-capture/bisect-{old,current}/`, `/home/shlong/Documents/VKtory-capture/bisect{77,7c3209,1befc3}/`. A/B/B/A of this patch against main `da2c3b1` (same code as `d59b4f8` apart from a docs commit), RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, warm store, house save `rt3`: | Runs | Build | Mean fps | Sending waits ms/s | Frames >=50 ms | |---|---|---:|---:|---:| | A1/A2 | main | 27.15 / 26.93 | 45.1 / 51.5 | 183 / 177 | | B1/B2 | patched | 28.99 / 29.43 | 37.2 / 32.7 | 112 / 100 | 110 s per run with W/I/K/J at 20/45/70/95 s. Static (no keys), 90 s per run: main 28.51 / 27.68 fps, 50.8 / 48.0 ms/s waits; patched 29.21 / 29.18 fps, 42.4 / 37.6 ms/s. `LIVE_NOT_TITLE` stayed at 16 in every run — the same Wine stack blocks at `0x100000000`, so the filter still declines them. Validation-layer runs were not used for timing. Evidence: `/home/shlong/Documents/VKtory-capture/liveguard-{ab,static}-{A1,B1,B2,A2}/`. ## Checklist (docs/AGENTS.md) - [x] One topic; `docs/TASKS.md` not edited (rules 29/31) - [x] No fallback, constant, switch, queue, `unsafe` or translator output changed (rules 2/9b/33/35/36/27) - [x] Comments say what is true now (rule 3) - [x] No game content as evidence; only counters, fps and guard counts - [x] `cargo check -p victory-gpu --features diagnostics` and `cargo test -p victory-gpu --features diagnostics` pass; `tools/build.sh` exit 0 - [x] Windows-only tests in `watch/live.rs` extended to assert the note is made and cleared; they cannot execute on this Linux host
#141 made live_protect call is_view for every block it guards. That filter fixed
the #139 crash (Wine stacks at 0x100000000 were made read-only), but a block
that faults is guarded again in a later batch; in the boat/house walks the same
13-20k blocks/s were asked of VirtualQuery again and again. On #171 this showed
up as sending waits, not as slot reads.

Remember the blocks is_view accepted in Guards::known_view. A re-guard of a
known block skips the query; the two ways a block can stop being title memory
(title_memory_unmapping, title_memory_freed) clear the note, so a reused address
is asked about again and the crash fix stays in force. Refused blocks were
already counted in LIVE_NOT_TITLE and are never remembered.

A/B/B/A on RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, warm
store, house save rt3, 110 s per run, scripted camera walk:
- main:       27.15 / 26.93 fps, sending waits 45.1 / 51.5 ms/s, slow frames 183/177
- with patch: 28.99 / 29.43 fps, sending waits 37.2 / 32.7 ms/s, slow frames 112/100

Static (no keys), 90 s per run:
- main:       28.51 / 27.68 fps, sending waits 50.8 / 48.0 ms/s
- with patch: 29.21 / 29.18 fps, sending waits 42.4 / 37.6 ms/s

LIVE_NOT_TITLE stayed at 16 in every run (the same Wine stack blocks), so the
filter still declines them. One topic, no diagnostic left behind. Windows-only
unit tests in watch/live.rs are extended to assert the note is made and cleared;
they cannot be executed on this Linux host. Evidence:
/home/shlong/Documents/VKtory-capture/liveguard-{ab,static}-{A1,B1,B2,A2}/.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 12:34:29 +00:00
Author
Owner

@⁠TheRifai on GitHub · 2026-12-02 13:19 UTC · original

Additional A/B/B/A in the maintainer's scene (prison cell), since #171's isolation used that save. Same pair of builds as the PR evidence, RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, warm store, named save prison, 90 s per run, standing still:

Run Build Mean fps Sending waits ms/s Blocks guarded again/s LIVE_NOT_TITLE
A1 main 17.86 98.5 9,590 16
B1 patched 20.87 62.0 13,433 16
B2 patched 21.61 74.0 13,002 16
A2 main 17.77 93.8 11,650 16

So in the prison cell the memo gives about +3 to +4 fps and cuts the sending wait by roughly a quarter to a third; the refusal count stays at 16, the same Wine stack blocks. This is closer to the scene where the maintainer saw the drop (13.1/13.0 fps main, 21.6 without #141), and the patched arms land near their reverted-#141 rate while keeping #141's filter. Evidence: /home/shlong/Documents/VKtory-capture/liveguard-prison-{A1,B1,B2,A2}/.

**@⁠TheRifai** on GitHub · 2026-12-02 13:19 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7346706353) Additional A/B/B/A in the maintainer's scene (prison cell), since #171's isolation used that save. Same pair of builds as the PR evidence, RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, warm store, named save `prison`, 90 s per run, standing still: | Run | Build | Mean fps | Sending waits ms/s | Blocks guarded again/s | `LIVE_NOT_TITLE` | |---|---|---:|---:|---:|---:| | A1 | main | 17.86 | 98.5 | 9,590 | 16 | | B1 | patched | 20.87 | 62.0 | 13,433 | 16 | | B2 | patched | 21.61 | 74.0 | 13,002 | 16 | | A2 | main | 17.77 | 93.8 | 11,650 | 16 | So in the prison cell the memo gives about +3 to +4 fps and cuts the sending wait by roughly a quarter to a third; the refusal count stays at 16, the same Wine stack blocks. This is closer to the scene where the maintainer saw the drop (13.1/13.0 fps main, 21.6 without #141), and the patched arms land near their reverted-#141 rate while keeping #141's filter. Evidence: `/home/shlong/Documents/VKtory-capture/liveguard-prison-{A1,B1,B2,A2}/`.
Author
Owner

@⁠Flezzonkeys on GitHub · 2026-12-02 13:20 UTC · original

Thanks for the quick patch. I tested f1301e5 unmodified on the machine from #171 (RX 9070 XT, 9800X3D, Proton Experimental). It helps a little here, but most of the drop remains.

First 41 world seconds of each run (victory_gpu::host lines with at least 1000 draws/frame), same save, played by hand:

Build Avg fps Seconds < 15 fps sending waits per wait
08adddc (2 runs) 14.7 / 13.6 61% / 61% 227 / 235 ms/s 8.2 / 6.8 ms
this PR (1 run) 15.8 41% 160 ms/s 5.6 ms
08adddc minus #141 (1 run) 21.6 2% 7 ms/s 0.5 ms

Only victory.exe differs between these builds. The route was not scripted and the machine had several GB in zram swap.

My guess, not proven: streaming unmaps and remaps title memory so often here that the remembered blocks are cleared and asked again. I had tried a similar cache myself before, with the same small effect. The log of this run shows no refused blocks at all, while you see 16.

About the red CI: the new test calls known_view.contains(&(...)), but Blocks::contains takes a usize, so the lib test does not compile (E0308, 5 times). The code itself builds fine.

I can test another version.

**@⁠Flezzonkeys** on GitHub · 2026-12-02 13:20 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7346733480) Thanks for the quick patch. I tested f1301e5 unmodified on the machine from #171 (RX 9070 XT, 9800X3D, Proton Experimental). It helps a little here, but most of the drop remains. First 41 world seconds of each run (`victory_gpu::host` lines with at least 1000 draws/frame), same save, played by hand: | Build | Avg fps | Seconds < 15 fps | sending waits | per wait | |---|---:|---:|---:|---:| | 08adddc (2 runs) | 14.7 / 13.6 | 61% / 61% | 227 / 235 ms/s | 8.2 / 6.8 ms | | **this PR (1 run)** | 15.8 | 41% | 160 ms/s | 5.6 ms | | 08adddc minus #141 (1 run) | 21.6 | 2% | 7 ms/s | 0.5 ms | Only `victory.exe` differs between these builds. The route was not scripted and the machine had several GB in zram swap. My guess, not proven: streaming unmaps and remaps title memory so often here that the remembered blocks are cleared and asked again. I had tried a similar cache myself before, with the same small effect. The log of this run shows no refused blocks at all, while you see 16. About the red CI: the new test calls `known_view.contains(&(...))`, but `Blocks::contains` takes a `usize`, so the lib test does not compile (E0308, 5 times). The code itself builds fine. I can test another version.
Author
Owner

@⁠TheRifai on GitHub · 2026-12-02 13:27 UTC · original

You were right on both counts, and I don't have a version that fixes the remaining drop.

The red CI was my test bug: Blocks::contains takes usize, I passed &usize five times. I pushed a corrected branch liveguard-known-view-v2 (de28376) with only that test fix; no force-push, this PR stays as-is. Please use the v2 branch if you try again.

On the effect size: your result is consistent with the remap-churn explanation. In my runs the memo saved 25-35% of sending waits and 1.5-3.5 fps, with 16 refusals per run; on your machine there are no refused blocks at all and remaps clear the note often, so there is little left to save. The memo only removes a repeated query — it cannot help the case where the blocks are genuinely new to the filter each time, and I have no further change to propose here without a profile of what is_view is being asked about after each unmap. The plain revert would recover more, but it reopens #139, so I am not proposing it.

**@⁠TheRifai** on GitHub · 2026-12-02 13:27 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7346906013) You were right on both counts, and I don't have a version that fixes the remaining drop. The red CI was my test bug: `Blocks::contains` takes `usize`, I passed `&usize` five times. I pushed a corrected branch `liveguard-known-view-v2` (`de28376`) with only that test fix; no force-push, this PR stays as-is. Please use the v2 branch if you try again. On the effect size: your result is consistent with the remap-churn explanation. In my runs the memo saved 25-35% of sending waits and 1.5-3.5 fps, with 16 refusals per run; on your machine there are no refused blocks at all and remaps clear the note often, so there is little left to save. The memo only removes a repeated query — it cannot help the case where the blocks are genuinely new to the filter each time, and I have no further change to propose here without a profile of what `is_view` is being asked about after each unmap. The plain revert would recover more, but it reopens #139, so I am not proposing it.
Author
Owner

@⁠Flezzonkeys on GitHub · 2026-12-02 14:12 UTC · original

Thanks for checking. I compared v2 with f1301e5: only the five test lines differ, so I won't run it again. The CI here stays red until that fix is on this PR's branch.

One more data point on what is asked after an unmap. Before your PR I tried two versions of this on d59b4f8 plus a few local commits:

Build sending waits per wait
#141 reverted 8 ms/s 0.7 ms
memo, cleared on every remap (same idea as this PR) 105 ms/s 4.8 ms
memo + the runtime's own records (umem, registered views, GPU-only blocks) asked before is_view 74 ms/s 4.5 ms

One run each, played by hand, with several GB in zram swap, so only the rough size counts.

The third version should answer a freshly remapped view without VirtualQuery, yet most of the wait stayed. So either many blocks are in none of those records, or the time is not mainly in the query. I did not count which. A counter for the VirtualQuery calls from live_title_block, plus the time spent in it, would tell the two apart.

**@⁠Flezzonkeys** on GitHub · 2026-12-02 14:12 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7348152376) Thanks for checking. I compared v2 with f1301e5: only the five test lines differ, so I won't run it again. The CI here stays red until that fix is on this PR's branch. One more data point on what is asked after an unmap. Before your PR I tried two versions of this on d59b4f8 plus a few local commits: | Build | sending waits | per wait | |---|---:|---:| | #141 reverted | 8 ms/s | 0.7 ms | | memo, cleared on every remap (same idea as this PR) | 105 ms/s | 4.8 ms | | memo + the runtime's own records (umem, registered views, GPU-only blocks) asked before `is_view` | 74 ms/s | 4.5 ms | One run each, played by hand, with several GB in zram swap, so only the rough size counts. The third version should answer a freshly remapped view without `VirtualQuery`, yet most of the wait stayed. So either many blocks are in none of those records, or the time is not mainly in the query. I did not count which. A counter for the `VirtualQuery` calls from `live_title_block`, plus the time spent in it, would tell the two apart.
Author
Owner

@⁠TheRifai on GitHub · 2026-12-02 14:40 UTC · original

Follow-up to your counter request. PR #216 (GPU: count is_view calls and time in live guards) adds the count and ns around live_title_block's is_view call, plus a stats line. One 100 s house run on main 963df8e with GE-Proton11-16: is_view 830 calls/s median, 80.6 ms/s median (128.8 mean), ~100 us per call; sending waits 28.3 ms/s median (74.4 mean). So the query path is larger than the wait it was blamed for, and ~100 us per call is far more than one VirtualQuery — the hole walk in is_view or umem-lock contention is the place to look, which fits your third version not helping much. No behaviour change; the #141 crash fix is untouched. Numbers and checklist are on #216; no plain revert proposed.

**@⁠TheRifai** on GitHub · 2026-12-02 14:40 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7348935737) Follow-up to your counter request. PR #216 (`GPU: count is_view calls and time in live guards`) adds the count and ns around `live_title_block`'s `is_view` call, plus a stats line. One 100 s house run on main `963df8e` with GE-Proton11-16: `is_view` 830 calls/s median, 80.6 ms/s median (128.8 mean), ~100 us per call; sending waits 28.3 ms/s median (74.4 mean). So the query path is larger than the wait it was blamed for, and ~100 us per call is far more than one `VirtualQuery` — the hole walk in `is_view` or umem-lock contention is the place to look, which fits your third version not helping much. No behaviour change; the #141 crash fix is untouched. Numbers and checklist are on #216; no plain revert proposed.
Author
Owner

@⁠TheRifai on GitHub · 2026-12-02 14:40 UTC · original

Correction: the counter PR is #219, not #216 (I misnumbered it in the previous comment).

**@⁠TheRifai** on GitHub · 2026-12-02 14:40 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7348941892) Correction: the counter PR is #219, not #216 (I misnumbered it in the previous comment).
Author
Owner

@⁠Flezzonkeys on GitHub · 2026-12-02 14:51 UTC · original

Thanks for the counter, that helps a lot. I think ~100 us can be a single VirtualQuery: Wine's get_vprot_range_size walks the page bytes to the end of the region, with virtual_mutex held. The comment in watch::guard describes the same cost (0.6 ms for a 174 MB heap).

The title's GPU-only view space (0x801, 24 GiB) stays one untouched placeholder (show_pool), so a query in it walks everything behind the address. I timed this with a small test program (Proton Experimental 11.0, 9800X3D, 24 GiB placeholder, 2000 calls each, no game running):

Address VirtualQuery
start 213-224 us
+12 GiB 110 us
+23 GiB 10 us
a 64 KiB commit 0.5 us

VirtualProtect on one block there takes 0.5 us, which would fit why the path was cheap before #141.

Not proven: that the blocks asked about are in that space. Counting calls by RegionSize in #219 would show it.

If so, a possible fix is to ask the runtime's own record first. title_placeholder_reserved already keeps these reservations (TOLD), but only with VICTORY_HOLES_TOLD=1. Kept always and checked before is_view, it would answer both mapped blocks and holes there without a query. The Wine stacks from #139 are outside those reservations, so they would still be refused.

**@⁠Flezzonkeys** on GitHub · 2026-12-02 14:51 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7349268932) Thanks for the counter, that helps a lot. I think ~100 us can be a single `VirtualQuery`: Wine's `get_vprot_range_size` walks the page bytes to the end of the region, with `virtual_mutex` held. The comment in `watch::guard` describes the same cost (0.6 ms for a 174 MB heap). The title's GPU-only view space (0x801, 24 GiB) stays one untouched placeholder (`show_pool`), so a query in it walks everything behind the address. I timed this with a small test program (Proton Experimental 11.0, 9800X3D, 24 GiB placeholder, 2000 calls each, no game running): | Address | `VirtualQuery` | |---|---:| | start | 213-224 us | | +12 GiB | 110 us | | +23 GiB | 10 us | | a 64 KiB commit | 0.5 us | `VirtualProtect` on one block there takes 0.5 us, which would fit why the path was cheap before #141. Not proven: that the blocks asked about are in that space. Counting calls by `RegionSize` in #219 would show it. If so, a possible fix is to ask the runtime's own record first. `title_placeholder_reserved` already keeps these reservations (`TOLD`), but only with `VICTORY_HOLES_TOLD=1`. Kept always and checked before `is_view`, it would answer both mapped blocks and holes there without a query. The Wine stacks from #139 are outside those reservations, so they would still be refused.
github-bot closed this pull request 2026-12-02 15:45:47 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 15:41 UTC · original

Thanks. This and #219 found the cause, and Flezzonkeys' trace on this PR finished the job: is_view is a VirtualQuery, which under Wine walks the region's page bytes with virtual_mutex held (~100 µs per call). The memo here only kept accepted blocks, so every refused block was queried again on every guard, and those are the slow ones.

I fixed it on our side in a different way (github.com/vktory6/VKtory@3aea0e4): the guards now keep the record of what the runtime gave the title (allocations, commits, placeholder reservations, until a whole release) and answer from that and umem's ranges with no Windows call. Anything else is asked once, and a refusal is remembered until the title is given memory there. Wine's stacks stay unguarded as #141 made them; its test is extended for both cases.

Measured on an RX 9070 XT, boat start, 141 world seconds each, A B B A: | run | build | fps |
|---|---|---|
| a1 | main fbf3e9d | 13.54 |
| b1 | fix | 25.01 |
| b2 | fix | 26.38 |
| a2 | main fbf3e9d | 14.18 |

"sending waits" in the stats line went from up to 174 ms a second to under 1 ms. No device loss, no refused-block lines in either build..

So I'm closing this one as superseded. The credit is in the commit message.

**@⁠vktory6** on GitHub · 2026-12-02 15:41 UTC · [original](https://github.com/vktory6/VKtory/pull/208#issuecomment-7350764298) Thanks. This and #219 found the cause, and Flezzonkeys' trace on this PR finished the job: `is_view` is a `VirtualQuery`, which under Wine walks the region's page bytes with `virtual_mutex` held (~100 µs per call). The memo here only kept accepted blocks, so every refused block was queried again on every guard, and those are the slow ones. I fixed it on our side in a different way (https://github.com/vktory6/VKtory/commit/3aea0e4): the guards now keep the record of what the runtime gave the title (allocations, commits, placeholder reservations, until a whole release) and answer from that and umem's ranges with no Windows call. Anything else is asked once, and a refusal is remembered until the title is given memory there. Wine's stacks stay unguarded as #141 made them; its test is extended for both cases. Measured on an RX 9070 XT, boat start, 141 world seconds each, A B B A: | run | build | fps | |---|---|---| | a1 | main fbf3e9d | 13.54 | | b1 | fix | 25.01 | | b2 | fix | 26.38 | | a2 | main fbf3e9d | 14.18 | "sending waits" in the stats line went from up to 174 ms a second to under 1 ms. No device loss, no refused-block lines in either build.. So I'm closing this one as superseded. The credit is in the commit message.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.