pool: use a 250 ms quarantine for STAGING pieces #279
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!279
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-279"
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?
@deyvideguilherme on GitHub · 2026-12-03 01:43 UTC · original
deyvideguilherme:fix/staging-rest-ms→main· +136 −2 · 1 files · 1 commits · closed without mergingSummary
Separates the post-return quarantine duration for
pool::STAGING(STAGING_REST = 250 ms) frompool::TEXTURES(REST = 5000 ms) incrates/victory-gpu/src/pool.rs.Problem
Pool::give()previously quarantined returned upload-heap slices inSTAGINGfor the sameREST = 5000 msused by placed VRAM textures inTEXTURES. During sustained texture streaming bursts on a 16 GiB RAM host, holding already-completed staging slices inrestingfor 5 seconds prevented slice reuse and overflow block reclamation. In baseline testing,pool::STAGINGgrew up to 1280–1920 MiB (20–30 × 64 MiB blocks in GTT/system RAM), contributing to elevated GTT occupancy and lowering available system RAM below 1000 MiB during peak streaming.Rationale
TEXTURESandSTAGINGhave different post-return lifetimes:TEXTURES(REST = 5000 ms, unchanged): placed VRAM heaps may still be referenced indirectly by bindless descriptors or pending submissions, so keeping the 5000 ms quarantine preserves existing behavior.STAGING(STAGING_REST = 250 ms): upload-heap slices are only used as copy sources and are dropped after their upload copies have completed. ParameterizingPool::with_rest(most, rest_ms)keepsTEXTURESat5000 mswhile allowingSTAGINGblocks to be reused and excess blocks aboveSTAGING_KEPTto be reclaimed sooner.Synchronization Audit
StagingPieceis owned exclusively byStaging._piece(crates/victory-gpu/src/texture.rs) and is returned toSTAGINGonly inDrop for StagingPiece:HostList::defer_texture):HostList::deferred().copiesretains a strongArc<Staging>untilHostList::reset()runs after the corresponding flight fence completes.texture::ahead): eachJobretains a strongArc<Staging>and waits for fence completion viaSetEventOnCompletionbeforefinish(jobs)drops the job batch.texture::let_go_idle): only evicts entries whenArc::strong_count == 1.reclaim()continue to go throughcrate::host::retire(block)before destruction.Because
Drop for StagingPieceruns after fence completion on both upload paths,REST = 5000 msis not the primary synchronization mechanism for upload copies;STAGING_REST = 250 msretains a conservative delay before slice reuse and block reclaim.Verification
Unit Tests & Build
pool::tests:11 passed; 0 failed, including two new deterministic tests coveringSTAGING_RESTvsRESTboundary behavior, overflow reclaim, and multi-threaded non-overlapping borrow/return../build.sh): completed with 0 warnings and 0 errors.A/B Gameplay Sessions
All three sessions were recorded on the same host and configuration (
mainbaselinefc79d68vs two separate confirmation sessions withSTAGING_REST = 250 ms). All runs exited cleanly with exit code 0 and 0 runtimeERRORlog entries.fc79d68,REST = 5000 ms)STAGING_REST = 250 ms)STAGING_REST = 250 ms)pool::STAGINGp50 / p90 / p99 / max (MiB)Test Environment
15906 MiB) + 15.5 GiB zram7.3.6-3-cachyos),amdgpu.gttsize=12288, Proton Experimental (ntsync)Limitations & Residual Risks
pool::STAGINGstill settles around 320–384 MiB (5–6 × 64 MiB blocks) due to longer-lived referenced staging entries; this change only addresses unnecessary quarantine retention after pieces are returned.250 ms): chosen as a conservative margin below5000 msrather than0 ms; optimal tuning across all drivers and workloads was not explored.@Kal0s-design on GitHub · 2026-12-03 19:17 UTC · original
Tested
efe81baon Windows 11 with a native MSVC build and toolchain 1.98.1. These are unit tests only and nothing was run in game.I went through the synchronization audit on the PR head and it matches the code as far as I can see. The piece only lives inside Staging (texture.rs:49, made at texture.rs:2511), so it goes back to the pool when the last Arc is dropped. Uploads deferred with defer_texture (host.rs:5995) stay in deferred().copies until reset() (host.rs:4694), and nothing removes steps from there earlier. Late flights are recycled only once the relay sees GetCompletedValue() reach their fence (host.rs:3124-3125), and the relay polls again after a failed wait instead of landing anything (host.rs:3154-3156). The sync path waits on the event before returning (host.rs:4277-4287). Ahead jobs keep their Arc until finish(jobs) after the wait (texture/ahead.rs:266-269, 287-291). let_go_idle checks strong_count with the table lock held (texture.rs:940-953). Every clone taken out of the table happens under that same lock (texture.rs:2466, 2300), and I found no Weak, so the count can't go up between the check and the removal. forget() and unstage() (texture.rs:1089, 2066) remove from the table unconditionally, but a list that recorded a copy holds its own Arc, so the same argument covers them. Blocks that reclaim() drops go through host::retire (pool.rs:63, 629), which waits for every submission begun so far plus BURY_LAG (host.rs:362-366, 392). A removed device ends the run through fail().
There's one gap, and it isn't new in this PR. In two places a failed fence wait gets logged and the code carries on after the copy may already have been sent. In host.rs:4277-4290, if Signal or SetEventOnCompletion fails it warns "host submission not waited for" and continues. fail() only runs if the device was removed, so otherwise the caller resets the lists and can drop the last Arc while the copy is still running. texture/ahead.rs:266-269 does the same thing. An error from Signal or SetEventOnCompletion after ExecuteCommandLists (line 287) only warns, and then finish(jobs) drops the jobs. Main has the same code (host.rs:4724 there), and it needs a D3D12 call to fail first. The REST comment (pool.rs:76-79) says the 5 s was meant to let in-flight work and deferred lists drain, and those two paths are exactly where the new STAGING_REST comment's assumption that copies have completed doesn't hold. Making them fatal, or keeping the lists until a later wait succeeds, would close it. I don't think it blocks this PR.
cargo test -p victory-gpu --lib pool:: passes 11 of 11 in debug and in release. I ran the two new tests 20 times on the debug binary and 20 times on the release one and all 40 runs passed. Neither test uses sleeps or the wall clock. Time is a now value passed in, or an atomic counter in the threaded test, so Windows timer granularity doesn't affect the 249/250 boundary. One thing about staging_rest_concurrent_borrow_and_return_never_overlaps is that it only checks that live pieces never overlap. I changed its pool to with_rest(STAGING_KEPT, 0) locally and it still passed, so it doesn't cover the quarantine. The other new test does cover the boundary. Both build their own Pool, so the STAGING static at pool.rs:493 is only checked by reading it.
The full run was cargo test -p victory-gpu --lib -- --test-threads=4 with --skip descriptor::tests::views_die_with_their_resource, because that test crashes on main too. The PR head gives 312 passed, 4 failed and 23 ignored. Main at
00aa4d3gives 338 passed, 5 failed and 23 ignored. The totals differ because the branch is 156 commits behind main. The same four tests fail on both, two indirect::tests::host_list_* and two pipeline::host::tests::*. Main's fifth failure, watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own, passes on the branch. The branch merges into main cleanly, and pool.rs, texture.rs and texture/ahead.rs haven't changed on main since the branch point.cargo clippy -p victory-gpu --all-targets shows no warnings in the changed lines. The only warning in pool.rs is too_many_arguments on take_piece, which was already on main.
AI-assisted: yes
@Luxuride on GitHub · 2026-12-04 12:09 UTC · original · edited 2026-12-05 11:22 UTC
Right fix, wrong branch: this has already been ported to the current pool by an open pull request, and the port is the safer version.
What I checked on
main@0fd7614:26b70f7("pool: 250 ms staging quarantine on top of the fence reuse"), whose message says it is a port of this PR. It applies the rest on the fence path (Pool::by_fence) rather than a bare clock.fc79d68) has no fence at all, so the only thing protecting an upload buffer from a GPU still reading it is a wall-clock timer —crates/victory-gpu/src/pool.rs:435(now + self.rest_ms). On the current pool the fence already proves the work retired; the timer is a backstop, not the mechanism.So what I can say is that the code is in
mainnow, that the 250 ms staging value and the test idea came from here, and that your name belongs on the ported commit's author line if it is not already there. What is left for this PR to do is the maintainer's call, not mine.For the record,
crates/victory-gpu/src/pool.rs:86(STAGING_REST) still has no derivation beyond "shorter than the 5 s rest"; if you know what the clock must actually cover, that comment is worth porting too.@deyvideguilherme on GitHub · 2026-12-04 12:32 UTC · original
@Luxuride Thanks for the review and the explanation! It makes total sense that the fence-backed path in #393 is the safer implementation for the current main. I’m glad the 250 ms logic and the test concepts were useful and got ported over successfully.
Regarding the 250 ms value itself: it was chosen empirically during our A/B testing on a 16GB RDNA 4 setup as a safe, conservative margin below 5000 ms to allow rapid upload-heap block reuse during heavy streaming bursts, without risking premature eviction. We didn't want to push it to 0 ms.
I'll go ahead and close this PR in favor of #393. Thanks again for the meticulous work!
Pull request closed