watch: interval-skip absent placeholders, coalesce VirtualProtect runs, O(dirty) re-arm (#1238) #1279
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!1279
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1279"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Vladimir-Human on GitHub · 2026-11-26 09:52 UTC · original
Vladimir-Human:perf/watch-guard-coalesce-dirty→main· +2678 −371 · 2 files · 1 commits · openSummary
Optimizes
watch::guardand view-memory protection/unprotection invictory-gpu(crates/victory-gpu/src/watch.rs,crates/victory-gpu/src/inplace.rs) to eliminate per-block guard walks, repeatedVirtualQueryprobing of unmapped placeholder blocks, and per-blockVirtualProtectsyscalls reported in #1238.What changed
Coalesced interval tracking & fast absent/placeholder skip (
watch.rs):BTreeSet<usize>/BTreeMap<usize, u64>sets inGuards(protected,clean,absent,aliased,viewed,holes,verified) with disjoint coalesced half-open interval containers (BlockSetandVerifiedMap) plusplaceholder_absent: BlockSet.guard_lockedchecksg.clean.covers(first, last)inO(log K)with zero allocations and jumps across contiguouscleanandabsentintervals instead of iteratingfirst..=lastblock-by-block.NtQueryVirtualMemory(MemoryRegionInformationEx)to lie inMEM_RESERVE_PLACEHOLDERreservations are tracked inplaceholder_absentand skipped with zeroVirtualProtectand zeroVirtualQuerysyscalls untiltitle_memory_remapped/title_memory_committedclears them (VICTORY_ABSENT_ONCE=0opts out; ordinary non-placeholderMEM_RESERVE/SEC_RESERVEreservations still probe viaVirtualQueryper region;guard_athonors its explicitkeepparameter;look_at_holesclearsplaceholder_absent/absentif a hole is silently filled).Bits::set_range/Bits::clear_range(clamped toBITS_MAX_BLOCK, skipping unallocated 4 GiB pieces).Contiguous run coalescing, O(dirty) re-arm, & single lock hold (
watch.rs,inplace.rs):writes_asusestry_guard_if_knownto verify known-view membership and runguard_lockedunder a singleGUARDSlock hold (with post-install()re-check so there is no TOCTOU window).guard_lockedmarks already-protectedblocks (e.g. alias-guarded views)cleaninO(dirty)without re-callingVirtualProtect, and coalesces adjacent unprotected dirty blocks into contiguous runs.protect_here,protect_alias_run, andunprotect_run_os(open/open_here) issue a single coalescedVirtualProtectper contiguous run, falling back toVirtualQuery-guided OS VM region stepping on VAD boundaries or uncommitted gaps (1 syscall per committed VAD, 0 failingVirtualProtectcalls on uncommitted holes,protected ∩ absent == ∅enforced by construction innote_protected,checked_mul(BLOCK)overflow guards).inplace::aliases_in_rangeandinplace::aliases_for_blocks(preserving lock orderMAPPING -> JOURNAL -> GUARDS -> VIEWS), a zero-allocation single-block unaliased fast path inopenfor VEH write faults, and strictPUBLISHEDclearing for both primary and alias blocks before anyPAGE_READWRITEtransition.Unit, stress, & deterministic benchmark tests (
watch.rs):block_set_and_verified_map_interval_invariantssparse_placeholder_gaps_are_skipped_without_probing_or_protectingcontiguous_runs_coalesce_guard_and_unguard_syscallsaliased_views_coalesce_protect_open_and_o_dirty_rearmordinary_reserve_is_not_placeholder_and_silent_commit_is_detectedprotected_and_absent_sets_remain_disjoint_after_protectunprotect_run_os_skips_uncommitted_gap_without_per_block_failuresconcurrent_writers_and_guard_readers_stay_coherentbenchmark_guard_coalesce_and_absent_skipMeasurements (
--release, live Windows placeholders & aliased views)VirtualProtectcallsVirtualQuerycallsVirtualProtectcallsVerification
cargo test -p victory-gpu(parallel): 221 passed; 0 failed; 6 ignoredcargo test -p victory-gpu --features diagnostics -- watch: 29 passed; 0 failed; 1 ignoredcargo test --release -p victory-gpu -- watch::tests::benchmark_guard_coalesce_and_absent_skip --exact --nocapture: PASScargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated(default &--features diagnostics): 0 warnings/errors in modified files (only 3 pre-existingAtomicU32::fetch_updatedeprecation warnings in untouchedobject.rsonrustc 1.100.0)cargo run -p xtask -- policy --staged: asset policy: 2 files okRelated: #1238
@Garu667 on GitHub · 2026-11-26 09:56 UTC · original
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 on GitHub · 2026-11-26 09:56 UTC · original
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
VirtualQueryevery frame; that cost went from 9.3 to 0.7 ms a frame. We did not countVirtualProtectcalls 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 on GitHub · 2026-11-26 11:00 UTC · original
Rebased cleanly onto
main(06702fe->4bc254c), preservingC::WatchKnownUs/C::WatchFailedUsdiagnostics inwrites_as, adaptingunchanged_knowntoO(log K)BlockSet::covers, and keepinginplace::views_between/inplace::pages_offorhost.rs. Re-verifiedcargo 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), andxtask 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 on06702fevs this PR looking at"a submission's preparing by part"(write-watch share) and the newWatchKnownUs/WatchFailedUs/GuardUscounters would be very helpful.@HLVM04 Thanks for sharing that native Windows
9.3 -> 0.7 ms/framedata point on placeholder skipping. This PR takes the sameNtQueryVirtualMemory(MemoryRegionInformationEx)MEM_RESERVE_PLACEHOLDERskip insideGuards' coalescedBlockSetintervals (placeholder_absent, plusPUBLISHEDbitset support underVICTORY_LIGHT_REFRESH=1+VICTORY_ABSENT_MS=told, while keeping ordinaryMEM_RESERVE/SEC_RESERVEprobing intact andVICTORY_ABSENT_ONCE=0as opt-out), and pairs it with single-locktry_guard_if_known,O(dirty)re-arm for already-protected alias blocks, andVirtualQuery-guided coalescedVirtualProtectacross primary and peer alias views.@Garu667 on GitHub · 2026-11-26 11:05 UTC · original
Will do: we have a fresh baseline on
06702ferunning right now (RTX 3080, boat mission, standing), and will run this PR on the same base next, with the preparing-by-part line and theWatchKnownUs/WatchFailedUs/GuardUscounters. Numbers here within the hour.@Garu667 on GitHub · 2026-11-26 11:38 UTC · original
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)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
06702fewith no conflict.@Garu667 on GitHub · 2026-11-26 14:43 UTC · original
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:
58de9bfalone 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.4bc254cdb2to328706091b@Vladimir-Human on GitHub · 2026-11-26 16:36 UTC · original
@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
skip_placeholdersis now OFF by default: Previouslyabsent_mode_raw() == 0enabled an infinite TTL onplaceholder_absent, skippingVirtualQueryprobes on placeholder holes permanently unlesstitle_memory_remapped/title_memory_committedfired.guard_policy()now keepsskip_placeholdersOFF by default—enabled only withVICTORY_PLACEHOLDER_SKIP=1, or withVICTORY_ABSENT_ONCE=1+VICTORY_ABSENT_MS=toldwhenVICTORY_PLACEHOLDER_SKIPis unset—while keepingO(1)-per-OS-regionuncommitted_end()region skipping active.PAGE_READWRITErestoration intitle_memory_remapped: Our new multi-threaded remap + write-fault stress test caught a concrete race whereguard()protects newly mapped pages betweenMapViewOfFile3andxmem::map'stitle_memory_remapped(), which previously evicted those runs fromg.protectedwithout callingVirtualProtect(..., PAGE_READWRITE)and left orphanedPAGE_READONLYpages (0xc0000005on write).title_memory_remappednow restoresPAGE_READWRITE(unprotect_run_os_with) when evicting guarded runs.!alias_batchlock-free clear ordering & VEHOnceLockpre-warming:open_with(..., alias_batch=false)now clearsPUBLISHED+g.aliasedacross all aliases before making primary blocks writable, andinstall()pre-warmswatch_coalesce()andwatch_alias_batch()alongsidelight_kept().Zero-overhead
OnceLock<bool>bisect switchesIf anything still reproduces under heavy driving/streaming on
3287060, these switches isolate each subsystem independently:VICTORY_PLACEHOLDER_SKIP=0|1(default0, unlessVICTORY_ABSENT_ONCE=1+VICTORY_ABSENT_MS=told)VICTORY_WATCH_COALESCE=0|1(default1;0falls back to per-blockVirtualProtectinprotect_here,protect_alias_run,unprotect_run_os)VICTORY_WATCH_ALIAS_BATCH=0|1(default1;0falls back to per-blockviews_between+pages_of)VICTORY_WATCH_SINGLE_LOCK=0|1(default1;0disablestry_guard_if_knownsingle-lock fast path)Verification (on
e4245f3->3287060)cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings -A deprecated(default &--features diagnostics): 0 warnings inwatch.rs/inplace.rs(only 3 pre-existingdeprecatedwarnings inobject.rs).VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --lib -- --test-threads=1:235 passed; 0 failed; 6 ignored--features diagnostics:254 passed; 0 failed; 7 ignoreddefault_placeholder_redetects_silent_map_without_remapped_notification,remap_notification_restores_writable_after_concurrent_protect,bisect_switches_parse_and_disable_paths_correctly, andconcurrent_remap_and_write_fault_stress.@KyleS98 on GitHub · 2026-11-26 23:07 UTC · original
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
VirtualProtectruns).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
VirtualQuerydirectly underwatch::guard.VICTORY_VIEW_KNOWN=1did not move it, so it is notis_view: it isuncommitted_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), andguardleaves a block noted absent inside one as it is. Onlyxmem::mapmakes memory appear there, and it already callstitle_memory_remapped, which forgets the blocks' absence. Ordinary reservations are asked as before. About 90 lines: 3524388 (VICTORY_ABSENT_ONCE=0turns it off).VirtualQueryunderwatch::guard, submitting threadPicture 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 onmainyet.Numbers and text only. AI-assisted (Claude Code, Claude Fable 5.2).
@KyleS98 on GitHub · 2026-11-26 23:30 UTC · original
A correction to my comment above: I offered to open the narrow change as a PR against
main, butmainalready has it. I had measured on an older base (#994's head) and had not looked at currentmainbefore writing.maincarriesVICTORY_ABSENT_ONCE=1(commit44bff61, off by default): a block found uncommitted is not asked about again forVICTORY_ABSENT_MS(100 ms), and withVICTORY_ABSENT_MS=toldnot 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 ofVirtualQueryunderwatch::guardgone, 64.5 → 61 ms a frame on an RTX 3090 Ti) can be read as a data point for that switch'stoldform on another card, measured on another tree.AI-assisted (Claude Code, Claude Fable 5.2).
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.