Reclaim idle snapshot buffers under host memory pressure #2234

Closed
LucaruluDev wants to merge 3 commits from upstream-pr/2234 into main
LucaruluDev commented 2026-11-29 10:52:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by LucaruluDev on 2026-11-29T10:52:35Z.


Refs #1620.

What it changes

The snapshot buffer pool in shadow.rs can retain
hundreds of MiB after allocation spikes, even when
smaller requests cannot reuse those buffers due to
the existing 4x capacity filter.

This change:

  • Reclaims excess idle snapshots under host memory pressure.
  • Retains a small warm pool.
  • Gives recently returned buffers a three-second reuse window.
  • Avoids repeatedly reallocating frequently used large buffers.
  • Drains idle buffers under critical commit pressure.
  • Preserves existing LowSpec limits and the 4x reuse filter.
  • Releases discarded buffers outside the pool mutex.

How it was tested

Hardware: Ryzen 7 9700X, RTX 5070 12 GB,
32 GiB DDR5, Windows 11.

Synthetic allocation spike followed by smaller requests:

Metric Before After
Retained buffer capacity 476 MiB 32 MiB
Capacity reclaimed 0 MiB 444 MiB

All 80 small requests were served from the pool
after reclamation.

Repeated 174 MiB requests under simulated
ordinary memory pressure:

  • Pool misses: 0/63.
  • Median request and fill time: 6.07 ms.
  • No-pressure control: 6.03 ms.

Tests:

  • 76 shadow tests passed.
  • 5 ignored.
  • 0 failures.

No shader changes.

These measurements represent retained vector
capacity, not process working set or committed
memory. Gameplay FPS and frame times have not
been measured.

Requests returning after the idle grace period
may require a new allocation.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.

Related: #1620, #479, #2015.

Inspired by the demand-aware trimming approach in
Marvisak/VIctory#3230, independently implemented
for the current NVIDIA codebase.

AI-assisted implementation and validation using
Claude Code and OpenAI Codex.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5550001860 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2234). Originally posted by [LucaruluDev](https://github.com/LucaruluDev) on 2026-11-29T10:52:35Z. --- Refs #1620. ## What it changes The snapshot buffer pool in `shadow.rs` can retain hundreds of MiB after allocation spikes, even when smaller requests cannot reuse those buffers due to the existing 4x capacity filter. This change: - Reclaims excess idle snapshots under host memory pressure. - Retains a small warm pool. - Gives recently returned buffers a three-second reuse window. - Avoids repeatedly reallocating frequently used large buffers. - Drains idle buffers under critical commit pressure. - Preserves existing LowSpec limits and the 4x reuse filter. - Releases discarded buffers outside the pool mutex. ## How it was tested Hardware: Ryzen 7 9700X, RTX 5070 12 GB, 32 GiB DDR5, Windows 11. Synthetic allocation spike followed by smaller requests: | Metric | Before | After | |---|---:|---:| | Retained buffer capacity | 476 MiB | 32 MiB | | Capacity reclaimed | 0 MiB | 444 MiB | All 80 small requests were served from the pool after reclamation. Repeated 174 MiB requests under simulated ordinary memory pressure: - Pool misses: 0/63. - Median request and fill time: 6.07 ms. - No-pressure control: 6.03 ms. Tests: - 76 shadow tests passed. - 5 ignored. - 0 failures. No shader changes. These measurements represent retained vector capacity, not process working set or committed memory. Gameplay FPS and frame times have not been measured. Requests returning after the idle grace period may require a new allocation. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1620, #479, #2015. Inspired by the demand-aware trimming approach in Marvisak/VIctory#3230, independently implemented for the current NVIDIA codebase. AI-assisted implementation and validation using Claude Code and OpenAI Codex.
ArturoWolff commented 2026-11-29 11:35:01 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ArturoWolff on 2026-11-29T11:35:01Z.


Thanks for keeping the capacity and resident-memory claims separate. This is a promising idle-memory optimization for smaller hosts. A source review of exact ba620fe6a2d9e45d13241ace47ef33ad6a92365e found one missed diagnostics caller:

  • shadow.rs:1990–2045 changes POOL from the vector to Mutex<SnapshotPool>, whose idle entries own bytes: Vec<u8>.
  • The #[cfg(feature = "diagnostics")] memory() census at 5082–5085 still calls pool.len() and pool.iter().map(|v| v.capacity()). SnapshotPool does not provide those methods. Accessing pool.idle.len() and summing pool.idle.iter().map(|v| v.bytes.capacity() as u64) would preserve the existing count/capacity telemetry.

The default shadow tests do not compile that diagnostics-only path. The exact-head CI job stopped in default Clippy before the all-features gate; I have not established the cause of that earlier failure or run the donor locally.

Our ordinary RTX 4060 / 16 GiB GE-Proton baseline has substantial physical memory pressure, but neither retained engine log measures idle snapshot capacity (the base census is diagnostics-only). The sampled intervals between its ordinary post-pressure sweep-related memory reports reached 45.2 and 61.2 seconds. These are not observed snapshot ages; they do underline the need to measure actual reuse and reclamation cadence on a slow submission path rather than treating the three-second grace interval as a guaranteed trim/reuse latency. Once the diagnostic caller is fixed, the existing pool-capacity census plus a bounded touched-buffer reuse/drop check would help distinguish a capacity result from real RAM/paging savings. No local performance or graphical-fidelity result for this patch yet.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7255210356 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2234#issuecomment-7255210356). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-29T11:35:01Z. --- Thanks for keeping the capacity and resident-memory claims separate. This is a promising idle-memory optimization for smaller hosts. A source review of exact `ba620fe6a2d9e45d13241ace47ef33ad6a92365e` found one missed diagnostics caller: - [`shadow.rs:1990–2045`](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/ba620fe6a2d9e45d13241ace47ef33ad6a92365e/crates/victory-gpu/src/shadow.rs#L1990-L2045) changes `POOL` from the vector to `Mutex<SnapshotPool>`, whose `idle` entries own `bytes: Vec<u8>`. - The `#[cfg(feature = "diagnostics")]` [`memory()` census at 5082–5085](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/ba620fe6a2d9e45d13241ace47ef33ad6a92365e/crates/victory-gpu/src/shadow.rs#L5082-L5085) still calls `pool.len()` and `pool.iter().map(|v| v.capacity())`. `SnapshotPool` does not provide those methods. Accessing `pool.idle.len()` and summing `pool.idle.iter().map(|v| v.bytes.capacity() as u64)` would preserve the existing count/capacity telemetry. The default shadow tests do not compile that diagnostics-only path. The exact-head [CI job](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46254451331/job/141319782755) stopped in default Clippy before the all-features gate; I have not established the cause of that earlier failure or run the donor locally. Our ordinary RTX 4060 / 16 GiB GE-Proton baseline has substantial physical memory pressure, but neither retained engine log measures idle snapshot capacity (the base census is diagnostics-only). The sampled intervals between its ordinary post-pressure sweep-related memory reports reached 45.2 and 61.2 seconds. These are not observed snapshot ages; they do underline the need to measure actual reuse and reclamation cadence on a slow submission path rather than treating the three-second grace interval as a guaranteed trim/reuse latency. Once the diagnostic caller is fixed, the existing pool-capacity census plus a bounded touched-buffer reuse/drop check would help distinguish a capacity result from real RAM/paging savings. No local performance or graphical-fidelity result for this patch yet. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
LucaruluDev commented 2026-11-29 12:37:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by LucaruluDev on 2026-11-29T12:37:19Z.


Thanks for catching this, @ArturoWolff!

Fixed in a11530f. The diagnostics census now counts
idle entries and sums their buffer capacities.

Both E0599 errors are gone. I also checked the
remaining POOL accesses. The reclamation policy
is unchanged.

The diagnostics and all-features builds still
encounter the same nine compiler errors reproduced
on upstream main. The three focused tests passed.

Following your suggestion, I ran a standalone
Windows probe with touched pages and simulated
memory pressure:

Metric Reduction
Idle buffer capacity 256 MiB
Private commit 256.51 MiB
Working set 256.01 MiB

The small buffer was successfully reused, and
the checked-out buffer passed the data checks.

I agree that the three-second grace period is
not a guarantee of reclamation latency. Actual
sweep cadence and gameplay performance remain
unmeasured.

Thanks again for the detailed review!

AI-assisted validation using OpenAI Codex.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7255944644 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2234#issuecomment-7255944644). Originally posted by [LucaruluDev](https://github.com/LucaruluDev) on 2026-11-29T12:37:19Z. --- Thanks for catching this, @ArturoWolff! Fixed in a11530f. The diagnostics census now counts idle entries and sums their buffer capacities. Both E0599 errors are gone. I also checked the remaining POOL accesses. The reclamation policy is unchanged. The diagnostics and all-features builds still encounter the same nine compiler errors reproduced on upstream main. The three focused tests passed. Following your suggestion, I ran a standalone Windows probe with touched pages and simulated memory pressure: | Metric | Reduction | |---|---:| | Idle buffer capacity | 256 MiB | | Private commit | 256.51 MiB | | Working set | 256.01 MiB | The small buffer was successfully reused, and the checked-out buffer passed the data checks. I agree that the three-second grace period is not a guarantee of reclamation latency. Actual sweep cadence and gameplay performance remain unmeasured. Thanks again for the detailed review! AI-assisted validation using OpenAI Codex.
LucaruluDev commented 2026-11-30 08:38:36 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by LucaruluDev on 2026-11-30T08:38:36Z.


I rebased this PR onto main at 41adb551. The conflict in host.rs was resolved by retaining upstream's idle-list reclamation and passing the same memory-pressure flag to the snapshot-pool trim.

The published tree matches the one already validated. The shadow suite passed 77 tests (5 ignored, 0 failures), and cargo check -p victory-gpu passed in release mode and with diagnostics and --all-features.

The new CI job failed again during Clippy on the pre-existing unused unwind_copy function in victory-loader/src/crash.rs:804. The file is identical on upstream main. Clippy treated the warning as an error under -D warnings, so the diagnostics and test steps were skipped.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7273161240 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2234#issuecomment-7273161240). Originally posted by [LucaruluDev](https://github.com/LucaruluDev) on 2026-11-30T08:38:36Z. --- I rebased this PR onto `main` at `41adb551`. The conflict in `host.rs` was resolved by retaining upstream's idle-list reclamation and passing the same memory-pressure flag to the snapshot-pool trim. The published tree matches the one already validated. The `shadow` suite passed 77 tests (5 ignored, 0 failures), and `cargo check -p victory-gpu` passed in release mode and with `diagnostics` and `--all-features`. [The new CI job](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46381367040/job/141721007424) failed again during Clippy on the pre-existing unused `unwind_copy` function in `victory-loader/src/crash.rs:804`. The file is identical on upstream `main`. Clippy treated the warning as an error under `-D warnings`, so the diagnostics and test steps were skipped.
LucaruluDev commented 2026-11-30 22:07:53 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by LucaruluDev on 2026-11-30T22:07:53Z.


Thanks for integrating this contribution into main (2d3ba6a0)!

Also, thanks to @ArturoWolff for the detailed review and suggestions that helped improve the patch and its validation.

Since the functionality is now included in main, this PR can be closed.

Happy to keep contributing to the project!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7293397159 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2234#issuecomment-7293397159). Originally posted by [LucaruluDev](https://github.com/LucaruluDev) on 2026-11-30T22:07:53Z. --- Thanks for integrating this contribution into main (`2d3ba6a0`)! Also, thanks to @ArturoWolff for the detailed review and suggestions that helped improve the patch and its validation. Since the functionality is now included in main, this PR can be closed. Happy to keep contributing to the project!

Pull request closed

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!2234
No description provided.