host, send, uav_pool: trim only unborrowed low-water spare pools at 1 Hz sweep #3381

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

@⁠Maverick0351a on GitHub · 2026-11-29 22:32 UTC · original
Maverick0351a:fix/sweep-spare-low-watermark → main · +49 −10 · 2 files · 1 commits · open

Summary

  • sweep() runs once per second (1 Hz) inside Host::submit when !behind (all in-flight submissions have landed, so 100% of the active per-frame D3D12 upload, scratch, submission-send, and UAV buffers have just been returned to the spare pools).
  • On 32 GB hosts where physical_free < 5 GiB (pressured() == true and keeps_under_pressure() == false, even with > 60 GiB of commit headroom available), the 1 Hz sweep() previously called immediate trim_to(16 MiB) / trim_to(0) on UPLOAD_SPARE, SPARE, SPARE_SHARED, UAV_SPARE, and send::SPARE:
    • send::trim() did not track a low-water mark (low), removed the largest buffers first (spare.remove(0)), and dropped ID3D12Resource inside SPARE.lock().
    • trim_spare_uploads(), trim_spare_chunks(), and uav_pool::sweep_uav_spare() used trim_to instead of Spare::trim_above(most), destroying 80-150 MiB of the active per-frame working set every second at !behind only for the very next frame to stall for 20-253 ms calling CreateCommittedResource + Map in D3D12 (frame_times: 27 frames, median 35.6 ms, p99 52-115 ms; 1 over 50 ms at 1 Hz; VICTORY_SEND_OWN: 27-253 ms taking them out of the CPU sides).
  • This PR:
    1. Tracks (kept, bytes, low) in send::SPARE, evicts only the unborrowed low-water surplus (spare.low.saturating_sub(floor)) in send::trim() unless critical_commit() is true, and drops evicted ID3D12Resource allocations outside SPARE.lock().
    2. Uses Spare::trim_above in the 1 Hz sweep() hooks (trim_spare_uploads(), sweep_spare_chunks(), and uav_pool::sweep_uav_spare()) when !critical_commit(), while preserving immediate trim_spare_chunks() for F7 hard flush (drop_spare_chunks()), xmem fallback, and tests.
**@⁠Maverick0351a** on GitHub · 2026-11-29 22:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381) `Maverick0351a:fix/sweep-spare-low-watermark` → `main` · +49 −10 · 2 files · 1 commits · open ## Summary - `sweep()` runs once per second (`1 Hz`) inside `Host::submit` when `!behind` (all in-flight submissions have landed, so 100% of the active per-frame D3D12 upload, scratch, submission-send, and UAV buffers have just been returned to the spare pools). - On 32 GB hosts where `physical_free < 5 GiB` (`pressured() == true` and `keeps_under_pressure() == false`, even with > 60 GiB of commit headroom available), the 1 Hz `sweep()` previously called immediate `trim_to(16 MiB)` / `trim_to(0)` on `UPLOAD_SPARE`, `SPARE`, `SPARE_SHARED`, `UAV_SPARE`, and `send::SPARE`: - `send::trim()` did not track a low-water mark (`low`), removed the largest buffers first (`spare.remove(0)`), and dropped `ID3D12Resource` inside `SPARE.lock()`. - `trim_spare_uploads()`, `trim_spare_chunks()`, and `uav_pool::sweep_uav_spare()` used `trim_to` instead of `Spare::trim_above(most)`, destroying `80-150 MiB` of the active per-frame working set every second at `!behind` only for the very next frame to stall for `20-253 ms` calling `CreateCommittedResource` + `Map` in D3D12 (`frame_times: 27 frames, median 35.6 ms, p99 52-115 ms; 1 over 50 ms` at 1 Hz; `VICTORY_SEND_OWN: 27-253 ms taking them out of the CPU sides`). - This PR: 1. Tracks `(kept, bytes, low)` in `send::SPARE`, evicts only the unborrowed low-water surplus (`spare.low.saturating_sub(floor)`) in `send::trim()` unless `critical_commit()` is true, and drops evicted `ID3D12Resource` allocations outside `SPARE.lock()`. 2. Uses `Spare::trim_above` in the 1 Hz `sweep()` hooks (`trim_spare_uploads()`, `sweep_spare_chunks()`, and `uav_pool::sweep_uav_spare()`) when `!critical_commit()`, while preserving immediate `trim_spare_chunks()` for F7 hard flush (`drop_spare_chunks()`), `xmem` fallback, and tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 22:35:09 +00:00
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 07:39 UTC · original

I reproduced a send-cache regression at 5cd08d8. In give_back, the cap loop removes the first entry after appending the newly returned buffer. If that buffer is larger than the entire cap, the loop evicts every existing spare before dropping the oversized buffer too. In a deterministic test with a 128 MiB cap, a 2 GiB one-shot return unnecessarily evicted the existing 16 and 64 MiB spares. This can happen with a large exact-size send from #3729 as well.

Cherry-pickable commit 8fb4ea9 restores the original largest-first cap eviction and preserves the remaining buffers' return order for the low-water trim. It reuses the host Spare accounting and drops the released buffers outside the lock. Both new tests failed with the original cap behavior and passed with the fix. On Windows, the spare filter passed 11 tests. I also applied this PR plus the follow-up and #3729 together on 41adb551; all six send unit tests passed there (two hardware probes were ignored). Staged asset policy passed.

Tested cache behavior only. In two existing RTX 4060/32 GB .05 logs, host pressure was logged but the 4 GiB upload refusal did not appear. No in-game timing measurement for this patch. Reviewed and tested with Codex assistance.

**@⁠tyr0nsur** on GitHub · 2026-11-30 07:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7271981682) I reproduced a send-cache regression at `5cd08d8`. In `give_back`, the cap loop removes the first entry after appending the newly returned buffer. If that buffer is larger than the entire cap, the loop evicts every existing spare before dropping the oversized buffer too. In a deterministic test with a 128 MiB cap, a 2 GiB one-shot return unnecessarily evicted the existing 16 and 64 MiB spares. This can happen with a large exact-size send from #3729 as well. [Cherry-pickable commit `8fb4ea9`](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/8fb4ea9d4e32aaeffdd1ec098a31d82266244871) restores the original largest-first cap eviction and preserves the remaining buffers' return order for the low-water trim. It reuses the host `Spare` accounting and drops the released buffers outside the lock. Both new tests failed with the original cap behavior and passed with the fix. On Windows, the spare filter passed 11 tests. I also applied this PR plus the follow-up and #3729 together on `41adb551`; all six send unit tests passed there (two hardware probes were ignored). Staged asset policy passed. Tested cache behavior only. In two existing RTX 4060/32 GB `.05` logs, host pressure was logged but the 4 GiB upload refusal did not appear. No in-game timing measurement for this patch. Reviewed and tested with Codex assistance.
Author
Owner

@⁠dyshay on GitHub · 2026-11-30 08:55 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched code pass. A run on an RTX 4090 is queued. Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-30 08:55 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7273518540) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched code pass. A run on an RTX 4090 is queued. Frame times will follow here.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-30 14:01 UTC · original

Measured this side by side with the other fixes for the same send-spare churn on an RTX 5080 + 9800X3D, 32 GB (where pressured() always holds), on vnv 829188e9 + #3347. Walking, Series X native 1440p, DLSS off, 300 s windows; first round, one run each:

arm fps >100 ms per 1,000 send trim per sweep card copies
base 19.5 55.4 68.0 ms 10.6 ms
this PR 21.7 35.0 9.3 ms 6.3 ms
#3411 20.2 52.5 4.9 ms 6.3 ms
#3994 (per-size window, release off the submitting thread) 20.3 52.1 0.0 ms 6.1 ms

This PR had the best fps and the fewest long frames in this round. The second round is running and I'll post it here. The 9.3 ms left in this PR's trim step is spent on the submitting thread; #3994 moves the release to its own thread, so the two could combine.

AI use: Claude Code (Claude Opus 5.5).

**@⁠Lyrnc** on GitHub · 2026-11-30 14:01 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7280714275) Measured this side by side with the other fixes for the same send-spare churn on an RTX 5080 + 9800X3D, **32 GB** (where `pressured()` always holds), on vnv 829188e9 + #3347. Walking, Series X native 1440p, DLSS off, 300 s windows; first round, one run each: | arm | fps | >100 ms per 1,000 | send trim per sweep | card copies | |---|---:|---:|---:|---:| | base | 19.5 | 55.4 | 68.0 ms | 10.6 ms | | **this PR** | **21.7** | **35.0** | 9.3 ms | 6.3 ms | | #3411 | 20.2 | 52.5 | 4.9 ms | 6.3 ms | | #3994 (per-size window, release off the submitting thread) | 20.3 | 52.1 | 0.0 ms | 6.1 ms | This PR had the best fps and the fewest long frames in this round. The second round is running and I'll post it here. The 9.3 ms left in this PR's trim step is spent on the submitting thread; #3994 moves the release to its own thread, so the two could combine. AI use: Claude Code (Claude Opus 5.5).
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-30 14:13 UTC · original

Shootout, final (2 runs per arm): RTX 5080 + 9800X3D, 32 GB, vnv 829188e9 + #3347, walking, Series X native 1440p, DLSS off, world +30..330 s. Every arm has the same local per-step sweep timing.

arm fps (2 runs) >100 ms per 1,000 send trim per sweep (submitting thread) card copies send buffers made / let go in 300 s largest kept spare
base 19.5 / 19.7 55.4 / 51.6 68.0 / 73.5 ms 10.6 / 10.0 ms (every second) n/a
#3994 (8b801739) 20.3 / 21.4 52.1 / 39.0 0.0 / 0.0 ms 6.1 / 6.2 ms 6/4, 7/4 416–480 MiB
#3381 21.7 / 20.1 35.0 / 46.3 9.3 / 9.2 ms 6.3 / 6.5 ms n/a n/a
#3411 (bundle) 20.2 / 20.8 52.5 / 45.4 4.9 / 4.9 ms 6.3 / 6.1 ms n/a n/a
  • Means: base 19.6 fps; #3994 20.9, #3381 20.9, #3411 20.5. Frames over 100 ms: 53.5 → 45.6 / 40.7 / 49.0.
  • The churn: all three remove it. Card copies drop from ~10.3 to ~6.2 ms, and heaps+sweep from 8.2 to 3.6–4.5 ms. No new stalls in any arm.
  • Where they differ: #3994 is the only one that leaves 0 ms of send trim on the submitting thread, since releases go to their own thread. #3381 still trims about 9 ms per sweep there. The fps differences are within run noise.
  • What none of them touches: the rest of the sweep, the resource let-go looks at 47–60 ms per sweep. #3272 takes care of those.

AI use: Claude Code (Claude Opus 5.5).

**@⁠Lyrnc** on GitHub · 2026-11-30 14:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7281025079) **Shootout, final (2 runs per arm)**: RTX 5080 + 9800X3D, **32 GB**, vnv 829188e9 + #3347, walking, Series X native 1440p, DLSS off, world +30..330 s. Every arm has the same local per-step sweep timing. | arm | fps (2 runs) | >100 ms per 1,000 | send trim per sweep (submitting thread) | card copies | send buffers made / let go in 300 s | largest kept spare | |---|---:|---:|---:|---:|---:|---:| | base | 19.5 / 19.7 | 55.4 / 51.6 | 68.0 / 73.5 ms | 10.6 / 10.0 ms | (every second) | n/a | | #3994 (8b801739) | 20.3 / 21.4 | 52.1 / 39.0 | **0.0 / 0.0 ms** | 6.1 / 6.2 ms | 6/4, 7/4 | 416–480 MiB | | #3381 | 21.7 / 20.1 | 35.0 / 46.3 | 9.3 / 9.2 ms | 6.3 / 6.5 ms | n/a | n/a | | #3411 (bundle) | 20.2 / 20.8 | 52.5 / 45.4 | 4.9 / 4.9 ms | 6.3 / 6.1 ms | n/a | n/a | - **Means:** base 19.6 fps; #3994 20.9, #3381 20.9, #3411 20.5. Frames over 100 ms: 53.5 → 45.6 / 40.7 / 49.0. - **The churn:** all three remove it. Card copies drop from ~10.3 to ~6.2 ms, and heaps+sweep from 8.2 to 3.6–4.5 ms. No new stalls in any arm. - **Where they differ:** #3994 is the only one that leaves 0 ms of send trim on the submitting thread, since releases go to their own thread. #3381 still trims about 9 ms per sweep there. The fps differences are within run noise. - **What none of them touches:** the rest of the sweep, the resource let-go looks at 47–60 ms per sweep. #3272 takes care of those. AI use: Claude Code (Claude Opus 5.5).
github-bot force-pushed github-bot/gh-3381 from 5cd08d87bd to a433e1ac0f 2026-11-30 21:35:12 +00:00 Compare
github-bot force-pushed github-bot/gh-3381 from a433e1ac0f to c637ae56a6 2026-12-01 02:59:01 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
The changes on this branch are already on the target branch. This will be an empty commit.
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/3381/head:github-bot/gh-3381'
git switch 'github-bot/gh-3381'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3381'
git switch 'github-bot/gh-3381'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3381'
git switch 'github-bot/gh-3381'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3381'
git switch 'main'
git merge --squash 'github-bot/gh-3381'
git switch 'main'
git merge --ff-only 'github-bot/gh-3381'
git switch 'main'
git merge 'github-bot/gh-3381'
git push origin 'main'
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!3381
No description provided.