Repository navigation
GPU: loose windows nothing has asked for go, with their memory (VICTORY_WINDOW_IDLE_SECS) - #3078
Luislariosss wants to merge 1 commit into
Conversation
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):
- Diff review: Tracking last-use timestamps on
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
left a comment
There was a problem hiding this comment.
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.- RTX 5090:
shadow::tests --test-threads=1(10 passed),memory::tests --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views(7 passed). - WARP (
--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_than that 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 withassertion 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 thatShared::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 callsloose()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 from LOOSE increments EVICTED immediately even though Shared.layout.copies retains the last Arc<Shadow> (and its 4 MiB D3D12 buffer) until a subsequent title-memory submission triggers Shared::rewrite.
|
Automated triage for the maintainers. Needs work. CI is failing: Before this can be reviewed for merging, also please:
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 |
…RY_WINDOW_IDLE_SECS) Copies of windows were never freed, and a long run kept every one it had ever made: one held 1,400 of them (6.4 GB) by its end, on a machine whose RAM is the limit. A window now goes when no submission has asked for it for 30 s (VICTORY_WINDOW_IDLE_SECS, 0 keeps them all) — but only one 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 of memory::Shared name every copy, so their references are discounted (their lock is never held with the map's: a rewrite takes both, in the other order), and changed() has them rebuilt without the gone ones. Measured over a 902 s world run, the first on this machine to survive its whole length: 720 windows went and 3.4 GB came back, the live set stayed at 840 (3.6 GB) instead of growing without end, no allocation errors, and the title went farther into its story than any run before. Test: an idle window goes, a fresh one stays, a held one stays, a gone one is made again.
|
Thanks @fuzeofficlal and the triage — all points are fixed in the new head:
Also: the 5 s
|
4a8176a to
3e937d3
Compare
|
Local RTX 4060 Laptop / 16 GiB system RAM verification at 3e937d3 (clean production source).
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: AI-assisted: omp / OpenAI Codex ran the checks and drafted this report. |
|
One additional bounded run on the same clean 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 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 (comment) . Same diagnostic-relaxed vkd3d caveat; AI-assisted verification using omp/OpenAI Codex. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
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):
- Moving
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.- Three consecutive full parallel
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. - An additional lifecycle probe with a live
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:1105 and shadow.rs:1281 have UTF-8 mojibake in two comments — — and → instead of — and →.)
Problem
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.