perf(gpu): opt-in time-sliced sweeps and bounded/hysteresis residency #552
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/lobomfz--VIctory-xmem!552
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-552"
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?
@chefulano on GitHub · 2026-12-05 02:46 UTC · original
chefulano:pr2/stutter-residency→main· +1198 −159 · 4 files · 1 commits · openProblem
On constrained 8 GiB VRAM / 16 GiB RAM systems (e.g., AMD RDNA 3 / RX 7600M XT 8 GiB) where textures constantly stream near the VRAM budget and Linux/RADV unified-memory page residency runs frequently, two maintenance paths still cause multi-millisecond frame-time spikes even after
#355spread gather slices to 4 ms:resource::let_go_idle()still runs retirement (Emptied → Unpooled → Room) andVICTORY_POOL_MOVEwork unbounded in a single submission pause, and fixed 4 ms gather slices can still exceed tight frame-time budgets.um/residency::tick()can spend many milliseconds migrating runs in one pass, and repeatedly promotes/watch-retires pages from non-write-combined pools that the CPU immediately re-touches.Change
Adds three opt-in switches (all off by default; exact
main/#355parity when unset, preserving#475residency census accounting) and documents the existingVICTORY_POOL_MOVE_MBswitch indocs/SETTINGS.md:VICTORY_SWEEP_BUDGET_MS(0.1–50.0 ms, off by default): Composes cleanly on top of#355'ssweep_stepsandgather_lap. When unset,host::sweep_stepsandresource::let_go_idleexecute the exactmain(#355) path unchanged. When enabled, time-sliceskeep.room == u64::MAX(slice_btree_range), budgeted gather (gather_lap_budgeted, droppingsweep_members()before lockingr.host.made), resumableRetireLap(Emptied → Unpooled → Room → MoveOut, counting skipped candidates against the slice clock viaretire_slice_should_pause()), and time-slicedmove_out_slice()sharing the 1 sVICTORY_POOL_MOVE_MBbyte budget across slices.RetireLapage (4,000 ms): Recordsstarted_msonRetireLapand unwinds (*retire_guard = None; RETIRE_OPEN = false; pool::drain(&[])) atRETIRE_LAP_MAX_AGE_LIMIT_MS = 4_000 msso stale block-fate snapshots cannot linger.<= 20 Hz) & unconditional maintenance: While a budgeted lap is open,host::sweep_steps()keeps once-a-second non-texture maintenance (pool::room/ staging reclaim,trim_library,shadow::let_go_idle,texture::let_go_idle) running unconditionally on schedule, checkslap_may_probe_emergency(now, lap_at)(>= 50 ms) and gatesvram_emergency()behind a 50 msLAP_EMG_ATCAS (<= 20 Hz) before querying DXGIQueryVideoMemoryInfo, and steps texture slices every 50 ms under VRAM emergency or 200 ms otherwise.VICTORY_RESIDENCY_BUDGET_MS(0.2–50.0 ms, off by default; Linux/RADV unified memory only): Wall-time-caps the per-run prepare+place loop ofum/residency::tick()before the final kernelkick(), running at least one run per pass for forward progress. Keepspass_msbelow the prepare loop in the default-off branch for exactmainparity.VICTORY_RESIDENCY_HYSTERESIS=1(off by default; Linux/RADV unified memory only): Tracks per-poolwatched_or_promotedvscpu_touchbacks(gated behindresidency_hysteresis_on()for exact default-off parity) with/2decay every 128 busy ticks (when>= 256or currently throttled, so throttled pools between 64 and 255 samples also age out and recover). Once a non-write-combined pool reaches>= 64samples with> 50%CPU re-touch rate, skips bothreal-page watch-retiring (warm promotion) and speculativeseen_untouchedpromotion while leaving write-combined GPU pools unthrottled.VICTORY_POOL_MOVE_MB(8..=4096, default128): Documents the existing rate-limit switch indocs/SETTINGS.mdand adds parser tests.Measured impact
Verified in live 4-minute streaming stress runs (
4 × 240 sABBA,0compiles) on an 8 GiB VRAM / 16 GiB RAM AMD RDNA 3 (RX 7600M XT 8 GiB) Linux host under RADV + vkd3d-proton:LAP_EMG_AT50 ms CAS): Cut emergencyQueryVideoMemoryInfocalls by -94.6% (84.7–96.2/s -> 4.8–5.3/s).4,000 msRetireLapage cap: Completed storm laps cleanly at1,746–2,572 msmax age without mid-storm aborts (vs1,500 mswhich aborted laps mid-eviction) while still bounding snapshot staleness.-96 to -112 MB(266–319 MB -> 163–232 MB) and raising worst-arm free host RAM (MemAvailable) by+162 MiB(753.8 -> 915.9 MiB).7.5 -> 8.6,+1.1 FPS), worst-3 5 s average FPS (12.84 -> 14.48,+1.64 FPS), and cumulative>= 100 msframe time (11,466 -> 8,581 ms,-25.2%).Verification
main(a5c6484, cleanly composing with merged#355and#550; no VRAM reserve changes included).cargo xtask policy:368 files ok;cargo test -p xtask -- policy::tests:7 passed, 0 failed;cargo test -p xtask -- switches::documented_switches_are_read:1 passed, 0 failed.cargo check --locked --target x86_64-pc-windows-msvc -p victory-gpu -p victory --testsandcargo clippy --no-deps --locked --target x86_64-pc-windows-msvc -p victory-gpu -p victory --all-targets: 0 errors, 0 new warnings (fixed both earlierexplicit_counter_loopclippy warnings).9 passed, 0 failed):host::tests::sweep_lap_cadence_speeds_up_on_emergency,resource::tests::resumable_sweep_slicing_visits_every_key_once_and_wraps(including skipped-entry pause bounds and 4,000 msRetireLapexpiry),resource::tests::sweep_budget_and_pool_move_mb_parsing, and all 6um::residency::tests::.@Kal0s-design on GitHub · 2026-12-05 06:03 UTC · original
Checked
0c449a3on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base isb581f7e, which is current main.On the PR,
cargo test -p victory-gpu --lib -- --test-threads=4 --skip descriptor::tests::views_die_with_their_resourcegives 357 passed and 5 failed. Main gives 352 passed and the same 5 failed (the two indirect host_list tests, the two pipeline::host library loads and the flaky watch one, all known here). It's the same 357/5 with VICTORY_SWEEP_BUDGET_MS=1.5, VICTORY_RESIDENCY_BUDGET_MS=2.0 and VICTORY_RESIDENCY_HYSTERESIS=1 set, and the five new tests pass.cargo check -p victoryis clean apart from the old room_lately warning. Clippy on victory-gpu --all-targets adds two explicit_counter_loop warnings, one for thevisitedcounter in slice_btree_range (resource.rs:2464) and one forskipped_visitedin the new test (resource.rs:6524). Nothing else is new.There's a caveat on the switches-on run. I put temporary prints on the branches of let_go_idle (reverted since). In the whole unit suite only one sweep reaches it, and it takes the keep.room == u64::MAX branch because the card is nowhere near its line. So with the switch on, the only new code the tests ran is the slice_btree_range walk at resource.rs:2878. gather_lap, the RetireLap phases and move_out_slice never ran. I didn't manage a test that drives them either. It would need real filled host copies that have been idle for IDLE_FRAMES frames plus a forced Keep, and that's more scaffolding than a throwaway patch. Everything below about the lap path comes from reading the code.
The residency half can't run on native D3D12 at all, so it's reading only too. um::pool bails at
get()?(um.rs:1147). load() only takes an AMD Vulkan device (um.rs:587), and then returns None unless the driver maps title pages on demand (um.rs:701-706, the setup.sh RADV). residency::opened is only called from um.rs:1179 and um.rs:1228, and that's what spawns the residency thread (residency.rs:381-384). On NVIDIA, on WARP, and on AMD with the Windows driver, VICTORY_RESIDENCY_BUDGET_MS and VICTORY_RESIDENCY_HYSTERESIS do nothing. The paging rows in SETTINGS.md don't say that today, so a short note would save Windows users from trying them.With the switches unset, behaviour matches main as far as I can see.
git diff -wshows the legacy branches of let_go_idle and tick are main's code reindented. It isn't literally identical though, which matters given the "exact main parity" wording.Here's what I checked in the time-sliced sweep, with the switch on.
made. Every stored Idle.at is checked againstallunder textures() before it's dereferenced again (resource.rs:2914 and in each phase). So a texture freed between slices is skipped, and one reallocated at the same address gets judged on its live state. move_out_slice keeps move_out's checks (fills, placed, host_wrote, try_lock, copy_destination, no twin). It walks sweep_members rather thanall, but only filled host copies are members (resource.rs:1710) and move_out needs fills anyway, so the candidate set is the same.madelock (unstage, grown, take, REPLACED), and the slice that moved it calls descriptor::host::moved(starts) and adds its bytes to the one-second window before it returns. A pause only keeps the cursor.made. move_out_slice and take_idle take made and then sweep_members, as main does. LAP and RETIRE_LAP are only touched inside let_go_idle on the submitting thread.idle_ms < 60_000full scan, and that branch never opens a lap, so it only goes on at 1 Hz. idle_ms is under 60 s there only when the system gives no budget, so it's an edge case.The other body claims I could check by reading hold. Skipped candidates count against the slice clock (slice_work goes up before the
continue). The sort runs once, between gather and the first retire phase (resource.rs:2915). Dropped residency runs are neither retired nor zapped. Write-combined pools are never throttled (!combinedin the throttle test). The documented ranges match the parsers (0.1 to 50 and 0.2 to 50 ms, 8 to 4096 MiB with 128 as default). Two tiny things.(processed_any || n > 0)at resource.rs:2587 is always true whenn & 63 == 63. The unwraps at resource.rs:2980 and 3107 are safe, since the guard was just filled or checked under the same lock.On the residency budget and hysteresis, again from reading only.
realpages hitcontinuewithout a retire (residency.rs:844). Retire is the only road to warm promotion for CPU-mapped pages in a non-write-combined pool, so throttling also stops warm promotion there, not just the speculative seen ones. That's probably intended, but it's more than the doc line says.I didn't test the game, any AMD or RADV setup (so none of the residency changes ran), VICTORY_POOL_MOVE through the slice path, or any run where the lap path actually opened.
AI-assisted: yes
0c449a3932tof9c404106f@chefulano on GitHub · 2026-12-05 20:22 UTC · original
Rebased
#552onto currentmain(a5c6484, composing cleanly on top of merged#355with exact#355parity whenVICTORY_SWEEP_BUDGET_MSis unset) and fixed every issue @Kal0s-design flagged:vram_emergency()DXGI queries:host::sweep_steps()now checkslap_may_probe_emergency(now, lap_at)(>= 50 ms) and gatesvram_emergency()behind a 50 msLAP_EMG_ATCAS (<= 20 Hz) before querying DXGIQueryVideoMemoryInfo. In live 4-minute 8 GiB RX 7600M XT stress runs, this cut emergency DXGI queries by -94.6% (84.7–96.2/s -> 4.8–5.3/s).RetireLapage (4,000 ms) & unconditional maintenance:RetireLapnow recordsstarted_msand unwinds viapool::drain(&[])atRETIRE_LAP_MAX_AGE_LIMIT_MS = 4_000 ms(verified live:1,500 msaborted laps mid-storm, whereas4,000 mscompleted cleanly at1,746–2,572 msmax age). Once-a-second non-texture maintenance (pool::room/ staging reclaim,trim_library,shadow::let_go_idle,texture::let_go_idle) runs unconditionally on schedule while a budgeted lap is open, cutting storm staging held by-96 to -112 MB(266–319 MB -> 163–232 MB) and raising worst-arm free host RAM (MemAvailable) by+162 MiB(753.8 -> 915.9 MiB) across the clean 4-minute ABBA (10/10NI pass,0compiles,0.0 swhiteout).um/residency.rs: Restoredpass_msbelow the prepare loop in the default-off (pass_budget_us.is_none()) branch, and gatedcpu_touchbacks,watched_or_promoted,decay_hysteresis, andhysteresis_loggedonresidency_hysteresis_on().explicit_counter_loopclippy warnings (slice_btree_rangeand its test), removed the redundant(processed_any || n > 0)condition ingather_lap_budgeted, added(Linux/RADV unified memory only, no effect on native D3D12)to both residency switches indocs/SETTINGS.md, and documented that hysteresis throttling skips bothreal-page watch-retiring (warm promotion) and speculativeseen_untouchedpromotion alongside the4,000 mslap cap and<= 20 Hzemergency probe cap.Verified on
a5c6484:cargo xtask policy(368 files ok),policy::tests(7/7),switches::documented_switches_are_read(1/1),cargo check+cargo clippy --no-deps(0new warnings), and all9/9scoped unit tests (sweep_lap_cadence,resumable_sweep_slicing,sweep_budget_and_pool_move_mb_parsing,um::residency::tests::).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.