GPU: let go of the idle snapshot pool, and shrink it under memory pressure #41
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
needs-logs
old-names
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!41
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-41"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@welisonzika14-jpg on GitHub · 2026-11-26 17:58 UTC · original
welisonzika14-jpg:fix/shadow-pool-idle→main· +156 −0 · 1 files · 2 commits · merged 2026-11-26 19:39 UTCProblem
shadow::POOLkeeps snapshot buffers for reuse, up to 512 MiB (give_back,KEPT). Onlygive_backever trims it, and only when another buffer comes back. So once snapshots stop, the last 512 MiB stays for the rest of the run, even when the host is short of memory. The largest buffer is always kept (kept > 0), so a single snapshot larger than 512 MiB stays too.Change
shadow::let_go_idlealready runs once a second fromhost::sweep. It now first callslet_go_idle_snapshots, which does this:host::ram_idle_msand 4 frames (the same rule as the loose windows), it frees all of it.residency::pressured()holds, it keeps only the smallest buffers, up to 32 MiB (POOL_PRESSURED_KEPT), and frees the rest, largest first.pooledandgive_backrecord the last use inPOOL_USED, as ahost::moment(). The freeing happens outside the lock, asgive_backalready does. The next snapshot after a trim is fresh memory, the same as every snapshot past the pool was before. With plenty of free RAM,ram_idle_msis 5 minutes, so normal play keeps the pool. The FPS cost should only show after an idle stretch or under pressure. I did not measure FPS in game.Tests
New
shadow::pool_tests:trimming_keeps_the_smallest_up_to_the_limittrimming_to_nothing_empties_the_poola_buffer_past_the_limit_goes_even_alonean_idle_pool_goes_and_a_pressed_one_shrinkspool_memory_load(#[ignore], run alone, because the pool is global):cargo test -p victory-gpu --lib shadow::pool_tests::pool_memory_load -- --ignored --nocapture --test-threads=1Load test on Windows 11 with an RTX 5070, in a debug build. It runs 256 snapshots of 1 to 32 MiB:
Results:
cargo test -p victory-gpu --lib: 401 passed, 0 failed, 37 ignored.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: clean.Related: HumanlyDev/HUMAN#7 also bounds this pool, in a different way. This PR is written separately and is smaller. It touches only
shadow.rs.Written with AI help (Claude/Kiro).
@TaynanGT on GitHub · 2026-11-26 19:18 UTC · original
The sweep drops returned buffers outside the pool mutex. One ordering detail needs attention before integration. A worker can return a buffer between checking
POOL_USEDand taking the mutex, so an idle sweep can discard a newly used buffer. Please take the idle decision under the same lock that records the last use. The 32 MiB figure should also be described as the post-sweep target, sincegive_backcan refill the pool before the next sweep.@TaynanGT on GitHub · 2026-11-26 19:21 UTC · original · reviewed
Here are the three edits for the idle-sweep race. Please batch them together. Both paths that touch the pool record their activity under its mutex, and the sweep checks that timestamp before trimming under the same mutex. The RAM and pressure queries and the buffer drops remain outside the lock.
@TaynanGT on GitHub · 2026-11-26 19:21 UTC · original
On
crates/victory-gpu/src/shadow.rsline 1272 (outdated):Move the
POOL_USED.store(...)to immediately after this lock acquisition.@TaynanGT on GitHub · 2026-11-26 19:21 UTC · original
On
crates/victory-gpu/src/shadow.rsline 1308 (outdated):Move the
POOL_USED.store(...)to immediately after this lock acquisition.@TaynanGT on GitHub · 2026-11-26 19:21 UTC · original
On
crates/victory-gpu/src/shadow.rsline 1352 (outdated):Replace the lines from
let idle = ...through thistrim_poolcall with the block below. Keep the closing};anddrop(gone)after it.@efsebayern on GitHub · 2026-11-26 19:29 UTC · original
I tested a local follow-up on
bd270273on Windows 11 with an i7-13700K and RTX 4080 SUPER. It keeps the pool's last-use timestamp under the same mutex as returns, takes, and the idle decision, as requested in the review. The RAM and pressure queries and the buffer drops stay outside the lock.The synthetic memory load still passed. The patched process held about 25 MiB of extra private memory after the pressure sweep and returned to its starting level after the idle trim. The 32 MiB cap is a post-sweep target.
The same local patch also keeps the buffers sorted by capacity and allocates fresh buffers outside the mutex. In a synthetic release benchmark with eight threads and 80,000 take/return pairs, median wall time fell from 200.5 ms to 37.3 ms over six alternating runs per build. That number covers the combined local patch and measures the pool only. I would keep the buffer-search optimization as a separate follow-up after #41 lands.
The
victory-gpurelease suite reported 402 passed, 0 failed, 38 ignored. Both ignored load tests were run separately and passed. Package Clippy with all features and the asset check also passed. AI-assisted with Codex.@TaynanGT on GitHub · 2026-11-26 19:34 UTC · original
@efsebayern, the pressure and idle measurements are helpful. I added the mutex-ordering fix in
4ff4ea1while keeping the capacity search unchanged. The 32 MiB target applies after a sweep. The 200.5 ms to 37.3 ms result came from the combined synthetic benchmark, so the search and allocation changes can be measured separately in a follow-up.