watch: interval-skip absent placeholders, coalesce VirtualProtect runs, O(dirty) re-arm (#1238) #1276

Closed
Vladimir-Human wants to merge 1 commit from upstream-pr/1279 into main
Vladimir-Human commented 2026-11-26 09:52:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-26T09:52:11Z.


Summary

Optimizes watch::guard and view-memory protection/unprotection in victory-gpu (crates/victory-gpu/src/watch.rs, crates/victory-gpu/src/inplace.rs) to eliminate per-block guard walks, repeated VirtualQuery probing of unmapped placeholder blocks, and per-block VirtualProtect syscalls reported in #1238.

What changed

  1. Coalesced interval tracking & fast absent/placeholder skip (watch.rs):

    • Replaced per-block BTreeSet<usize> / BTreeMap<usize, u64> sets in Guards (protected, clean, absent, aliased, viewed, holes, verified) with disjoint coalesced half-open interval containers (BlockSet and VerifiedMap) plus placeholder_absent: BlockSet.
    • guard_locked checks g.clean.covers(first, last) in O(log K) with zero allocations and jumps across contiguous clean and absent intervals instead of iterating first..=last block-by-block.
    • Uncommitted spans confirmed via NtQueryVirtualMemory(MemoryRegionInformationEx) to lie in MEM_RESERVE_PLACEHOLDER reservations are tracked in placeholder_absent and skipped with zero VirtualProtect and zero VirtualQuery syscalls until title_memory_remapped / title_memory_committed clears them (VICTORY_ABSENT_ONCE=0 opts out; ordinary non-placeholder MEM_RESERVE / SEC_RESERVE reservations still probe via VirtualQuery per region; guard_at honors its explicit keep parameter; look_at_holes clears placeholder_absent/absent if a hole is silently filled).
    • Added word-level Bits::set_range / Bits::clear_range (clamped to BITS_MAX_BLOCK, skipping unallocated 4 GiB pieces).
  2. Contiguous run coalescing, O(dirty) re-arm, & single lock hold (watch.rs, inplace.rs):

    • writes_as uses try_guard_if_known to verify known-view membership and run guard_locked under a single GUARDS lock hold (with post-install() re-check so there is no TOCTOU window).
    • guard_locked marks already-protected blocks (e.g. alias-guarded views) clean in O(dirty) without re-calling VirtualProtect, and coalesces adjacent unprotected dirty blocks into contiguous runs.
    • protect_here, protect_alias_run, and unprotect_run_os (open / open_here) issue a single coalesced VirtualProtect per contiguous run, falling back to VirtualQuery-guided OS VM region stepping on VAD boundaries or uncommitted gaps (1 syscall per committed VAD, 0 failing VirtualProtect calls on uncommitted holes, protected ∩ absent == ∅ enforced by construction in note_protected, checked_mul(BLOCK) overflow guards).
    • Added lock-batched inplace::aliases_in_range and inplace::aliases_for_blocks (preserving lock order MAPPING -> JOURNAL -> GUARDS -> VIEWS), a zero-allocation single-block unaliased fast path in open for VEH write faults, and strict PUBLISHED clearing for both primary and alias blocks before any PAGE_READWRITE transition.
  3. Unit, stress, & deterministic benchmark tests (watch.rs):

    • block_set_and_verified_map_interval_invariants
    • sparse_placeholder_gaps_are_skipped_without_probing_or_protecting
    • contiguous_runs_coalesce_guard_and_unguard_syscalls
    • aliased_views_coalesce_protect_open_and_o_dirty_rearm
    • ordinary_reserve_is_not_placeholder_and_silent_commit_is_detected
    • protected_and_absent_sets_remain_disjoint_after_protect
    • unprotect_run_os_skips_uncommitted_gap_without_per_block_failures
    • concurrent_writers_and_guard_readers_stay_coherent
    • benchmark_guard_coalesce_and_absent_skip

Measurements (--release, live Windows placeholders & aliased views)

Workload Metric Baseline After Reduction / Speedup
Sparse placeholders (192 blocks, 128 split 64 KiB holes, 60 submissions, 4 dirty/sub) VirtualProtect calls 493 125 3.9x fewer
Sparse placeholders (same) VirtualQuery calls 7,808 132 (0 steady-state) 59.2x fewer
Sparse placeholders (same) Wall-clock time 2.977 ms 0.504 ms 5.9x faster
Dual-aliased contiguous view (64 blocks x 2 views, 30 open+guard cycles) VirtualProtect calls 5,855 122 48.0x fewer
Dual-aliased contiguous view (same) Wall-clock time 3.293 ms 1.844 ms 1.8x faster

Verification

  • cargo test -p victory-gpu (parallel): 221 passed; 0 failed; 6 ignored
  • cargo test -p victory-gpu --features diagnostics -- watch: 29 passed; 0 failed; 1 ignored
  • cargo test --release -p victory-gpu -- watch::tests::benchmark_guard_coalesce_and_absent_skip --exact --nocapture: PASS
  • cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated (default & --features diagnostics): 0 warnings/errors in modified files (only 3 pre-existing AtomicU32::fetch_update deprecation warnings in untouched object.rs on rustc 1.100.0)
  • cargo run -p xtask -- policy --staged: asset policy: 2 files ok

Related: #1238

<!-- greyfinch-sync:fxceless/victory-fork:issue:5507766657 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T09:52:11Z. --- ## Summary Optimizes `watch::guard` and view-memory protection/unprotection in `victory-gpu` (`crates/victory-gpu/src/watch.rs`, `crates/victory-gpu/src/inplace.rs`) to eliminate per-block guard walks, repeated `VirtualQuery` probing of unmapped placeholder blocks, and per-block `VirtualProtect` syscalls reported in #1238. ### What changed 1. **Coalesced interval tracking & fast absent/placeholder skip (`watch.rs`)**: - Replaced per-block `BTreeSet<usize>` / `BTreeMap<usize, u64>` sets in `Guards` (`protected`, `clean`, `absent`, `aliased`, `viewed`, `holes`, `verified`) with disjoint coalesced half-open interval containers (`BlockSet` and `VerifiedMap`) plus `placeholder_absent: BlockSet`. - `guard_locked` checks `g.clean.covers(first, last)` in `O(log K)` with zero allocations and jumps across contiguous `clean` and `absent` intervals instead of iterating `first..=last` block-by-block. - Uncommitted spans confirmed via `NtQueryVirtualMemory(MemoryRegionInformationEx)` to lie in `MEM_RESERVE_PLACEHOLDER` reservations are tracked in `placeholder_absent` and skipped with zero `VirtualProtect` and zero `VirtualQuery` syscalls until `title_memory_remapped` / `title_memory_committed` clears them (`VICTORY_ABSENT_ONCE=0` opts out; ordinary non-placeholder `MEM_RESERVE` / `SEC_RESERVE` reservations still probe via `VirtualQuery` per region; `guard_at` honors its explicit `keep` parameter; `look_at_holes` clears `placeholder_absent`/`absent` if a hole is silently filled). - Added word-level `Bits::set_range` / `Bits::clear_range` (clamped to `BITS_MAX_BLOCK`, skipping unallocated 4 GiB pieces). 2. **Contiguous run coalescing, O(dirty) re-arm, & single lock hold (`watch.rs`, `inplace.rs`)**: - `writes_as` uses `try_guard_if_known` to verify known-view membership and run `guard_locked` under a single `GUARDS` lock hold (with post-`install()` re-check so there is no TOCTOU window). - `guard_locked` marks already-`protected` blocks (e.g. alias-guarded views) `clean` in `O(dirty)` without re-calling `VirtualProtect`, and coalesces adjacent unprotected dirty blocks into contiguous runs. - `protect_here`, `protect_alias_run`, and `unprotect_run_os` (`open` / `open_here`) issue a single coalesced `VirtualProtect` per contiguous run, falling back to `VirtualQuery`-guided OS VM region stepping on VAD boundaries or uncommitted gaps (1 syscall per committed VAD, 0 failing `VirtualProtect` calls on uncommitted holes, `protected ∩ absent == ∅` enforced by construction in `note_protected`, `checked_mul(BLOCK)` overflow guards). - Added lock-batched `inplace::aliases_in_range` and `inplace::aliases_for_blocks` (preserving lock order `MAPPING -> JOURNAL -> GUARDS -> VIEWS`), a zero-allocation single-block unaliased fast path in `open` for VEH write faults, and strict `PUBLISHED` clearing for both primary and alias blocks before any `PAGE_READWRITE` transition. 3. **Unit, stress, & deterministic benchmark tests (`watch.rs`)**: - `block_set_and_verified_map_interval_invariants` - `sparse_placeholder_gaps_are_skipped_without_probing_or_protecting` - `contiguous_runs_coalesce_guard_and_unguard_syscalls` - `aliased_views_coalesce_protect_open_and_o_dirty_rearm` - `ordinary_reserve_is_not_placeholder_and_silent_commit_is_detected` - `protected_and_absent_sets_remain_disjoint_after_protect` - `unprotect_run_os_skips_uncommitted_gap_without_per_block_failures` - `concurrent_writers_and_guard_readers_stay_coherent` - `benchmark_guard_coalesce_and_absent_skip` ### Measurements (`--release`, live Windows placeholders & aliased views) | Workload | Metric | Baseline | After | Reduction / Speedup | |---|---|---:|---:|---:| | Sparse placeholders (192 blocks, 128 split 64 KiB holes, 60 submissions, 4 dirty/sub) | `VirtualProtect` calls | 493 | 125 | **3.9x fewer** | | Sparse placeholders (same) | `VirtualQuery` calls | 7,808 | 132 (0 steady-state) | **59.2x fewer** | | Sparse placeholders (same) | Wall-clock time | 2.977 ms | 0.504 ms | **5.9x faster** | | Dual-aliased contiguous view (64 blocks x 2 views, 30 open+guard cycles) | `VirtualProtect` calls | 5,855 | 122 | **48.0x fewer** | | Dual-aliased contiguous view (same) | Wall-clock time | 3.293 ms | 1.844 ms | **1.8x faster** | ### Verification - `cargo test -p victory-gpu` (parallel): **221 passed; 0 failed; 6 ignored** - `cargo test -p victory-gpu --features diagnostics -- watch`: **29 passed; 0 failed; 1 ignored** - `cargo test --release -p victory-gpu -- watch::tests::benchmark_guard_coalesce_and_absent_skip --exact --nocapture`: **PASS** - `cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated` (default & `--features diagnostics`): **0 warnings/errors** in modified files (only 3 pre-existing `AtomicU32::fetch_update` deprecation warnings in untouched `object.rs` on `rustc 1.100.0`) - `cargo run -p xtask -- policy --staged`: **asset policy: 2 files ok** Related: #1238
Garu667 commented 2026-11-26 10:06:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T09:56:00Z.


Nice work on the syscall counts. Do you have in-game numbers too? For instance the frame log's "a submission's preparing by part" line (write-watch share) or the usual frame time, before/after, in a world scene. On an RTX 3080 the write-watch part is ~11.8 ms of ~79 ms the submit worker spends preparing per frame (boat mission), so it would be a real gain there. Happy to run an A/B here if that helps.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7188671506 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7188671506). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T09:56:00Z. --- Nice work on the syscall counts. Do you have in-game numbers too? For instance the frame log's "a submission's preparing by part" line (write-watch share) or the usual frame time, before/after, in a world scene. On an RTX 3080 the write-watch part is ~11.8 ms of ~79 ms the submit worker spends preparing per frame (boat mission), so it would be a real gain there. Happy to run an A/B here if that helps.
HLVM04 commented 2026-11-26 10:06:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HLVM04 on 2026-11-26T09:56:14Z.


In-game data point for the placeholder skip, from a separate local change of ours (not this PR's code): native Windows, RTX 5070 Ti, Series S profile, fork stack in the first gameplay scene. Absent blocks inside placeholder reservations (which the runtime already reports) are no longer queried with VirtualQuery every frame; that cost went from 9.3 to 0.7 ms a frame. We did not count VirtualProtect calls or measure the alias-view coalescing part, and it is a few runs on one scene, so it says nothing about this PR's other changes.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7188677668 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7188677668). Originally posted by [HLVM04](https://github.com/HLVM04) on 2026-11-26T09:56:14Z. --- In-game data point for the placeholder skip, from a separate local change of ours (not this PR's code): native Windows, RTX 5070 Ti, Series S profile, fork stack in the first gameplay scene. Absent blocks inside placeholder reservations (which the runtime already reports) are no longer queried with `VirtualQuery` every frame; that cost went from 9.3 to 0.7 ms a frame. We did not count `VirtualProtect` calls or measure the alias-view coalescing part, and it is a few runs on one scene, so it says nothing about this PR's other changes.
Vladimir-Human commented 2026-11-26 11:05:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-26T11:00:16Z.


Rebased cleanly onto main (06702fe -> 4bc254c), preserving C::WatchKnownUs / C::WatchFailedUs diagnostics in writes_as, adapting unchanged_known to O(log K) BlockSet::covers, and keeping inplace::views_between / inplace::pages_of for host.rs. Re-verified cargo test -p victory-gpu -- --test-threads=1 (222 passed, 0 failed, 6 ignored), --features diagnostics -- watch (29 passed, 0 failed), clippy (0 warnings in touched files), and xtask policy (220 files ok).

@Garu667 Thanks for the offer! We do not have local title assets here, so we cannot run in-game world-scene captures ourselves—our numbers above are from the live-Win32 synthetic benchmark (benchmark_guard_coalesce_and_absent_skip). An RTX 3080 A/B on 06702fe vs this PR looking at "a submission's preparing by part" (write-watch share) and the new WatchKnownUs / WatchFailedUs / GuardUs counters would be very helpful.

@HLVM04 Thanks for sharing that native Windows 9.3 -> 0.7 ms/frame data point on placeholder skipping. This PR takes the same NtQueryVirtualMemory(MemoryRegionInformationEx) MEM_RESERVE_PLACEHOLDER skip inside Guards' coalesced BlockSet intervals (placeholder_absent, plus PUBLISHED bitset support under VICTORY_LIGHT_REFRESH=1 + VICTORY_ABSENT_MS=told, while keeping ordinary MEM_RESERVE/SEC_RESERVE probing intact and VICTORY_ABSENT_ONCE=0 as opt-out), and pairs it with single-lock try_guard_if_known, O(dirty) re-arm for already-protected alias blocks, and VirtualQuery-guided coalesced VirtualProtect across primary and peer alias views.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7190129973 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7190129973). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T11:00:16Z. --- Rebased cleanly onto `main` (`06702fe` -> `4bc254c`), preserving `C::WatchKnownUs` / `C::WatchFailedUs` diagnostics in `writes_as`, adapting `unchanged_known` to `O(log K)` `BlockSet::covers`, and keeping `inplace::views_between` / `inplace::pages_of` for `host.rs`. Re-verified `cargo test -p victory-gpu -- --test-threads=1` (222 passed, 0 failed, 6 ignored), `--features diagnostics -- watch` (29 passed, 0 failed), `clippy` (0 warnings in touched files), and `xtask policy` (220 files ok). @Garu667 Thanks for the offer! We do not have local title assets here, so we cannot run in-game world-scene captures ourselves—our numbers above are from the live-Win32 synthetic benchmark (`benchmark_guard_coalesce_and_absent_skip`). An RTX 3080 A/B on `06702fe` vs this PR looking at `"a submission's preparing by part"` (write-watch share) and the new `WatchKnownUs` / `WatchFailedUs` / `GuardUs` counters would be very helpful. @HLVM04 Thanks for sharing that native Windows `9.3 -> 0.7 ms/frame` data point on placeholder skipping. This PR takes the same `NtQueryVirtualMemory(MemoryRegionInformationEx)` `MEM_RESERVE_PLACEHOLDER` skip inside `Guards`' coalesced `BlockSet` intervals (`placeholder_absent`, plus `PUBLISHED` bitset support under `VICTORY_LIGHT_REFRESH=1` + `VICTORY_ABSENT_MS=told`, while keeping ordinary `MEM_RESERVE`/`SEC_RESERVE` probing intact and `VICTORY_ABSENT_ONCE=0` as opt-out), and pairs it with single-lock `try_guard_if_known`, `O(dirty)` re-arm for already-protected alias blocks, and `VirtualQuery`-guided coalesced `VirtualProtect` across primary and peer alias views.
Garu667 commented 2026-11-26 12:07:19 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T11:05:32Z.


Will do: we have a fresh baseline on 06702fe running right now (RTX 3080, boat mission, standing), and will run this PR on the same base next, with the preparing-by-part line and the WatchKnownUs / WatchFailedUs / GuardUs counters. Numbers here within the hour.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7190253159 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7190253159). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T11:05:32Z. --- Will do: we have a fresh baseline on `06702fe` running right now (RTX 3080, boat mission, standing), and will run this PR on the same base next, with the preparing-by-part line and the `WatchKnownUs` / `WatchFailedUs` / `GuardUs` counters. Numbers here within the hour.
Garu667 commented 2026-11-26 12:07:20 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T11:38:11Z.


A/B as promised. RTX 3080 10 GB, Windows 11, diagnostics build, Series X profile, first boat mission, character standing ~3 min, README set + CARD_SYNC_BATCH=1 CARD_HASH_WIDE=1. One launch each, same checkpoint:

06702fe (run 65) 06702fe + this PR (run 67)
world fps, median 9.1 10.0
usual frame (last 4 readings) 80 / 99 / 101 / 102 ms 86 / 86 / 88 / 86 ms
submit worker at work 87.7 ms 69.7 ms
guards (frame log) 10.1 ms 3.4 ms
asks not made, known guarded view memory 1,647 in 11.93 ms 1,669 in 2.81 ms
preparing: refreshes (the flush) 14.1 ms 7.9 ms
preparing: write-watch + look under flights (settles included) 12.8 ms 26.1 ms
submit thread waiting for the card in settles 6.4 ms 14.8 ms

So the guard and known-view work drops ~3-4x in game too, and the submit worker does ~18 ms less work a frame. Part of that time now shows up as waiting for the card (the write-watch line includes settles), which is expected once the worker gets ahead. Net ~+10 % fps here. Picture unchanged (distinct colours per capture 86-88k vs 88-90k, same scene), no device loss. Merged onto 06702fe with no conflict.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7190978678 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7190978678). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T11:38:11Z. --- A/B as promised. RTX 3080 10 GB, Windows 11, diagnostics build, Series X profile, first boat mission, character standing ~3 min, README set + `CARD_SYNC_BATCH=1 CARD_HASH_WIDE=1`. One launch each, same checkpoint: | | `06702fe` (run 65) | `06702fe` + this PR (run 67) | |---|---|---| | world fps, median | 9.1 | **10.0** | | usual frame (last 4 readings) | 80 / 99 / 101 / 102 ms | 86 / 86 / 88 / 86 ms | | submit worker at work | 87.7 ms | **69.7 ms** | | guards (frame log) | 10.1 ms | **3.4 ms** | | asks not made, known guarded view memory | 1,647 in 11.93 ms | 1,669 in **2.81 ms** | | preparing: refreshes (the flush) | 14.1 ms | 7.9 ms | | preparing: write-watch + look under flights (settles included) | 12.8 ms | 26.1 ms | | submit thread waiting for the card in settles | 6.4 ms | 14.8 ms | So the guard and known-view work drops ~3-4x in game too, and the submit worker does ~18 ms less work a frame. Part of that time now shows up as waiting for the card (the write-watch line includes settles), which is expected once the worker gets ahead. Net ~+10 % fps here. Picture unchanged (distinct colours per capture 86-88k vs 88-90k, same scene), no device loss. Merged onto `06702fe` with no conflict.
Garu667 commented 2026-11-26 15:04:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T14:43:44Z.


Important follow-up to my A/B above: the gain holds standing, but while driving the boat this PR loses the device. RTX 3080, same checkpoint: 58de9bf alone ran 9 min, driving most of it, with no loss; 58de9bf + this PR lost the device (DRED "hung") after ~40 s standing and ~15 s of driving; two earlier driving runs with it in a combined build were lost the same way (3 of 3 with it, 0 of 1 without). Standing runs never lost it, so it seems tied to the heavy remapping and streaming while moving (those frames show 100k-1M page faults and hundreds of remaps each). Happy to rerun with diagnostics, e.g. a switch that turns parts of it off.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7195236345 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7195236345). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T14:43:44Z. --- Important follow-up to my A/B above: the gain holds standing, but while **driving** the boat this PR loses the device. RTX 3080, same checkpoint: `58de9bf` alone ran 9 min, driving most of it, with no loss; `58de9bf` + this PR lost the device (DRED "hung") after ~40 s standing and **~15 s of driving**; two earlier driving runs with it in a combined build were lost the same way (3 of 3 with it, 0 of 1 without). Standing runs never lost it, so it seems tied to the heavy remapping and streaming while moving (those frames show 100k-1M page faults and hundreds of remaps each). Happy to rerun with diagnostics, e.g. a switch that turns parts of it off.
Vladimir-Human commented 2026-11-26 16:36:57 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-26T16:36:57Z.


@Garu667 Thank you for the detailed follow-up and driving repro. Rebased onto main (e4245f3 -> 3287060) with the following fixes and diagnostic bisect switches:

Changes

  1. skip_placeholders is now OFF by default: Previously absent_mode_raw() == 0 enabled an infinite TTL on placeholder_absent, skipping VirtualQuery probes on placeholder holes permanently unless title_memory_remapped / title_memory_committed fired. guard_policy() now keeps skip_placeholders OFF by default—enabled only with VICTORY_PLACEHOLDER_SKIP=1, or with VICTORY_ABSENT_ONCE=1 + VICTORY_ABSENT_MS=told when VICTORY_PLACEHOLDER_SKIP is unset—while keeping O(1)-per-OS-region uncommitted_end() region skipping active.
  2. Concurrent remap PAGE_READWRITE restoration in title_memory_remapped: Our new multi-threaded remap + write-fault stress test caught a concrete race where guard() protects newly mapped pages between MapViewOfFile3 and xmem::map's title_memory_remapped(), which previously evicted those runs from g.protected without calling VirtualProtect(..., PAGE_READWRITE) and left orphaned PAGE_READONLY pages (0xc0000005 on write). title_memory_remapped now restores PAGE_READWRITE (unprotect_run_os_with) when evicting guarded runs.
  3. !alias_batch lock-free clear ordering & VEH OnceLock pre-warming: open_with(..., alias_batch=false) now clears PUBLISHED + g.aliased across all aliases before making primary blocks writable, and install() pre-warms watch_coalesce() and watch_alias_batch() alongside light_kept().

Zero-overhead OnceLock<bool> bisect switches

If anything still reproduces under heavy driving/streaming on 3287060, these switches isolate each subsystem independently:

  • VICTORY_PLACEHOLDER_SKIP=0|1 (default 0, unless VICTORY_ABSENT_ONCE=1 + VICTORY_ABSENT_MS=told)
  • VICTORY_WATCH_COALESCE=0|1 (default 1; 0 falls back to per-block VirtualProtect in protect_here, protect_alias_run, unprotect_run_os)
  • VICTORY_WATCH_ALIAS_BATCH=0|1 (default 1; 0 falls back to per-block views_between + pages_of)
  • VICTORY_WATCH_SINGLE_LOCK=0|1 (default 1; 0 disables try_guard_if_known single-lock fast path)

Verification (on e4245f3 -> 3287060)

  • cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings -A deprecated (default & --features diagnostics): 0 warnings in watch.rs / inplace.rs (only 3 pre-existing deprecated warnings in object.rs).
  • VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --lib -- --test-threads=1:
    • default features: 235 passed; 0 failed; 6 ignored
    • --features diagnostics: 254 passed; 0 failed; 7 ignored
    • Includes new tests: default_placeholder_redetects_silent_map_without_remapped_notification, remap_notification_restores_writable_after_concurrent_protect, bisect_switches_parse_and_disable_paths_correctly, and concurrent_remap_and_write_fault_stress.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7197876402 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7197876402). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T16:36:57Z. --- @Garu667 Thank you for the detailed follow-up and driving repro. Rebased onto `main` (`e4245f3` -> `3287060`) with the following fixes and diagnostic bisect switches: ### Changes 1. **`skip_placeholders` is now OFF by default:** Previously `absent_mode_raw() == 0` enabled an infinite TTL on `placeholder_absent`, skipping `VirtualQuery` probes on placeholder holes permanently unless `title_memory_remapped` / `title_memory_committed` fired. `guard_policy()` now keeps `skip_placeholders` OFF by default—enabled only with `VICTORY_PLACEHOLDER_SKIP=1`, or with `VICTORY_ABSENT_ONCE=1` + `VICTORY_ABSENT_MS=told` when `VICTORY_PLACEHOLDER_SKIP` is unset—while keeping `O(1)`-per-OS-region `uncommitted_end()` region skipping active. 2. **Concurrent remap `PAGE_READWRITE` restoration in `title_memory_remapped`:** Our new multi-threaded remap + write-fault stress test caught a concrete race where `guard()` protects newly mapped pages between `MapViewOfFile3` and `xmem::map`'s `title_memory_remapped()`, which previously evicted those runs from `g.protected` without calling `VirtualProtect(..., PAGE_READWRITE)` and left orphaned `PAGE_READONLY` pages (`0xc0000005` on write). `title_memory_remapped` now restores `PAGE_READWRITE` (`unprotect_run_os_with`) when evicting guarded runs. 3. **`!alias_batch` lock-free clear ordering & VEH `OnceLock` pre-warming:** `open_with(..., alias_batch=false)` now clears `PUBLISHED` + `g.aliased` across all aliases before making primary blocks writable, and `install()` pre-warms `watch_coalesce()` and `watch_alias_batch()` alongside `light_kept()`. ### Zero-overhead `OnceLock<bool>` bisect switches If anything still reproduces under heavy driving/streaming on `3287060`, these switches isolate each subsystem independently: - `VICTORY_PLACEHOLDER_SKIP=0|1` (default `0`, unless `VICTORY_ABSENT_ONCE=1` + `VICTORY_ABSENT_MS=told`) - `VICTORY_WATCH_COALESCE=0|1` (default `1`; `0` falls back to per-block `VirtualProtect` in `protect_here`, `protect_alias_run`, `unprotect_run_os`) - `VICTORY_WATCH_ALIAS_BATCH=0|1` (default `1`; `0` falls back to per-block `views_between` + `pages_of`) - `VICTORY_WATCH_SINGLE_LOCK=0|1` (default `1`; `0` disables `try_guard_if_known` single-lock fast path) ### Verification (on `e4245f3` -> `3287060`) - `cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings -A deprecated` (default & `--features diagnostics`): 0 warnings in `watch.rs` / `inplace.rs` (only 3 pre-existing `deprecated` warnings in `object.rs`). - `VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --lib -- --test-threads=1`: - default features: `235 passed; 0 failed; 6 ignored` - `--features diagnostics`: `254 passed; 0 failed; 7 ignored` - Includes new tests: `default_placeholder_redetects_silent_map_without_remapped_notification`, `remap_notification_restores_writable_after_concurrent_protect`, `bisect_switches_parse_and_disable_paths_correctly`, and `concurrent_remap_and_write_fault_stress`.
KyleS98 commented 2026-11-26 23:07:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T23:07:47Z.


An in-game data point for the placeholder part, from a much smaller change than this PR (so it says nothing about the interval containers or the coalesced VirtualProtect runs).

What I measured first. RTX 3090 Ti, Ryzen 9 9950X3D, Windows 11, Series S profile, prologue cell, on #994's head + #911 + #868. The sampling profiler had the submitting thread 8.5 ms a frame in VirtualQuery directly under watch::guard. VICTORY_VIEW_KNOWN=1 did not move it, so it is not is_view: it is uncommitted_end, asked once per run of absent blocks at every asking, because an ordinary reservation can be committed with no word to the guards.

The small version: the runtime tells the guards which reservations are placeholders (from XMemVirtualAlloc, where it makes them), and guard leaves a block noted absent inside one as it is. Only xmem::map makes memory appear there, and it already calls title_memory_remapped, which forgets the blocks' absence. Ordinary reservations are asked as before. About 90 lines: 3524388 (VICTORY_ABSENT_ONCE=0 turns it off).

before with it
VirtualQuery under watch::guard, submitting thread 8.5 ms a frame not in the profile
"copies" on the frame line 25.5 ms 15.8 ms
frame 64.5 ms 61 ms

Picture the same in the cell, 0 exceptions, one 6-minute run each way. That matches the 9.3 → 0.7 ms @HLVM04 reported above for the same idea. If the maintainers would rather have the narrow change than wait for the larger one, I can open it as a PR against main; it has not been built or run on main yet.

Numbers and text only. AI-assisted (Claude Code, Claude Fable 5.2).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7205279166 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7205279166). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-26T23:07:47Z. --- An in-game data point for the placeholder part, from a much smaller change than this PR (so it says nothing about the interval containers or the coalesced `VirtualProtect` runs). **What I measured first.** RTX 3090 Ti, Ryzen 9 9950X3D, Windows 11, Series S profile, prologue cell, on #994's head + #911 + #868. The sampling profiler had the submitting thread 8.5 ms a frame in `VirtualQuery` directly under `watch::guard`. `VICTORY_VIEW_KNOWN=1` did not move it, so it is not `is_view`: it is `uncommitted_end`, asked once per run of absent blocks at every asking, because an ordinary reservation can be committed with no word to the guards. **The small version:** the runtime tells the guards which reservations are placeholders (from `XMemVirtualAlloc`, where it makes them), and `guard` leaves a block noted absent inside one as it is. Only `xmem::map` makes memory appear there, and it already calls `title_memory_remapped`, which forgets the blocks' absence. Ordinary reservations are asked as before. About 90 lines: [3524388](https://github.com/KyleS98/VIctory-Neo/commit/3524388) (`VICTORY_ABSENT_ONCE=0` turns it off). | | before | with it | |---|---|---| | `VirtualQuery` under `watch::guard`, submitting thread | 8.5 ms a frame | not in the profile | | "copies" on the frame line | 25.5 ms | 15.8 ms | | frame | 64.5 ms | 61 ms | Picture the same in the cell, 0 exceptions, one 6-minute run each way. That matches the 9.3 → 0.7 ms @HLVM04 reported above for the same idea. If the maintainers would rather have the narrow change than wait for the larger one, I can open it as a PR against `main`; it has not been built or run on `main` yet. Numbers and text only. AI-assisted (Claude Code, Claude Fable 5.2).
KyleS98 commented 2026-11-26 23:30:39 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T23:30:39Z.


A correction to my comment above: I offered to open the narrow change as a PR against main, but main already has it. I had measured on an older base (#994's head) and had not looked at current main before writing.

main carries VICTORY_ABSENT_ONCE=1 (commit 44bff61, off by default): a block found uncommitted is not asked about again for VICTORY_ABSENT_MS (100 ms), and with VICTORY_ABSENT_MS=told not until the runtime tells of it, which is the rule my change applies to placeholders. So there is nothing for me to send; the numbers above (8.5 ms a frame of VirtualQuery under watch::guard gone, 64.5 → 61 ms a frame on an RTX 3090 Ti) can be read as a data point for that switch's told form on another card, measured on another tree.

AI-assisted (Claude Code, Claude Fable 5.2).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7205600730 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7205600730). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-26T23:30:39Z. --- A correction to my comment above: I offered to open the narrow change as a PR against `main`, but `main` already has it. I had measured on an older base (#994's head) and had not looked at current `main` before writing. `main` carries `VICTORY_ABSENT_ONCE=1` (commit `44bff61`, off by default): a block found uncommitted is not asked about again for `VICTORY_ABSENT_MS` (100 ms), and with `VICTORY_ABSENT_MS=told` not until the runtime tells of it, which is the rule my change applies to placeholders. So there is nothing for me to send; the numbers above (8.5 ms a frame of `VirtualQuery` under `watch::guard` gone, 64.5 → 61 ms a frame on an RTX 3090 Ti) can be read as a data point for that switch's `told` form on another card, measured on another tree. AI-assisted (Claude Code, Claude Fable 5.2).
Vladimir-Human commented 2026-11-27 07:16:27 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-27T07:16:27Z.


Thanks @Garu667 for the RTX 3080 driving repro and @KyleS98 for pointing out the overlap with main. Before rebasing onto 9a9091d, I audited 4bc254c vs 3287060 against current main:

  1. Already in main: 44bff61 (VICTORY_ABSENT_ONCE=1 VICTORY_ABSENT_MS=told + VICTORY_LIGHT_REFRESH=1) already provides the placeholder VirtualQuery skip, and b1d777a already added the single-block open_here fast path on VEH write faults.
  2. Audit findings (4bc254c vs 3287060):
    • 4bc254c (the build tested while driving) had skip_placeholders ON by default and evicted g.protected in title_memory_remapped without restoring PAGE_READWRITE, which can leave pages stuck PAGE_READONLY outside g.protected when guard() races between xmem::map's commit() and title_memory_remapped().
    • 3287060 fixed both of those and added bisect switches, but still has two heavy-remap lock-hold issues: note_absent_span (watch.rs:2469) calls NtQueryVirtualMemory under GUARDS even when skip_placeholders is off, and title_memory_remapped (watch.rs:3030) calls unprotect_run_os_with under physical() + MAPPING.write() + GUARDS even on xmem::unmap immediately before UnmapViewOfFile2.
    • Without local title assets to reproduce the driving DRED hang directly, I cannot prove hardware-free that 3287060 resolves it.
  3. Next step: Holding off on rebasing/force-pushing #1279 onto 9a9091d for now. Happy to either (a) cut a narrowed, opt-in branch stacked cleanly on 44bff61 keeping only BlockSet / coalesced VirtualProtect / O(dirty) re-arm with per-stage kill-switches and both remap-lock fixes if testers still want to bisect driving stability, or (b) close #1279 if 44bff61 + b1d777a already cover what is needed on main.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7212312751 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7212312751). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T07:16:27Z. --- Thanks `@Garu667` for the RTX 3080 driving repro and `@KyleS98` for pointing out the overlap with `main`. Before rebasing onto `9a9091d`, I audited `4bc254c` vs `3287060` against current `main`: 1. **Already in `main`:** `44bff61` (`VICTORY_ABSENT_ONCE=1 VICTORY_ABSENT_MS=told` + `VICTORY_LIGHT_REFRESH=1`) already provides the placeholder `VirtualQuery` skip, and `b1d777a` already added the single-block `open_here` fast path on VEH write faults. 2. **Audit findings (`4bc254c` vs `3287060`):** - `4bc254c` (the build tested while driving) had `skip_placeholders` ON by default and evicted `g.protected` in `title_memory_remapped` without restoring `PAGE_READWRITE`, which can leave pages stuck `PAGE_READONLY` outside `g.protected` when `guard()` races between `xmem::map`'s `commit()` and `title_memory_remapped()`. - `3287060` fixed both of those and added bisect switches, but still has two heavy-remap lock-hold issues: `note_absent_span` (`watch.rs:2469`) calls `NtQueryVirtualMemory` under `GUARDS` even when `skip_placeholders` is off, and `title_memory_remapped` (`watch.rs:3030`) calls `unprotect_run_os_with` under `physical() + MAPPING.write() + GUARDS` even on `xmem::unmap` immediately before `UnmapViewOfFile2`. - Without local title assets to reproduce the driving DRED hang directly, I cannot prove hardware-free that `3287060` resolves it. 3. **Next step:** Holding off on rebasing/force-pushing `#1279` onto `9a9091d` for now. Happy to either (a) cut a narrowed, opt-in branch stacked cleanly on `44bff61` keeping only `BlockSet` / coalesced `VirtualProtect` / `O(dirty)` re-arm with per-stage kill-switches and both remap-lock fixes if testers still want to bisect driving stability, or (b) close `#1279` if `44bff61` + `b1d777a` already cover what is needed on `main`.
Vladimir-Human commented 2026-11-27 12:42:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-27T12:42:36Z.


Rebased onto latest main (9a9091d) in c290c4c:

  • Resolved the open_here merge conflict cleanly, keeping b1d777a's single-block fast path (first + 1 == last) ahead of BlockSet::take_range + coalesced VirtualProtect, and keeping bcc5421's VICTORY_INPLACE_CONSTANTS intact in inplace.rs.
  • Gated note_absent_span's NtQueryVirtualMemory placeholder query loop behind skip_placeholders so the default path incurs zero placeholder probes under GUARDS (while keeping unprotect_run_os_with under GUARDS in title_memory_remapped).
  • Verified (VICTORY_D3D12_DEBUG=1, --test-threads=1): clippy clean on touched files (default & --features diagnostics); HW default watch:: 33/33 (1 ignored) + inplace:: 8/8; HW --features diagnostics watch:: 33/33 (1 ignored) + inplace:: 8/8; WARP watch:: 33/33 (1 ignored) + inplace:: 8/8.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7218579641 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7218579641). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T12:42:36Z. --- Rebased onto latest `main` (`9a9091d`) in `c290c4c`: - Resolved the `open_here` merge conflict cleanly, keeping `b1d777a`'s single-block fast path (`first + 1 == last`) ahead of `BlockSet::take_range` + coalesced `VirtualProtect`, and keeping `bcc5421`'s `VICTORY_INPLACE_CONSTANTS` intact in `inplace.rs`. - Gated `note_absent_span`'s `NtQueryVirtualMemory` placeholder query loop behind `skip_placeholders` so the default path incurs zero placeholder probes under `GUARDS` (while keeping `unprotect_run_os_with` under `GUARDS` in `title_memory_remapped`). - Verified (`VICTORY_D3D12_DEBUG=1`, `--test-threads=1`): `clippy` clean on touched files (default & `--features diagnostics`); HW default `watch::` 33/33 (1 ignored) + `inplace::` 8/8; HW `--features diagnostics` `watch::` 33/33 (1 ignored) + `inplace::` 8/8; WARP `watch::` 33/33 (1 ignored) + `inplace::` 8/8.
Vladimir-Human commented 2026-11-27 20:57:27 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-27T20:57:27Z.


Closing as superseded following 5dbf5ce2 (rebase onto VIctory-NVIDIA 959dcaf): watch.rs on main now includes coalesced multi-block VirtualProtect (protect_here), uncommitted_end, and known_holes() placeholder-hole skipping cleanly. Happy to open a fresh small PR on 2eade68c+ if any remaining isolated watch.rs optimization is still needed.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7227997224 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1279#issuecomment-7227997224). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T20:57:27Z. --- Closing as superseded following `5dbf5ce2` (rebase onto `VIctory-NVIDIA` `959dcaf`): `watch.rs` on `main` now includes coalesced multi-block `VirtualProtect` (`protect_here`), `uncommitted_end`, and `known_holes()` placeholder-hole skipping cleanly. Happy to open a fresh small PR on `2eade68c+` if any remaining isolated `watch.rs` optimization is still needed.

Pull request closed

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
fxceless/victory-fork!1276
No description provided.