perf(gpu): opt-in time-sliced sweeps and bounded/hysteresis residency #552

Open
github-bot wants to merge 1 commit from github-bot/gh-552 into main AGit
Owner

@⁠chefulano on GitHub · 2026-12-05 02:46 UTC · original
chefulano:pr2/stutter-residency → main · +1198 −159 · 4 files · 1 commits · open

Problem

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 #355 spread gather slices to 4 ms:

  1. Under heavy streaming, resource::let_go_idle() still runs retirement (Emptied → Unpooled → Room) and VICTORY_POOL_MOVE work unbounded in a single submission pause, and fixed 4 ms gather slices can still exceed tight frame-time budgets.
  2. 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 / #355 parity when unset, preserving #475 residency census accounting) and documents the existing VICTORY_POOL_MOVE_MB switch in docs/SETTINGS.md:

  • VICTORY_SWEEP_BUDGET_MS (0.1–50.0 ms, off by default): Composes cleanly on top of #355's sweep_steps and gather_lap. When unset, host::sweep_steps and resource::let_go_idle execute the exact main (#355) path unchanged. When enabled, time-slices keep.room == u64::MAX (slice_btree_range), budgeted gather (gather_lap_budgeted, dropping sweep_members() before locking r.host.made), resumable RetireLap (Emptied → Unpooled → Room → MoveOut, counting skipped candidates against the slice clock via retire_slice_should_pause()), and time-sliced move_out_slice() sharing the 1 s VICTORY_POOL_MOVE_MB byte budget across slices.
    • Bounded open RetireLap age (4,000 ms): Records started_ms on RetireLap and unwinds (*retire_guard = None; RETIRE_OPEN = false; pool::drain(&[])) at RETIRE_LAP_MAX_AGE_LIMIT_MS = 4_000 ms so stale block-fate snapshots cannot linger.
    • Rate-capped emergency cadence (<= 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, checks lap_may_probe_emergency(now, lap_at) (>= 50 ms) and gates vram_emergency() behind a 50 ms LAP_EMG_AT CAS (<= 20 Hz) before querying DXGI QueryVideoMemoryInfo, 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 of um/residency::tick() before the final kernel kick(), running at least one run per pass for forward progress. Keeps pass_ms below the prepare loop in the default-off branch for exact main parity.
  • VICTORY_RESIDENCY_HYSTERESIS=1 (off by default; Linux/RADV unified memory only): Tracks per-pool watched_or_promoted vs cpu_touchbacks (gated behind residency_hysteresis_on() for exact default-off parity) with /2 decay every 128 busy ticks (when >= 256 or currently throttled, so throttled pools between 64 and 255 samples also age out and recover). Once a non-write-combined pool reaches >= 64 samples with > 50% CPU re-touch rate, skips both real-page watch-retiring (warm promotion) and speculative seen_untouched promotion while leaving write-combined GPU pools unthrottled.
  • VICTORY_POOL_MOVE_MB (8..=4096, default 128): Documents the existing rate-limit switch in docs/SETTINGS.md and adds parser tests.

Measured impact

Verified in live 4-minute streaming stress runs (4 × 240 s ABBA, 0 compiles) on an 8 GiB VRAM / 16 GiB RAM AMD RDNA 3 (RX 7600M XT 8 GiB) Linux host under RADV + vkd3d-proton:

  • Emergency DXGI probe cap (LAP_EMG_AT 50 ms CAS): Cut emergency QueryVideoMemoryInfo calls by -94.6% (84.7–96.2/s -> 4.8–5.3/s).
  • 4,000 ms RetireLap age cap: Completed storm laps cleanly at 1,746–2,572 ms max age without mid-storm aborts (vs 1,500 ms which aborted laps mid-eviction) while still bounding snapshot staleness.
  • Unconditional 1-s non-texture maintenance: Kept staging reclaim and idle texture release running through VRAM storms, 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).
  • In an earlier single combined-build 135 s A/B run on the same host, enabling sweep + residency pacing improved 1% low FPS (7.5 -> 8.6, +1.1 FPS), worst-3 5 s average FPS (12.84 -> 14.48, +1.64 FPS), and cumulative >= 100 ms frame time (11,466 -> 8,581 ms, -25.2%).

Verification

  • Rebased onto main (a5c6484, cleanly composing with merged #355 and #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 --tests and cargo clippy --no-deps --locked --target x86_64-pc-windows-msvc -p victory-gpu -p victory --all-targets: 0 errors, 0 new warnings (fixed both earlier explicit_counter_loop clippy warnings).
  • Scoped Windows unit tests (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 ms RetireLap expiry), resource::tests::sweep_budget_and_pool_move_mb_parsing, and all 6 um::residency::tests::.
**@⁠chefulano** on GitHub · 2026-12-05 02:46 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/552) `chefulano:pr2/stutter-residency` → `main` · +1198 −159 · 4 files · 1 commits · open ## Problem 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 `#355` spread gather slices to 4 ms: 1. Under heavy streaming, `resource::let_go_idle()` still runs retirement (`Emptied → Unpooled → Room`) and `VICTORY_POOL_MOVE` work unbounded in a single submission pause, and fixed 4 ms gather slices can still exceed tight frame-time budgets. 2. `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` / `#355` parity when unset, preserving `#475` residency census accounting) and documents the existing `VICTORY_POOL_MOVE_MB` switch in `docs/SETTINGS.md`: - **`VICTORY_SWEEP_BUDGET_MS` (0.1–50.0 ms, off by default):** Composes cleanly on top of `#355`'s `sweep_steps` and `gather_lap`. When unset, `host::sweep_steps` and `resource::let_go_idle` execute the exact `main` (`#355`) path unchanged. When enabled, time-slices `keep.room == u64::MAX` (`slice_btree_range`), budgeted gather (`gather_lap_budgeted`, dropping `sweep_members()` before locking `r.host.made`), resumable `RetireLap` (`Emptied → Unpooled → Room → MoveOut`, counting skipped candidates against the slice clock via `retire_slice_should_pause()`), and time-sliced `move_out_slice()` sharing the 1 s `VICTORY_POOL_MOVE_MB` byte budget across slices. - **Bounded open `RetireLap` age (`4,000 ms`):** Records `started_ms` on `RetireLap` and unwinds (`*retire_guard = None; RETIRE_OPEN = false; pool::drain(&[])`) at `RETIRE_LAP_MAX_AGE_LIMIT_MS = 4_000 ms` so stale block-fate snapshots cannot linger. - **Rate-capped emergency cadence (`<= 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, checks `lap_may_probe_emergency(now, lap_at)` (`>= 50 ms`) and gates `vram_emergency()` behind a 50 ms `LAP_EMG_AT` CAS (`<= 20 Hz`) before querying DXGI `QueryVideoMemoryInfo`, 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 of `um/residency::tick()` before the final kernel `kick()`, running at least one run per pass for forward progress. Keeps `pass_ms` below the prepare loop in the default-off branch for exact `main` parity. - **`VICTORY_RESIDENCY_HYSTERESIS=1` (off by default; Linux/RADV unified memory only):** Tracks per-pool `watched_or_promoted` vs `cpu_touchbacks` (gated behind `residency_hysteresis_on()` for exact default-off parity) with `/2` decay every 128 busy ticks (when `>= 256` or currently throttled, so throttled pools between 64 and 255 samples also age out and recover). Once a non-write-combined pool reaches `>= 64` samples with `> 50%` CPU re-touch rate, skips both `real`-page watch-retiring (warm promotion) and speculative `seen_untouched` promotion while leaving write-combined GPU pools unthrottled. - **`VICTORY_POOL_MOVE_MB` (`8..=4096`, default `128`):** Documents the existing rate-limit switch in `docs/SETTINGS.md` and adds parser tests. ## Measured impact Verified in live 4-minute streaming stress runs (`4 × 240 s` ABBA, `0` compiles) on an **8 GiB VRAM / 16 GiB RAM AMD RDNA 3 (RX 7600M XT 8 GiB)** Linux host under RADV + vkd3d-proton: - **Emergency DXGI probe cap (`LAP_EMG_AT` 50 ms CAS):** Cut emergency `QueryVideoMemoryInfo` calls by **-94.6%** (`84.7–96.2/s -> 4.8–5.3/s`). - **`4,000 ms` `RetireLap` age cap:** Completed storm laps cleanly at **`1,746–2,572 ms` max age** without mid-storm aborts (vs `1,500 ms` which aborted laps mid-eviction) while still bounding snapshot staleness. - **Unconditional 1-s non-texture maintenance:** Kept staging reclaim and idle texture release running through VRAM storms, 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`). - In an earlier single combined-build 135 s A/B run on the same host, enabling sweep + residency pacing improved 1% low FPS (`7.5 -> 8.6`, `+1.1 FPS`), worst-3 5 s average FPS (`12.84 -> 14.48`, `+1.64 FPS`), and cumulative `>= 100 ms` frame time (`11,466 -> 8,581 ms`, `-25.2%`). ## Verification - Rebased onto `main` (`a5c6484`, cleanly composing with merged `#355` and `#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 --tests` and `cargo clippy --no-deps --locked --target x86_64-pc-windows-msvc -p victory-gpu -p victory --all-targets`: 0 errors, 0 new warnings (fixed both earlier `explicit_counter_loop` clippy warnings). - Scoped Windows unit tests (`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 ms `RetireLap` expiry), `resource::tests::sweep_budget_and_pool_move_mb_parsing`, and all 6 `um::residency::tests::`.
Adds VICTORY_SWEEP_BUDGET_MS (time-sliced gather, retirement, and
pool-move sweeps with 50/200 ms open-lap continuation without starving
once-a-second non-texture maintenance), VICTORY_RESIDENCY_BUDGET_MS
(per-run prepare+place wall-time cap so no dropped run is left
retired/zapped), VICTORY_RESIDENCY_HYSTERESIS (per-pool >50% CPU
touch-back throttling with periodic decay so throttled pools recover),
and documents existing VICTORY_POOL_MOVE_MB.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 02:52:33 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 06:03 UTC · original

Checked 0c449a3 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, which is current main.

On the PR, cargo test -p victory-gpu --lib -- --test-threads=4 --skip descriptor::tests::views_die_with_their_resource gives 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 victory is clean apart from the old room_lately warning. Clippy on victory-gpu --all-targets adds two explicit_counter_loop warnings, one for the visited counter in slice_btree_range (resource.rs:2464) and one for skipped_visited in 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 -w shows 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.

  • strike() now always does a fetch_add on cpu_touchbacks (residency.rs:626). strike is also reached from touched() (residency.rs:570), so that one runs on the thread that touches a retired page, not only in the residency thread. watched_or_promoted is bumped on retire (residency.rs:852) and on every card placement in both paths. The decay runs every 128 busy ticks (residency.rs:722), and hysteresis_logged is stored for every pool every tick (residency.rs:777). All of it is cheap, and none of it exists without unified memory.
  • pass_ms is now taken before the prepare loop instead of after it (residency.rs:938). It only feeds the promoted stamp and the QUICK_RETURN window in returned(), so with the switch off the quick-return count can shift a little. Moving it back below the prepare loop in the legacy branch would make the parity exact.
  • The "page residency pass" line always carries budget_stopped now (residency.rs:1103).
  • host::sweep reads lap_open() at the top of every call (host.rs:343), plus once more after the once-a-second path (host.rs:385). These are relaxed loads.

Here's what I checked in the time-sliced sweep, with the switch on.

  • In-flight safety holds up as far as I can tell. Every let-go still goes through take_idle, which redoes long_ago, sole_idle (one Arc strong count and one COM reference) and copy_destination under made. Every stored Idle.at is checked against all under 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 than all, but only filled host copies are members (resource.rs:1710) and move_out needs fills anyway, so the candidate set is the same.
  • Pausing POOL_MOVE doesn't leave anything half done. Each texture is moved whole under its own made lock (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.
  • Lock order looks fine. gather_lap drops sweep_members before it takes 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.
  • The cursor resumes by key, so removals between slices don't skip anything. An entry that turns idle after the cursor passed it waits for the next lap, which is fine. I don't see anything that can be skipped forever.
  • The open lap is a snapshot. fate, waited, the Idle.piece values that fed block_fates, and the pool::drain(&draining) call (resource.rs:2931) are all fixed when the retire lap starts, and so are idle_ms, room_ms, age, grace and do_move_out. Main refreshes all of that every second. If a lap lasts longer than a second (1.5 ms every 200 ms, or every 50 ms under pressure), blocks stay marked draining from stale idle sums, and Emptied can be applied by block index to a slot the pool has reused. take_idle keeps that from being unsafe, but it can let go or drain more than main would. Ending a lap after a fixed age, or redoing the drain call each slice, would bound it.
  • Under pressure (!open) the full sweep is gone. Reclaim is capped at about budget times cadence, roughly 3 % of wall time at 1.5 ms per 50 ms, where main does the whole job once a second. That's the point of the switch, but it trades against how fast VRAM comes back when admissions are closed. Your numbers are from a combined build, so a run of this branch alone near the line would help.
  • With a lap open, host::sweep calls vram_emergency() on every submission, before the cadence check (host.rs:359). That's two QueryVideoMemoryInfo calls per submission, where main makes them once a second. Checking the time against 50 ms first and only then asking would avoid it. Each slice also redoes let_go_idle's fixed prelude (REPLACED partition, video_memory, texture_blocks, vram_plan) outside the slice clock, at 5 to 20 Hz.
  • In the keep.room == u64::MAX branch the budget replaces the idle_ms < 60_000 full 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 (!combined in 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 when n & 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.

  • The budget loop only ever drops a suffix of the plan, and the plan puts the down runs (reached, room, cold) before up and up_seen. So stopping early never promotes without the demotions it counted on. Each run now takes and drops the lazy::moving() write guard by itself (residency.rs:971), where main holds one guard for the whole place loop. That looks fine and probably helps, since a title thread touching a zapped page waits on a smaller window.
  • When a pool is throttled, real pages hit continue without 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.
  • Recovery is slow when counts are high. Decay only runs on busy ticks, once every 128 of them, which is at least 25.6 s with the 200 ms TICK. A pool at the 11k/10k from your test needs about 8 halvings to drop under 64 samples, so several minutes of busy play before it's probed again.

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

**@⁠Kal0s-design** on GitHub · 2026-12-05 06:03 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/552#issuecomment-7433067614) Checked 0c449a3 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, which is current main. On the PR, `cargo test -p victory-gpu --lib -- --test-threads=4 --skip descriptor::tests::views_die_with_their_resource` gives 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 victory` is clean apart from the old room_lately warning. Clippy on victory-gpu --all-targets adds two explicit_counter_loop warnings, one for the `visited` counter in slice_btree_range (resource.rs:2464) and one for `skipped_visited` in 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 -w` shows 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. - strike() now always does a fetch_add on cpu_touchbacks (residency.rs:626). strike is also reached from touched() (residency.rs:570), so that one runs on the thread that touches a retired page, not only in the residency thread. watched_or_promoted is bumped on retire (residency.rs:852) and on every card placement in both paths. The decay runs every 128 busy ticks (residency.rs:722), and hysteresis_logged is stored for every pool every tick (residency.rs:777). All of it is cheap, and none of it exists without unified memory. - pass_ms is now taken before the prepare loop instead of after it (residency.rs:938). It only feeds the promoted stamp and the QUICK_RETURN window in returned(), so with the switch off the quick-return count can shift a little. Moving it back below the prepare loop in the legacy branch would make the parity exact. - The "page residency pass" line always carries budget_stopped now (residency.rs:1103). - host::sweep reads lap_open() at the top of every call (host.rs:343), plus once more after the once-a-second path (host.rs:385). These are relaxed loads. Here's what I checked in the time-sliced sweep, with the switch on. - In-flight safety holds up as far as I can tell. Every let-go still goes through take_idle, which redoes long_ago, sole_idle (one Arc strong count and one COM reference) and copy_destination under `made`. Every stored Idle.at is checked against `all` under 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 than `all`, but only filled host copies are members (resource.rs:1710) and move_out needs fills anyway, so the candidate set is the same. - Pausing POOL_MOVE doesn't leave anything half done. Each texture is moved whole under its own `made` lock (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. - Lock order looks fine. gather_lap drops sweep_members before it takes `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. - The cursor resumes by key, so removals between slices don't skip anything. An entry that turns idle after the cursor passed it waits for the next lap, which is fine. I don't see anything that can be skipped forever. - The open lap is a snapshot. fate, waited, the Idle.piece values that fed block_fates, and the pool::drain(&draining) call (resource.rs:2931) are all fixed when the retire lap starts, and so are idle_ms, room_ms, age, grace and do_move_out. Main refreshes all of that every second. If a lap lasts longer than a second (1.5 ms every 200 ms, or every 50 ms under pressure), blocks stay marked draining from stale idle sums, and Emptied can be applied by block index to a slot the pool has reused. take_idle keeps that from being unsafe, but it can let go or drain more than main would. Ending a lap after a fixed age, or redoing the drain call each slice, would bound it. - Under pressure (!open) the full sweep is gone. Reclaim is capped at about budget times cadence, roughly 3 % of wall time at 1.5 ms per 50 ms, where main does the whole job once a second. That's the point of the switch, but it trades against how fast VRAM comes back when admissions are closed. Your numbers are from a combined build, so a run of this branch alone near the line would help. - With a lap open, host::sweep calls vram_emergency() on every submission, before the cadence check (host.rs:359). That's two QueryVideoMemoryInfo calls per submission, where main makes them once a second. Checking the time against 50 ms first and only then asking would avoid it. Each slice also redoes let_go_idle's fixed prelude (REPLACED partition, video_memory, texture_blocks, vram_plan) outside the slice clock, at 5 to 20 Hz. - In the keep.room == u64::MAX branch the budget replaces the `idle_ms < 60_000` full 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 (`!combined` in 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 when `n & 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. - The budget loop only ever drops a suffix of the plan, and the plan puts the down runs (reached, room, cold) before up and up_seen. So stopping early never promotes without the demotions it counted on. Each run now takes and drops the lazy::moving() write guard by itself (residency.rs:971), where main holds one guard for the whole place loop. That looks fine and probably helps, since a title thread touching a zapped page waits on a smaller window. - When a pool is throttled, `real` pages hit `continue` without 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. - Recovery is slow when counts are high. Decay only runs on busy ticks, once every 128 of them, which is at least 25.6 s with the 200 ms TICK. A pool at the 11k/10k from your test needs about 8 halvings to drop under 64 samples, so several minutes of busy play before it's probed again. 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
github-bot force-pushed github-bot/gh-552 from 0c449a3932 to f9c404106f 2026-12-05 20:24:33 +00:00 Compare
Author
Owner

@⁠chefulano on GitHub · 2026-12-05 20:22 UTC · original

Note

🤖 Gemini 4 Neon responding on behalf of chefulano

Rebased #552 onto current main (a5c6484, composing cleanly on top of merged #355 with exact #355 parity when VICTORY_SWEEP_BUDGET_MS is unset) and fixed every issue @⁠Kal0s-design flagged:

  • Eliminated per-submission vram_emergency() DXGI queries: host::sweep_steps() now checks lap_may_probe_emergency(now, lap_at) (>= 50 ms) and gates vram_emergency() behind a 50 ms LAP_EMG_AT CAS (<= 20 Hz) before querying DXGI QueryVideoMemoryInfo. 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).
  • Bounded open RetireLap age (4,000 ms) & unconditional maintenance: RetireLap now records started_ms and unwinds via pool::drain(&[]) at RETIRE_LAP_MAX_AGE_LIMIT_MS = 4_000 ms (verified live: 1,500 ms aborted laps mid-storm, whereas 4,000 ms completed cleanly at 1,746–2,572 ms max 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/10 NI pass, 0 compiles, 0.0 s whiteout).
  • Exact default-off parity in um/residency.rs: Restored pass_ms below the prepare loop in the default-off (pass_budget_us.is_none()) branch, and gated cpu_touchbacks, watched_or_promoted, decay_hysteresis, and hysteresis_logged on residency_hysteresis_on().
  • Clippy & docs: Fixed both explicit_counter_loop clippy warnings (slice_btree_range and its test), removed the redundant (processed_any || n > 0) condition in gather_lap_budgeted, added (Linux/RADV unified memory only, no effect on native D3D12) to both residency switches in docs/SETTINGS.md, and documented that hysteresis throttling skips both real-page watch-retiring (warm promotion) and speculative seen_untouched promotion alongside the 4,000 ms lap cap and <= 20 Hz emergency 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 (0 new warnings), and all 9/9 scoped unit tests (sweep_lap_cadence, resumable_sweep_slicing, sweep_budget_and_pool_move_mb_parsing, um::residency::tests::).

**@⁠chefulano** on GitHub · 2026-12-05 20:22 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/552#issuecomment-7444760334) > [!NOTE] > 🤖 **Gemini 4 Neon responding on behalf of chefulano** Rebased `#552` onto current `main` (`a5c6484`, composing cleanly on top of merged `#355` with exact `#355` parity when `VICTORY_SWEEP_BUDGET_MS` is unset) and fixed every issue @⁠Kal0s-design flagged: - **Eliminated per-submission `vram_emergency()` DXGI queries:** `host::sweep_steps()` now checks `lap_may_probe_emergency(now, lap_at)` (`>= 50 ms`) and gates `vram_emergency()` behind a 50 ms `LAP_EMG_AT` CAS (`<= 20 Hz`) before querying DXGI `QueryVideoMemoryInfo`. 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`). - **Bounded open `RetireLap` age (`4,000 ms`) & unconditional maintenance:** `RetireLap` now records `started_ms` and unwinds via `pool::drain(&[])` at `RETIRE_LAP_MAX_AGE_LIMIT_MS = 4_000 ms` (verified live: `1,500 ms` aborted laps mid-storm, whereas `4,000 ms` completed cleanly at `1,746–2,572 ms` max 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/10` NI pass, `0` compiles, `0.0 s` whiteout). - **Exact default-off parity in `um/residency.rs`:** Restored `pass_ms` below the prepare loop in the default-off (`pass_budget_us.is_none()`) branch, and gated `cpu_touchbacks`, `watched_or_promoted`, `decay_hysteresis`, and `hysteresis_logged` on `residency_hysteresis_on()`. - **Clippy & docs:** Fixed both `explicit_counter_loop` clippy warnings (`slice_btree_range` and its test), removed the redundant `(processed_any || n > 0)` condition in `gather_lap_budgeted`, added `(Linux/RADV unified memory only, no effect on native D3D12)` to both residency switches in `docs/SETTINGS.md`, and documented that hysteresis throttling skips both `real`-page watch-retiring (warm promotion) and speculative `seen_untouched` promotion alongside the `4,000 ms` lap cap and `<= 20 Hz` emergency 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` (`0` new warnings), and all `9/9` scoped unit tests (`sweep_lap_cadence`, `resumable_sweep_slicing`, `sweep_budget_and_pool_move_mb_parsing`, `um::residency::tests::`).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/552/head:github-bot/gh-552'
git switch 'github-bot/gh-552'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-552'
git switch 'github-bot/gh-552'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-552'
git switch 'github-bot/gh-552'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-552'
git switch 'main'
git merge --squash 'github-bot/gh-552'
git switch 'main'
git merge --ff-only 'github-bot/gh-552'
git switch 'main'
git merge 'github-bot/gh-552'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.