Write watch: out-of-GUARDS 64-stripe VirtualProtect (VICTORY_GUARD_SHARDED, off) #434
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/434"
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?
Imported from readmet3xt-lab/foxhound. Originally posted by Pototoooo on 2026-12-02T09:35:22Z.
Summary
Ports out-of-
GUARDSstripedVirtualProtectguarding from RFC #413 (patches 01, 05 and 06, MIT-0) onto foxhound'swatch.rs, behind an opt-in switch (VICTORY_GUARD_SHARDED=1, off by default):SRWLOCKstripes (VP_STRIPE, 4 MiB / 64 blocks per stripe) strictly outsideGUARDSin the lock hierarchy (VP_STRIPE[i < j]->GUARDS).VpStripes(u64)carries only an 8-byte bitmask on the stack (zero heap allocation, safe in the vectored exception handler).on_write's write-fault handling into a#[inline(never)]helper so VEH entry keeps a minimal stack footprint for non-write exceptions (e.g. stack growth guard pages).VICTORY_GUARD_SHARDED=1,guard_lockeddropsGUARDSbefore callingsoft_runs,VirtualProtect(PAGE_READONLY),VirtualQuery, andelsewhere, holding only the target 4 MiB stripe(s) inprotect_here_stripedandcover_stripedand takingGUARDSonly for brief metadata checks and commits.ARMINGbitmap set underGUARDSbefore Phase 2VirtualProtectand cleared only after committing intog.protectedor completingreopen_striped_block(sotitle_memory_written'sVICTORY_LOCK_TRIMfast path,writing,views_mapped,open_page,put_beside, and the VEH handler never observe a half-armed block).Guards::epochs, 4096 slots) bumped on everyopen(includingopen_one_view),unguard,settle,views_mapped,title_memory_splitting,title_memory_unmapping,title_memory_changed, andtitle_memory_freed, preventing ABA races between out-of-lockVirtualProtect/elsewherephases and Phase-3 commit /cover_stripedclean marking.g.aliased.contains(ob) && !inplace::pages_of(ob * BLOCK).is_empty()) underVP_STRIPE[ob]+GUARDSbefore aliasVirtualProtectincover_striped, serializing againsttitle_memory_unmappingso an unmapped view whose VA was reused by the allocator can never be made read-only.reopen_striped_blockunderVP_STRIPE(outsideGUARDS) when a concurrent open, fault, partial-page open, or remap invalidates a Phase-3 commit, preventing orphaned read-only pages.VICTORY_GUARD_PAGES(PARTLY/close_pages/forget_pages),VICTORY_FAULT_UNLOCKED(OPENING/settleclearingPROTECTEDunconditionally),VICTORY_SOFT_VIEWS, andVICTORY_GUARD_BATCH(guard_ahead).VICTORY_GUARD_SHARDEDis unset (the default),guard_sharded()isfalse,lock_vp_range/lock_vp_allare no-ops, andguard_lockedruns the existing path unchanged.Verification
watch::guard_striped_tests:striped_protect_reopens_block_when_open_races_phase2(forced interleaving via pre-VirtualProtecthook confirmingARMINGis set, stale epoch is rejected in Phase 3,PAGE_READWRITEis restored viaVirtualQuery+ direct write, andPROTECTED/ARMINGare cleared)striped_guard_tracks_writes_and_aliases(two mapped views of one section guarded with striped mode, alias write detection,title_memory_written, and unmapping cleanup)watch::tests pass under:VICTORY_GUARD_SHARDED=0(default)VICTORY_GUARD_SHARDED=1VICTORY_GUARD_SHARDED=1 VICTORY_GUARD_PAGES=1VICTORY_GUARD_SHARDED=1:no_write_to_views_is_lost_with_batched_guards: 850+ consecutive runs passed (0 failures, 0 deadlocks, 0 stack overflows)no_write_is_lost_when_faults_open_one_page: 50/50 consecutive runs passedcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test -p victory-gpu -p victory-hle -p victory-core -p victory-pipeline -p victory-loader --locked --lib: all passingAfter procotos-art's RFC #413 patches 01, 05 and 06 (MIT-0), adapted to foxhound's
PARTLY/guard_ahead/VICTORY_LOCK_TRIMwatch code.Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-02T16:51:02Z.
Impressive scope — the stripe lock design moving VirtualProtect outside GUARDS should significantly reduce contention on the guard path. The epoch-based skip in bury is a nice touch.
Interaction with our work: Our #478 batches contiguous blocks in
unguard()into single VirtualProtect calls. Both PRs touchunguard()— ours reduces syscall count, yours reduces lock hold time. They're complementary but will need merge reconciliation. Our journal sharding (16 RwLock shards in JOURNAL) operates on a completely different lock and doesn't conflict with the VP_STRIPE lock order.Questions for the author:
reopen_striped_blockrecovery path — is this the same race that #457 fixes, or a different window?Imported from readmet3xt-lab/foxhound. Originally posted by tillo88 on 2026-12-02T21:05:55Z.
Replay-bench measurement: no measurable difference on v0.8.3.3
Measured: PR head
c0ab945merged onto release v0.8.3.3 (same code as main7dbcdcb), withVICTORY_GUARD_SHARDED=1, 2 measured runs (after a warm-up run that is not counted), against 3 runs of v0.8.3.3 without the PR, same route (~6.5 min).Mean fps: release 36.38, PR 35.95 (-1.2%). That is below the 2-3% we treat as a real change, so: no measurable difference on this route. Only 3 release runs so far, so the release's own spread is not established yet.
Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost).
Note: two earlier release runs the same evening, with identical switches, were much slower for most of the route (6-9 fps average); the cause is not known yet and they are left out of the comparison above. No PR run fell into that state.
Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default
play-foxhound.ps1settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap.Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
Imported from readmet3xt-lab/foxhound. Originally posted by Pototoooo on 2026-12-03T03:09:36Z.
Thanks for the review and the notes on #478 / #457, @GValdezN!
VirtualProtect: Batching is not restricted to a single stripe.protect_here_striped()callslock_vp_range(from, to)up front for the entire contiguous run[from, to), computes the 64-bit stripe bitmask (4 MiB per stripe), and acquires all spannedVP_STRIPE[idx]locks in strict ascending index order (i < j). So a batchedVirtualProtectin Phase 2 holds every stripe lock covering that range. As for reconciling with #478, this PR only addsg.bump_epoch(block)insideunguard(), so your contiguousVirtualProtectbatching there should compose cleanly.reopen_striped_blockvs #457: On theVICTORY_GUARD_SHARDED=1path, yes — it covers the sameprotectvsopen_unlocked(VICTORY_FAULT_UNLOCKED=1) race window as #457, plus the wider windows opened by releasingGUARDSduring Phase 2 (such as concurrentopen_page/PARTLY,settle(), or epoch-bumping opens/remaps). If Phase 3 (commit_striped_block) detects any of those underGUARDS, it rejects commit andreopen_striped_block()restoresPAGE_READWRITEand clearsPROTECTEDandARMINGwhile still holding the stripe lock(s). The defaultVICTORY_GUARD_SHARDED=0path (protect_here/protect_alias/open_unlocked) is untouched here, so #457 remains complementary for the default path (and for not pushing toOPENEDwhenopen_unlocked'sVirtualProtectfails).@tillo88 Thanks for running the replay bench and confirming zero crashes on v0.8.3.3! That's very useful data — on this route/CPU,
GUARDScontention duringVirtualProtectdoesn't look like the primary bottleneck, and the conservativelock_vp_all()currently taken onopen()paths (becauseopen()can also unguard aliases at arbitrary addresses) adds a small fixed cost under low contention. Good confirmation that keepingVICTORY_GUARD_SHARDEDopt-in (off by default) is the right call unless we narrow the non-aliasedopen()locking or see a workload whereGUARDSwait time dominates.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.