Repository navigation
Conversation
…atch Bits/publish
Reduce GUARDS mutex contention during concurrent refresh workers and
title write faults by moving VirtualProtect (both primary block runs and
aliased views) outside the GUARDS mutex, and batch Bits / PUBLISHED
updates per 64-block word (VICTORY_WATCH_UNLOCKED_PROTECT=0 disables).
- Add PROTECT_GATE (RwLock) and PROTECTING bitset (strict lock order:
MAPPING -> Asking -> PROTECT_GATE -> GUARDS -> OPENED) so guard_with_pub
/ protect_unlocked run VirtualProtect, elsewhere, and uncommitted_end
under shared read access while mutators (unmap/free/remap/split/open)
take exclusive write access and fault handlers spin briefly on
wait_protecting.
- Pre-mark PROTECTING/PROTECTED/g.protected before releasing GUARDS,
protect primary runs via protect_unlocked, then protect aliased views
outside GUARDS with RAII ClearProtectingSlice and full all_others
re-verification before inserting into g.clean.
- Add word-batched Bits::{set_word, clear_word, set_all},
Blocks::{insert_all, diff_into}, and publish_pairs to eliminate
per-page PUBLISHED atomics and Vec allocations in writes_with.
|
I reproduced an ownership regression on exact head 2789218. In open_unlocked, OPENING.swap_on returns true when another fault already owns the bit. The combined early-return branch then clears that other opener's bit. A guard or a third fault can observe the still-active opening as idle. This branch is shared by both VICTORY_WATCH_UNLOCKED_PROTECT settings. The asset-free Windows fixture holds the first opener's claim on a real allocated block, exercises the competing fault entry, and checks that the first claim survives. It failed on the unmodified production logic and passed with this two-check correction. The correction leaves an existing claim alone and clears only a claim taken by the current caller when PROTECTING requires fallback. All 66 watch tests passed with VICTORY_WATCH_UNLOCKED_PROTECT=1 and again with 0. Preliminary in-game comparisonI built the exact PR head plus the small ownership correction as a single locked Windows diagnostics executable. Same RTX 5070 Laptop, copied porch checkpoint, warm cache, Series S with DLSS Ultra Performance and frame generation off. Only VICTORY_WATCH_UNLOCKED_PROTECT changed. I used three corresponding host reports around 17–28 seconds after the world entered, with roughly 5,200 draws per frame in both modes. These numbers are medians of those reports.
The enabled session lost Windows foreground shortly after two screenshots confirmed the expected porch pose, so the longer camera-qualified comparison and frame-time percentiles are incomplete. Both modes still show the separately tracked porch arm artifact. The aggregate lock time measures worker contention and is separate from wall-clock frame time. Series X with 2x DLSS FGI tested the corrected guard code on the same .05 base with the explicit 1080p startup fix and #3811, using one Windows diagnostics executable. Both processes used the same copied save, warmed cache, DLSS Performance (960×540 to 1920×1080), 2x DLSS frame generation, and the 15 rendered FPS cap. VICTORY_AB was clear. Only VICTORY_WATCH_UNLOCKED_PROTECT changed. Foreground was polled for the duration. The enabled attempt lost focus after 15.46 seconds, so I compared an interior 14-second interval before that loss to the same world time in the disabled run. The initial screenshots matched the same porch pose. Both windows contain 210 rendered-frame intervals, with median draws 5,787 and 5,750. A later complete enabled window advanced to a much heavier scene and is excluded.
The enabled p95 is 68.3–70.9 ms using either endpoint for the CSV clock alignment. The shown rate uses complete plugin reporting intervals, not individual display-frame timings. This supports lower guard contention in a second profile. The short matched window shows modest improvement at the cap and leaves steadiness under higher load unverified. Protection protocol modeThe diagnostics toggle currently allows VICTORY_AB to switch which protection implementation and which publication path writes_with chooses. The legacy and unlocked implementations use the same protection bookkeeping, and the legacy path does not honor PROTECTING during an unlocked protection change. A live flip can therefore mix protocols across workers, or within one call if its two flag reads differ. The performance cases above explicitly clear VICTORY_AB and set the mode before each process. I isolated the setting at first use in a follow-up commit. Default-on and exact =0 behavior stay the same. The regression launches fresh child processes with VICTORY_AB targeting this switch and checks unset, =0, and =1. The old selector failed the extracted regression. The integrated Windows regression and all 70 watch tests passed in both fresh switch modes after correction. |
|
Whole-process stalls of 2.2–2.7 s with this PR (busy-wait in Tested this PR merged with ten other open PRs (#3733, #3850, #3832, #3848, #3750, #3753, #3705, #3694, #3762, #3726) on 41adb55, diagnostics build, Series S profile, DLSS + FG, 5-minute standing runs from one save.
A sampling profiler with per-round timestamps took 3–7 samples during each long frame instead of ~250, so its own thread was stalled too: the whole process stops, not one waiting thread. Likely cause: fn wait_protecting(block: usize) {
let mut tries = 0u32;
while PROTECTING.any(block, block + 1) {
if tries < 256 {
std::hint::spin_loop();
} else if tries < 320 {
std::thread::yield_now();
} else {
std::thread::sleep(std::time::Duration::from_micros(200));
}
tries = tries.saturating_add(1);
}
}
Found with Claude Code. |
…outside GUARDS mutex and batch Bits/publish
…pin mode at startup Address review findings on trustno1-coder#3760: - Split open_unlocked's OPENING.swap_on(block) and PROTECTING.any(...) checks so a competing fault does not clear another opener's OPENING bit. - Add spin/yield/sleep backoff to wait_protecting to prevent whole-process starvation stalls when multiple title threads fault on a PROTECTING block. - Read VICTORY_WATCH_UNLOCKED_PROTECT once via OnceLock instead of toggled! so VICTORY_AB cannot mix legacy and unlocked protocols mid-run. - Add regression test watch::tests::open_unlocked_preserves_existing_opening_claim.
|
Thank you @Yoruiopz and @ihyajb for catching those issues — all three fixes are now pushed in
Verified locally on
|
…ng paths Wake only draws waiting for the affected pipeline and stop waiting when its compile is deferred. Publish placed-view shapes through immutable numbered slots. Handle adjacent soft copies of the same physical page under bounded remapping locks. Keep large gaps out of initial write-watch queries, retain full in-flight hazard checks, and publish the exact observed pages using word masks. Based in part on upstream profiles and changes in VIctory-NVIDIA trustno1-coder#2188, trustno1-coder#2804, trustno1-coder#3760 and trustno1-coder#3850.
What it changes
guard()previously held the globalGUARDSmutex across allVirtualProtect,elsewhere,uncommitted_end, and aliased-viewprotect_aliascalls, stalling concurrent refresh worker threads and any locked write-fault path behind OS page-table walks. In addition,writes_withallocated aVec<usize>and updatedPUBLISHEDpage by page on every guarded refresh.This PR moves both primary and aliased-view
VirtualProtectcalls outsideGUARDSand batchesBits/PUBLISHEDupdates per 64-block word (enabled by default;VICTORY_WATCH_UNLOCKED_PROTECT=0falls back to the existingguard+publishpath):PROTECT_GATE+PROTECTING):MAPPING -> Asking -> PROTECT_GATE -> GUARDS -> OPENED.guard_with_pub/protect_unlockedholdPROTECT_GATE.read()while runningelsewhere,uncommitted_end, andVirtualProtectoutsideGUARDS; mutators (title_memory_allocated,look_at_holes,writing,kernel_writing,title_memory_written,views_mapped,title_memory_splitting,title_memory_remapped,title_memory_unmapping,title_memory_freed,title_memory_made_real) takePROTECT_GATE.write().soft_runs(...)is read underGUARDSbefore dropping the lock so concurrenttitle_memory_made_realcannot be missed.PROTECTINGmarks in-flight primary and alias blocks before droppingGUARDS(with RAIIClearProtecting/ClearProtectingSliceguards). Fault handlers (on_write,opened_for_writing,came_back) spin briefly onwait_protecting, andopen_unlockedreturnsfalseifPROTECTINGis set so racing faults take the safe locked/settled path.GUARDSis released,restore_rwreverts its protection; for aliased blocks,pending_cleanre-verifies allall_others(g.protected,g.aliased,!failed_aliases,!OPENING,!PROTECTING || alias_to_vp_set,!BESIDE,!unsettled) before marking a blockclean.Bits::{ensure_piece, set_word, clear_word, set_all}and word-levelBlocks::{insert_all, diff_into}.BESIDE/OPENING/TOLD/PROTECTINGpiece lookups and cachedg.protected/g.clean/now_instantinguard_with_pub.publish_pairsavoids theVec<usize>allocation inwrites_withand updatesPUBLISHEDper 64-block word, only called whenguard_with_pubreportsany_publishable.How it was tested
v2026.11.28.01baseline).VirtualProtectrunning insideGUARDS,guard: GUARDS mutex waitsummed across worker threads reached 18.51 ms/frame.VirtualProtectoutsideGUARDS+ batchingBits/publish_pairsreducedguard: GUARDS mutex waitto ~2.8 ms/frame.cargo testpassed for the crates it touches: yescargo test --locked -p victory-gpu --lib watch:: -- --test-threads=1: 65 passed, 0 failed.cargo test --locked -p victory-gpu --lib watch::many_askers_tests: 10 passed, 0 failed (default ON) and 10 passed, 0 failed (VICTORY_WATCH_UNLOCKED_PROTECT=0).watch::many_askers_tests::no_write_to_resting_views_is_lost_between_askers: 30 consecutive runs, 0 failures (runs=30 fails=0).cargo clippy -p victory-gpu --no-deps --all-targets --lockedand--all-features: 0 warnings in touched/new code.cargo xtask policy --staged: passed.Checked for overlap
shadow.rslanding bitmap) and watch: extend WRITTEN_EPOCHS for lock-free journal reads and whole-page notes #3756 (watch.rslock-freeWRITTEN_EPOCHSjournal).