GPU: opt-in hot-block pinning in watch::guard (VICTORY_WATCH_PIN, addresses #1238) #1360

Open
github-bot wants to merge 1 commit from github-bot/gh-1360 into main AGit
Owner

@⁠RustPolaris on GitHub · 2026-11-26 18:10 UTC · original
RustPolaris:pr/watch-hot-block-pin → main · +225 −8 · 1 files · 1 commits · open

Summary

Implements opt-in hot-block pinning in watch::guard (addresses #1238).

When a title repeatedly writes to the same non-aliased mapped view blocks every frame (e.g. dynamic constant/instance/ring buffers), watch::guard previously re-armed PAGE_READONLY on every check only for the next CPU write to immediately fault through the VEH and re-open PAGE_READWRITE.

With VICTORY_WATCH_PIN=<N> (0 / off by default):

  • Tracks consecutive opens/faults (hot_streak) per non-aliased block that did not survive clean across a check.
  • Once a block faults N consecutive times without surviving clean, it is pinned (pinned) with a lease of VICTORY_WATCH_PIN_LEASE checks (default 32, clamped 1..=1024).
  • While pinned, guard_at reports the block dirty without calling VirtualProtect(..., PAGE_READONLY) and leaves it PAGE_READWRITE, avoiding both the re-arm syscall and the next VEH write fault.
  • When the lease reaches 0, the block is unpinned and re-probed once with PAGE_READONLY; if writes have stopped, it survives clean and clears its hot_streak.

Safety invariants

  • Off by default (VICTORY_WATCH_PIN=0).
  • Aliased blocks are never pinned: open_here skips streak/pin updates whenever aliases.contains_key(&block).
  • Remap/unmap cleanup: title_memory_remapped, clear_for_test, and drop_all clear pinned and hot_streak alongside protected/clean.
  • Known-view accounting: known_view and guard_at's known check include g.pinned.contains_key(&first) so pinned blocks remain recognized as view memory.
  • No allocation inside VEH: pin_config() is eagerly initialized in install() before installing the vectored exception handler.

Verification

  • Added unit test watch::tests::hot_block_pinning_skips_reprotect_and_cools_down covering threshold promotion, lease countdown without re-protecting, lease-expiry re-probe, cooldown back to clean, and remap cleanup.
  • cargo test -p victory-gpu --lib -- --test-threads=1 --skip depth_bounds_pipeline_loads_and_filters_draws: 223 passed, 0 failed.
  • cargo clippy -p victory-gpu --lib -- -D warnings and cargo clippy -p victory-gpu --lib --features diagnostics -- -D warnings: 0 warnings.
  • Tested live in world frames on Windows 10 (RTX 3060 Ti) with VICTORY_WATCH_PIN=4: logged 3,723–78,495 skipped VirtualProtect re-arms across runs (6–10 active pinned blocks at steady state), zero crashes or corruption.

Developed with AI assistance (Antigravity).

**@⁠RustPolaris** on GitHub · 2026-11-26 18:10 UTC · [original](https://github.com/fxceless/victory-fork/pull/1360) `RustPolaris:pr/watch-hot-block-pin` → `main` · +225 −8 · 1 files · 1 commits · open ## Summary Implements opt-in hot-block pinning in `watch::guard` (addresses #1238). When a title repeatedly writes to the same non-aliased mapped view blocks every frame (e.g. dynamic constant/instance/ring buffers), `watch::guard` previously re-armed `PAGE_READONLY` on every check only for the next CPU write to immediately fault through the VEH and re-open `PAGE_READWRITE`. With `VICTORY_WATCH_PIN=<N>` (`0` / off by default): - Tracks consecutive opens/faults (`hot_streak`) per non-aliased block that did not survive clean across a check. - Once a block faults `N` consecutive times without surviving clean, it is pinned (`pinned`) with a lease of `VICTORY_WATCH_PIN_LEASE` checks (default `32`, clamped `1..=1024`). - While pinned, `guard_at` reports the block dirty without calling `VirtualProtect(..., PAGE_READONLY)` and leaves it `PAGE_READWRITE`, avoiding both the re-arm syscall and the next VEH write fault. - When the lease reaches `0`, the block is unpinned and re-probed once with `PAGE_READONLY`; if writes have stopped, it survives clean and clears its `hot_streak`. ## Safety invariants - **Off by default** (`VICTORY_WATCH_PIN=0`). - **Aliased blocks are never pinned**: `open_here` skips streak/pin updates whenever `aliases.contains_key(&block)`. - **Remap/unmap cleanup**: `title_memory_remapped`, `clear_for_test`, and `drop_all` clear `pinned` and `hot_streak` alongside `protected`/`clean`. - **Known-view accounting**: `known_view` and `guard_at`'s `known` check include `g.pinned.contains_key(&first)` so pinned blocks remain recognized as view memory. - **No allocation inside VEH**: `pin_config()` is eagerly initialized in `install()` before installing the vectored exception handler. ## Verification - Added unit test `watch::tests::hot_block_pinning_skips_reprotect_and_cools_down` covering threshold promotion, lease countdown without re-protecting, lease-expiry re-probe, cooldown back to clean, and remap cleanup. - `cargo test -p victory-gpu --lib -- --test-threads=1 --skip depth_bounds_pipeline_loads_and_filters_draws`: 223 passed, 0 failed. - `cargo clippy -p victory-gpu --lib -- -D warnings` and `cargo clippy -p victory-gpu --lib --features diagnostics -- -D warnings`: 0 warnings. - Tested live in world frames on Windows 10 (RTX 3060 Ti) with `VICTORY_WATCH_PIN=4`: logged `3,723`–`78,495` skipped `VirtualProtect` re-arms across runs (`6`–`10` active pinned blocks at steady state), zero crashes or corruption. *Developed with AI assistance (Antigravity).*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:15:45 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1360/head:github-bot/gh-1360'
git switch 'github-bot/gh-1360'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1360'
git switch 'github-bot/gh-1360'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1360'
git switch 'github-bot/gh-1360'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1360'
git switch 'main'
git merge --squash 'github-bot/gh-1360'
git switch 'main'
git merge --ff-only 'github-bot/gh-1360'
git switch 'main'
git merge 'github-bot/gh-1360'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.