Sweep: release trimmed spares off the submitting thread (once-a-second hitch) #3951

Closed
github-bot wants to merge 2 commits from github-bot/gh-3951 into main AGit
Owner

@⁠Colej1921 on GitHub · 2026-11-30 12:47 UTC · original
Colej1921:fix/sweep-release-off-thread → main · +69 −7 · 2 files · 2 commits · closed without merging

What

Fixes a frame hitch that happened about once a second. Under memory pressure, the once-a-second sweep (host.rs sweep()) now releases the spares it trims on a background thread (victory-release). Before, it released them on the submitting thread.

Why

The sweep runs on the submitting thread, before a submission starts. While the PC is under host memory pressure, which can happen even on a 32 GB PC (1–2 GB free while the title runs), the sweep trims three kinds of spare:

  • scratch chunks
  • copy sources
  • send memory

Releasing those D3D12 buffers took 22–45 ms every second:

  • 7–24 ms releasing scratch chunks (trim_spare_chunks)
  • 11–15 ms releasing send memory (send::trim)

As a result, one frame came in late in nearly every second, even at a steady 30 fps. I found this with per-step timing of the sweep (not included in this PR).

No list names what a trim lets go of: a list holds what it records until it is reset. So only the release itself is left, and D3D12 objects are free-threaded. The release thread holds none of our locks.

Measured

Rig: Ryzen 7 7700X, RTX 4070 SUPER, 32 GB, Series S profile, DLSS frame generation 2x, 30 fps cap. Two 90-second walks with the game focused, on the same build, with only VICTORY_RELEASE_APART different:

VICTORY_RELEASE_APART on (default) =0 (as before)
seconds with a frame over 66 ms 4 / 88 26 / 88
seconds with a frame over 100 ms 0 1
sweeps of 20 ms or more 3 85

A standing-still pair at the same spot, uncapped: seconds whose longest frame was more than 40 ms above that second's median went from 21/60 to 1/60.

Notes

  • VICTORY_RELEASE_APART=0 restores the old behaviour.
  • Only the three sweep-time trims use it: trim_spare_uploads, trim_spare_chunks and send::trim. Other drops are unchanged.
  • Tests: cargo test -p victory-gpu --lib gives 920 passed, 2 failed. Both failures predate this PR:
    • shader_cache::tests::every_switch_of_the_translator_is_in_the_key fails on main without this change.
    • card_steps::places_written_after_sending_are_learned is flaky and passes when run alone.
  • Clippy: cargo clippy -p victory-gpu --all-targets -- -D warnings reports the same 4 errors as main, none of them new.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TqPhfCMSaeRyntpNrQy31k

**@⁠Colej1921** on GitHub · 2026-11-30 12:47 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951) `Colej1921:fix/sweep-release-off-thread` → `main` · +69 −7 · 2 files · 2 commits · closed without merging ## What Fixes a frame hitch that happened about once a second. Under memory pressure, the once-a-second sweep (`host.rs` `sweep()`) now releases the spares it trims on a background thread (`victory-release`). Before, it released them on the submitting thread. ## Why The sweep runs on the submitting thread, before a submission starts. While the PC is under host memory pressure, which can happen even on a 32 GB PC (1–2 GB free while the title runs), the sweep trims three kinds of spare: - scratch chunks - copy sources - send memory Releasing those D3D12 buffers took **22–45 ms every second**: - 7–24 ms releasing scratch chunks (`trim_spare_chunks`) - 11–15 ms releasing send memory (`send::trim`) As a result, one frame came in late in nearly every second, even at a steady 30 fps. I found this with per-step timing of the sweep (not included in this PR). No list names what a trim lets go of: a list holds what it records until it is reset. So only the release itself is left, and D3D12 objects are free-threaded. The release thread holds none of our locks. ## Measured Rig: Ryzen 7 7700X, RTX 4070 SUPER, 32 GB, Series S profile, DLSS frame generation 2x, 30 fps cap. Two 90-second walks with the game focused, on the same build, with only `VICTORY_RELEASE_APART` different: | | `VICTORY_RELEASE_APART` on (default) | `=0` (as before) | |---|---|---| | seconds with a frame over 66 ms | **4 / 88** | 26 / 88 | | seconds with a frame over 100 ms | 0 | 1 | | sweeps of 20 ms or more | **3** | 85 | A standing-still pair at the same spot, uncapped: seconds whose longest frame was more than 40 ms above that second's median went from 21/60 to 1/60. ## Notes - `VICTORY_RELEASE_APART=0` restores the old behaviour. - Only the three sweep-time trims use it: `trim_spare_uploads`, `trim_spare_chunks` and `send::trim`. Other drops are unchanged. - **Tests:** `cargo test -p victory-gpu --lib` gives 920 passed, 2 failed. Both failures predate this PR: - `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` fails on `main` without this change. - `card_steps::places_written_after_sending_are_learned` is flaky and passes when run alone. - **Clippy:** `cargo clippy -p victory-gpu --all-targets -- -D warnings` reports the same 4 errors as `main`, none of them new. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01TqPhfCMSaeRyntpNrQy31k
The once-a-second sweep runs on the submitting thread. Under the PC's
memory pressure (1-2 GB of a 32 GB PC free while the title runs) it trims
the spare scratch chunks, copy sources and send memory, and releasing those
D3D12 buffers took 22-45 ms every second: 7-24 ms for scratch chunks and
11-15 ms for send memory. One frame came late in nearly every second at a
steady 30 (Ryzen 7 7700X, RTX 4070 SUPER).

What a trim lets go of is named by no list, so only the release is left;
it now happens on a thread of its own (victory-release). The same 90 s
walk, focused, 30 fps cap and frame generation on, with only the switch
different: seconds with a frame over 66 ms went from 26 of 88 to 4 of 88,
and sweeps of 20 ms or more from 85 to 3.

VICTORY_RELEASE_APART=0 releases on the caller's thread, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TqPhfCMSaeRyntpNrQy31k
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 12:51:35 +00:00
trim_spare_chunks is also called by xmem's retry of a commit refused at the
limit and by the F7 hard flush, which both need the chunks gone before they
go on; handing them to victory-release made that retry run while they were
still alive. Only the sweep releases them apart now (trim_spare_chunks_by);
trim_spare_chunks drops them before it returns, as before.

release_apart keeps the Sender without a Mutex (Sender is Sync).

Found by review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TqPhfCMSaeRyntpNrQy31k
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 13:10 UTC · original

I checked the release queue at 202d3f13. The fix already keeps xmem/F7 scratch release synchronous. The sweep queue itself is still unbounded. A blocked driver release can leave old batches alive while the pools replenish, even though their counters no longer include those batches.

The follow-up budgets logical bytes across queued and currently releasing batches. Each batch holds its charge through the last resource drop. Admission uses at most 256 MiB, or one eighth of sampled host headroom when lower. A batch that cannot fit, or one trimmed under critical commit pressure, releases on the caller. This can bring back the release hitch on an overloaded worker. It bounds deferred work and the existing immediate paths still release inline.

For a standalone RTX 4060 test I blocked a 32 MiB batch inside its destructor, queued a 16 MiB batch and tried another 16 MiB with a 48 MiB test cap. DXGI non-local usage went 92 → 76 MiB while the worker was still blocked and then 76 → 28 MiB after it ran again. The original unbounded enqueue also reproduced the pending overflow in an isolated blocked-destructor fixture. 17 diagnostics tests passed and the two queue tests passed on WARP. The test uses artificial delay and does not measure frame time.

Companion commit

**@⁠tyr0nsur** on GitHub · 2026-11-30 13:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951#issuecomment-7279462482) I checked the release queue at `202d3f13`. The fix already keeps xmem/F7 scratch release synchronous. The sweep queue itself is still unbounded. A blocked driver release can leave old batches alive while the pools replenish, even though their counters no longer include those batches. The follow-up budgets logical bytes across queued and currently releasing batches. Each batch holds its charge through the last resource drop. Admission uses at most 256 MiB, or one eighth of sampled host headroom when lower. A batch that cannot fit, or one trimmed under critical commit pressure, releases on the caller. This can bring back the release hitch on an overloaded worker. It bounds deferred work and the existing immediate paths still release inline. For a standalone RTX 4060 test I blocked a 32 MiB batch inside its destructor, queued a 16 MiB batch and tried another 16 MiB with a 48 MiB test cap. DXGI non-local usage went **92 → 76 MiB** while the worker was still blocked and then **76 → 28 MiB** after it ran again. The original unbounded enqueue also reproduced the pending overflow in an isolated blocked-destructor fixture. 17 diagnostics tests passed and the two queue tests passed on WARP. The test uses artificial delay and does not measure frame time. [Companion commit](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/cfff9bd89ff8ac29f7ebe0834bbcb0f10e084bf3)
Author
Owner

@⁠dyshay on GitHub · 2026-11-30 14:53 UTC · original

Merged for testing into our integration branch dyshay/VIctory-NVIDIA janus-prs (adapted: release apart in the sweep and send::trim; trim_spare_chunks stays synchronous). Builds and the targeted CPU tests pass; a run on an RTX 4090 (Series S, hardware RT) is queued and I'll post the result here.

**@⁠dyshay** on GitHub · 2026-11-30 14:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951#issuecomment-7282099783) Merged for testing into our integration branch [dyshay/VIctory-NVIDIA `janus-prs`](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs) (adapted: release apart in the sweep and `send::trim`; `trim_spare_chunks` stays synchronous). Builds and the targeted CPU tests pass; a run on an RTX 4090 (Series S, hardware RT) is queued and I'll post the result here.
github-bot closed this pull request 2026-12-01 18:50:56 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:47 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:47 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951#issuecomment-7321556175) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3951
No description provided.