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

Open
Maverick0351a wants to merge 1 commit from upstream-pr/3381 into main
Maverick0351a commented 2026-11-29 22:32:36 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Maverick0351a on 2026-11-29T22:32:36Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5555856527 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381). Originally posted by [Maverick0351a](https://github.com/Maverick0351a) on 2026-11-29T22:32:36Z. --- ## 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.
tyr0nsur commented 2026-11-30 07:39:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T07:39:45Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7271981682 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7271981682). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T07:39:45Z. --- 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.
dyshay commented 2026-11-30 08:55:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-30T08:55:46Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7273518540 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7273518540). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-30T08:55:46Z. --- 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.
Lyrnc commented 2026-11-30 14:01:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T14:01:20Z.


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7280714275 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7280714275). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-30T14:01:20Z. --- 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 commented 2026-11-30 14:13:12 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T14:13:12Z.


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7281025079 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3381#issuecomment-7281025079). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-30T14:13:12Z. --- **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).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3381:upstream-pr/3381'
git switch 'upstream-pr/3381'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3381'
git switch 'upstream-pr/3381'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3381'
git switch 'upstream-pr/3381'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3381'
git switch 'main'
git merge --squash 'upstream-pr/3381'
git switch 'main'
git merge --ff-only 'upstream-pr/3381'
git switch 'main'
git merge 'upstream-pr/3381'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

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