GPU: loose windows nothing has asked for go, with their memory (VICTORY_WINDOW_IDLE_SECS) #3078
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3078
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3078"
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?
@Luislariosss on GitHub · 2026-11-26 06:50 UTC · original
Luislariosss:perf/loose-window-eviction→main· +215 −7 · 3 files · 1 commits · openProblem
Loose windows — host copies of title memory that belongs to no buffer — were never freed, so a long run kept every one it had ever made. One measured world run held 1,400 of them (6.4 GB) by its end, on a machine whose RAM is what limits it.
Change
crates/victory-gpu/src/shadow.rstracks each window's last-asked time and the periodic line's sweep incrates/victory-gpu/src/host.rsfrees windows idle for 30 s (VICTORY_WINDOW_IDLE_SECS,0keeps them all) — but only ones no view, list or heap still holds, since one of those would keep reading the old copy while a later ask made another of the same range. The page tables ofcrates/victory-gpu/src/memory.rsname every copy, so their references are counted and discounted (their lock is never held with the window map's: a rewrite takes both, in the other order), and the copies' generation is bumped so the tables are rebuilt without the gone ones. A window the title comes back to is copied again.Measurement (Ryzen 5 9600X, RX 9060 XT 16 GB, 15 GB RAM)
A 902 s world run — the first on this machine to survive its whole planned length, and the farthest the title has gone:
232 tests passing, 247 with
--all-features, clippy clean in both. The new test covers the four cases: an idle window goes, a fresh one stays, one held by another reference stays, a gone one is made again.Risk
A window the title comes back to is copied again, which costs an allocation and a copy — on this machine the recycled bytes far outweighed that. Windows still held by an external
Arckeep their memory until that holder goes, by design.@Marvisak on GitHub · 2026-11-26 08:22 UTC · original
Automated triage for the maintainers.
Needs work. CI is failing:
shadow::tests::idle_loose_windows_go_and_fresh_ones_stayassertsEVICTED[0] == 1and got 2.EVICTEDandLOOSEare process-wide, andevict_older_thansweeps every loose window, including ones other tests running in parallel made. The test needs to check only its own key, or compare a before/after delta of the counter. It must not depend on global totals.Before this can be reviewed for merging, also please:
changed()only has the page tables rebuilt later, and a GPU table built from the old layout may still name the evicted copy's GPU address. Say what keeps that buffer alive until the GPU is done with it.tracing::info!line inMeterbehinddiagnosticslike the other counters.loose_statsandEVICTEDare documented as diagnostics.The memory win in the description is worth having. The verdict changes once CI is green and the in-flight lifetime is shown.
Generated by Claude Code
4a8176ab9fto3e937d3780@Dukestar69 on GitHub · 2026-11-26 06:55 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):LOOSEwindows and evicting idle windows (VICTORY_WINDOW_IDLE_SECS, default 30 s) only whenArc::strong_count == 2 + shared_refs(so no live view, list, or heap still holds a reference) while dropping evicted copies outside the locks cleanly bounds loose-window memory growth.cargo test -p victory-gpu --features diagnostics shadow::tests -- --test-threads=1(RTX 5090 & WARP): 10 passed, 0 failed on both (includingidle_loose_windows_go_and_fresh_ones_stay).cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 08:12 UTC · original · requested changes
Tested locally on Windows 11 x64 (
rustc 1.98.1, NVIDIA GeForce RTX 5090 + WARP):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default and--all-features): clean.shadow::tests --test-threads=1(10 passed),memory::tests --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views(7 passed).--features diagnostics,VICTORY_D3D12_WARP=1):shadow::tests(10 passed),memory::tests(8 passed);cargo xtask policy: 191 files ok.There is a CI failure plus three concurrency issues in
evict_older_thanthat need attention before merge:CI failure in
shadow::tests::idle_loose_windows_go_and_fresh_ones_stay(crates/victory-gpu/src/shadow.rs:1784):CI failed with
assertion left == right failed: one window went (left: 2, right: 1). Becausecargo testruns tests in parallel in the same process, callingevict_older_than(Duration::from_secs(1))also evicts loose windows created >1 s earlier by other tests, bumping the process-globalEVICTED[0]counter past 1. Using a threshold well above test runtime (e.g.Duration::from_secs(1800)against the3600 sbackdate) and asserting on the delta (after >= before + 1) fixes the flake.TOCTOU between
memory::shared_refsandArc::strong_count(shadow.rs:107-116):shared_refs(shadow)locks and unlocksSHAREDbeforeevict_older_thanre-locksLOOSEand checksArc::strong_count(shadow) == 2 + tables. If a heap is dropped (memory::release) or a page table is rewritten (Shared::rewrite) in that gap, the actual table reference count drops by 1 whiletablesstays stale—so a live external holder (list, view, or heap) makesstrong_count == 2 + tablesevaluate true, evicting a window that is still in use and allowing a subsequentloose()call to create a duplicateShadowfor the same title memory range.Note that
Shared::rewritealready locksSHAREDbeforeLOOSE(memory::prepare->Shared::rewrite->shadow::all()), so holdingSHAREDacross theLOOSEcheck (sameSHARED -> LOOSEorder) avoids the TOCTOU without inverting lock order.Arc<Layout>refcount blindspot whenMeter::frameracesHost::execute(host.rs:3481,memory.rs:216, 576, 638, 645):Host::presentcallsp.meter.frame(p.hwnd)(shadow::evict_idle()) without holdingself.submitted. Meanwhile, a concurrentHost::executeholds a clone ofArc<Layout>(inmemory::prepare,defer_missed, anddefer_after), which does not incrementArc::strong_count(shadow)for entries insideLayout.copies.evict_older_thancan therefore evict a window fromLOOSEwhile an in-flight submission is still reading/writing it viaLayout, allowing a concurrentloose()call to allocate a secondShadowfor the same range before copy-back completes. Runningevict_idle()under the submission lock (likeresource::evict_unused()) or verifyingArc::strong_count(&table.layout) == 1while holdingSHAREDcloses this race.Timestamp not re-checked under
LOOSElock (shadow.rs:108-112):If another thread calls
loose()on a candidate between collectingcandidatesand re-lockingLOOSE(updating*used = nowand dropping its temporaryArc), line 109 only checksArc::ptr_eq(held, shadow)and does not re-checknow.saturating_duration_since(*used) >= idle, evicting a freshly accessed window.Minor note: when
tables > 0, removing a window fromLOOSEincrementsEVICTEDimmediately even thoughShared.layout.copiesretains the lastArc<Shadow>(and its 4 MiB D3D12 buffer) until a subsequent title-memory submission triggersShared::rewrite.@Luislariosss on GitHub · 2026-11-26 11:27 UTC · original
Thanks @fuzeofficlal and the triage — all points are fixed in the new head:
EVICTED[0]grew, and sweeps with a 1800 s threshold against a 3600 s backdate, so windows other tests made in parallel are not touched.strong_count.memory::with_shared_refsholds the page tables' lock while the loose windows' lock is taken inside it (tables, then windows: the orderShared::rewrite→shadow::all()already takes them), and the count, the check and the removal happen in that one critical section.evict_idle()no longer runs fromMeter::frame. It runs inHost::executeright afterresource::evict_unused(), undersubmitted, so no submission is in flight and noArc<Layout>clone fromprepare/defer_missed/defer_afteris live; it looks at the windows at most every 5 s. A comment there says what keeps a gone copy's buffer alive: the page tables hold their own reference untilpreparerewrites them for the next submission.Also: the 5 s
tracing::info!line andloose_statsare behinddiagnostics.EVICTEDcounts windows when they leave the map; their bytes come back once the tables are rewritten without them (noted in the code).cargo test -p victory-gpu --locked: 232 passed (three runs in a row);--all-features: 247 passed;cargo clippy --all-targets -- -D warningsclean with and without--all-features.@pickles976 on GitHub · 2026-11-26 12:59 UTC · original
Local RTX 4060 Laptop / 16 GiB system RAM verification at
3e937d3780(clean production source).shadow::tests::idle_loose_windows_go_and_fresh_ones_stay: 1 passed, 0 failed, real NVIDIA device initialized.dxgi.hideNvidiaGpu = False. Important qualification: vkd3d-proton 3.2.02576c0b4adfae4a+is our diagnostic-relaxed build (assertions disabled and allocator/list vtable identity checks removed; null checks retained), not stock-runtime certification.0)30)Both runs remained on loading artwork and were deliberately stopped by the RAM guard, not diagnosed as application OOM crashes. The default sweep does run and removes windows, but it does not relieve this machine's first-loading RAM limit sufficiently. The 67 MB counter means removal from the loose map, not a direct measurement of resident bytes returned: page tables may retain references. A single pair with differing load progress and OS file-cache residency does not establish a timing regression or a causal endpoint-memory delta.
This is compatible with the large benefit you measured later in a long world run; our limiting burst happens earlier. Local logs:
20261126T125419Z-{console.log,resources.csv}and20261126T125548Z-{console.log,resources.csv}. No game content attached.AI-assisted: omp / OpenAI Codex ran the checks and drafted this report.
@pickles976 on GitHub · 2026-11-26 13:06 UTC · original
One additional bounded run on the same clean
3e937d3780d529a0bd08a8644ff1c20ee53372cd:VICTORY_WINDOW_IDLE_SECS=5, restored the same cache/data/vkd3d-cache seed, same title/input sequence and unchanged guards/environment described above. Fresh GPU release compilation confirmed after switching back from other PRs.Earlier eviction does operate during loading: last diagnostic reported 46 windows/252MB gone idle, versus12/67MB with the default30s. Remaining loose windows:414/1887MB. These are removed-map capacity counters, not proof of equivalent resident RAM returned.
The run still stopped at the2048MiB available-RAM guard after71.69s (available RAM12327.8→1796.2MiB; GPU3216MiB; final cgroup7165.6MiB, anon2748.6MiB, shmem4101.1MiB). Loading-art transition at50s, no gameplay; three compute pipeline refusals remained. Local log prefix
20261126T130504Z. Different starting RAM/progress means the extra seconds are not a quantified performance or total-RAM improvement.This narrows the result: lowering the existing threshold increases early retirement, but does not resolve this machine's loading RAM floor. No recommendation to change the default from this single sample, and no conclusion about later world-run savings. Related standalone #2971/#2972/#2974 checks and title results: #3012 . Same diagnostic-relaxed vkd3d caveat; AI-assisted verification using omp/OpenAI Codex.
@fuzeofficlal on GitHub · 2026-11-26 18:11 UTC · original · approved these changes
All previous concurrency and CI items are resolved in
3e937d37— approving to clear the earlier change request.Re-verified on
main(63bcca43) on Windows 11 x64 (RTX 5090 + WARP +VICTORY_D3D12_DEBUG=1):shadow::evict_idle()intoHost::execute(crates/victory-gpu/src/host.rs:1171) undersubmitted, holdingSHARED -> LOOSEacross the ref-count, timestamp check, and removal viamemory::with_shared_refs(crates/victory-gpu/src/memory.rs:232), and gatingloose_stats/ the 5 s log behinddiagnosticscleanly address all three concurrency races and the triage notes.cargo xtask policy(191 files ok) andcargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features) pass.cargo test --locked -p victory-gpu --features diagnosticsruns under WARP all passed (247/247 each), andshadow::tests::+memory::tests::passed underVICTORY_D3D12_DEBUG=1on both RTX 5090 and WARP.Sharedpage table (refs_in_tables = 1) confirmed on both RTX 5090 and WARP underVICTORY_D3D12_DEBUG=1that a held window stays, dropping the external ref letsevict_older_thanevict it and bumpgeneration(), the page table keeps the buffer alive untilmemory::preparerewrites it, and the finalArc<Shadow>drops cleanly afterward with zero Debug Layer messages.(Tiny non-blocking typo:
crates/victory-gpu/src/shadow.rs:1105andshadow.rs:1281have UTF-8 mojibake in two comments ——and→instead of—and→.)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.