Lists: new memory made ahead off the list threads, placed constants from the card's scratch pool, and the pools keep what the last second used (residency waits) #4319
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4319"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T18:51:22Z.
Problem
The threads that record the title's lists wait for new memory to become resident (
host::resident,VICTORY_WAIT_RESIDENT) and, for the card's memory, to be mapped (host::mapped):HostList::place_constant→Host::uav_bufferandHostList::scratch_alloc→take_chunk.VICTORY_WAIT_RESIDENT=0the device was lost (2026-11-25). So the fix has to keep every wait and take it off the list threads.Root cause
Three things make the lists allocate, and so wait, far more often than their memory use needs:
place_constant(VICTORY_PLACED_CONSTANTS, on) snapshots constants into a 64 KiB card buffer fromhost.uav_buffer. That is a committed resource made withCREATE_NOT_RESIDENT, thenMakeResident, then a copy-queue round trip inmapped(). The list lets it go at its reset. It is the only per-recording card buffer of aHostListthat the card scratch pool (uav_pool) does not take back:between,card_budget,batch_argsandindirect_argsall go throughtake_uav/retire_uavs. On our bench the title reads 3-7 placed constants a frame, and the mapping waits (only card memory and shared buffers wait for a mapping) come to 28,600-30,600 a run. The buffers made ahead inahead.rswould serve the 64 KiB size, but that store stops filling under host memory pressure and above 70 % of the card's budget. On a 32 GB PC with the world loaded both hold the whole time: pressure came on about 33 s into the runs checked and never cleared, and the card sat at 87-96 % of its budget while turning. So the store is empty exactly when the lists need it.sweep()trims the scratch chunk pools to 16 MiB (trim_spare_chunks) and the card scratch pool to nothing (sweep_uav_spare). The pressure needs 5 GiB free to clear; on these PCs it never does (130-450 MB free while turning). So every second the chunks the frames use were freed, and the next frames made them again, each one resident-waited on a list thread while the system paged. This is #3381's finding.Fix
49cfd1da, Maverick0351a). Under pressure the sweep trims only what a pool kept unborrowed for the whole second (Spare::trim_aboveon the low-water mark): the scratch chunk pools, the upload copy sources, and the card scratch pool (what lies above a 16 MiB warm floor, or above none when the card is high or RAM is short). Everything still goes at critical commit, and the card pool at critical card memory. Its send.rs hunk is left out: #3994 (ours, now merged) changed the same trim differently.0ef04ea0).place_constanttakes its buffer withuav_pool::take_uavat the pool's bucket size (64 KiB for the usual snapshot). The constants are written before they are read, which is what the pool asks of its users.Deferred::placed_uavs. The old one was kept withHostList::keep.HostList::placed_common()at the close moves them fromGENERIC_READtoCOMMON, asbetween_common()does forbetween. WithVICTORY_CLOSE_LEAN=2the move is left out: a buffer decays to common when its submission finishes.place::placed_back()gives them toretire_uavs, which hands them to the pool once every submission started before has finished. One that a descriptor slot still holds (HostHeap::keep_refafterconstant_at) is let go as before, so no other list writes a buffer a slot may still show. Buffers the close did not move back are let go as before.VICTORY_UAV_POOL=0gives a buffer per recording again.078070e7,host/reserve.rs,VICTORY_RESIDENT_AHEAD, on;0: as before).scratch_wbsays so) and in shared memory, and card buffers of the pool's 64 KiB bucket.take_chunk_kindafterSPARE/SPARE_SHARED;take_uavafterUAV_SPARE), and makes its own only if none is ready.victory-resident-ahead, off the frame's cores) makes them with the same calls the list would have made (new_chunk, factored out oftake_chunk_kind, anduav_buffer_now). So each is resident, and the card's mapped, before any list can take it. Nothing is named by a list or a slot before its wait is over; only the waiting thread changes.Lane::target): as many as lists asked of it in the busiest second of the last eight, at most 4 MiB for each small lane and 32 MiB for each lane of 4 MiB chunks (72 MiB of the PC's memory and 4 MiB of the card's over all five). A lane nobody asked of keeps none. What is ready past the target goes after each second. A take wakes the thread.trim_spare_chunks()(critical sweep, F7, the XMem fallback) andfree_all_spares()(an upload buffer refused for memory) let them go too.new memory waited forandmappedlines, so those keep measuring the other threads.What does not change: every allocation still waits until it is resident and, for the card's memory, mapped, before any list or descriptor names it.
VICTORY_WAIT_RESIDENT,VICTORY_RESIDENT_LATERandahead.rsare untouched.Verification
Windows 11, MSVC, RTX 5080 (the GPU tests run on it), on the branch's tree (
078070e7):cargo check -p victory-gpu --lib --tests --locked -j 4: passes on078070e7, and on0ef04ea0alone (the middle commit builds without the reserve). No warning inreserve.rs,place.rsoruav_pool.rs.cargo test -p victory-gpu --lib --locked -j 4 -- host::reserve host::uav_pool host::place host::spare scratch sweep_spare trim_spare: 28 passed, 0 failed, 3 ignored (the three are main's benchmarks). That includes the existinghost_list_uav_pool_lifecycle_retire_trim_and_info_queue,place_constant_reads_what_place_copy_wrote(debug layer clean),a_trim_frees_only_what_was_never_asked_for_since_the_last,pressure_trim_preserves_eviction_order_and_low_watermark, bothcard_stepsshared-scratch tests andhost_list_reuses_and_grows_scratch_across_submissions.a_lane_keeps_what_the_busiest_recent_window_asked: the target follows the window's asks, a quiet window keeps the busy one, a full lane gives a new one back, the one made last goes first.a_lane_lets_go_past_its_target_once_asking_falls: the busy window is remembered for exactly eight windows; then what is past the target goes, oldest first; a lane nobody asks of keeps nothing.a_lane_keeps_no_more_than_its_bytes: 1,000 asks keep 8 chunks of 4 MiB (32 MiB).the_lanes_are_the_sizes_lists_ask_for: the five lanes, their limits, and the card lane equal to the pool's 64 KiB bucket.off_no_lane_serves,only_the_filling_threads_waits_are_counted_here.a_step_makes_what_was_asked_for_and_it_is_taken_next(on the card): one card buffer and one first chunk asked for, one step makes both (64 KiB, unordered access; a 256 KiB chunk whose mapping is written), the lanes give them out next, nothing more is made while nothing is short.placed_constants_buffers_go_back_to_the_card_pool_once_their_list_has_run(on the card): two snapshots past one buffer's room, the debug layer clean after the close, the buffer nothing holds back in the pool after the reset, the one standing for a slot's hold not.cargo clippy -p victory-gpu --lib --tests --locked -j 4: no warning on a touched line. The two it gives are main's:host.rs:5173(manual_is_multiple_of) andshadow.rs:7197(rangedunused).NOT tested
Nothing was run in the title (no game run for this branch).
cargo build --release --locked -p victory), with #3703 (the long-frame line) merged into each so the frames name what they waited for:84bd61e2+ #3703.VICTORY_RESIDENT_AHEAD=0(only #3381's trim and the placed constants' pool).residentis the largest part, andresidentsummed;new memory waited forandnew card memory waited for until it is mapped, at 150 s and at 270 s;made by lists that found none readyshould be a small share oftaken;placed constants' buffers ... back to itagainstlet go as a slot still showed them.device removedand no DRED report;VICTORY_D3D12_DEBUG=1in a diagnostics build, no debug-layer error on the placed constants' buffers (state at the close, reuse);residentas the largest part of long frames whilemade by listsstays low, the waits come from those other sites, which this branch does not move.VICTORY_RESIDENT_LATER=1.Overlap
Main moved by over 500 commits while this was written, and #3381, #3699, #3951 and #3703 all conflict with main
84bd61e2on their own now. The merge checks below were made on the branch's first base (41adb551), where those PRs applied.sweep()now callstexback::sweep_read_backs(); kept). If #3381 lands first, drop that commit. Its send.rs hunk is not here (see #3994).0c8c2092) and in this branch's base. That is why #3381's send.rs hunk is left out.ebe912e1, in this branch's base): coalesces concurrentmapped()waits. Complementary: it shortens the mapping waits that remain; this branch moves them off the list threads. The reserve thread's waits, coalesced or not, are counted on its own line.mapped()to 2 s. Merged cleanly on41adb551; it now conflicts with main's #1553 rewrite ofmapped()either way. The reserve's thread would get the bound too.sweep()andtrim_spare_uploads(); with this branch also in the last lines oftrim_spare_chunks()(the reserve's bytes). A small rebase either way.41adb551. Itslongframe::addinresident()andmapped()sits after this branch's early return, so the reserve thread's waits stay out of the long-frame line. It needs a rebase onto main for the bench builds anyway.VICTORY_RESIDENT_LATER=1(existing, off):EnqueueMakeResidentwith a fence, and a wait at the descriptor write and on the queue. That is the other way to take the wait off these threads. It is left as it is; the reserve works with it on or off.ahead.rs(VICTORY_BUFFERS_AHEAD): the bulk store of 64 KiB buffers for the title buffers' copies. Not changed. It stops under host pressure and above 70 % of the card's budget; the reserve is small and sized by what lists ask, so it keeps working there.AI use
Claude Code (Claude Opus 5.5) read the open PRs on residency and the scratch pools, the bench and teammate logs, and the code paths. It took #3381's two hunks, wrote the other two commits and their tests, ran the checks above, and wrote this note. The first commit is Maverick0351a's (#3381).
🤖 Generated with Claude Code
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-12-01T05:54:01Z.
Bench result: the camera-turn A/B from "NOT tested", run this morning. RTX 5080 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Windows 11. Release builds, one shared shader cache (warmed first):
84bd61e2.078070e7.VICTORY_RESIDENT_AHEAD=0.Neither build has #3703's long-frame line (main has none), so there is no per-cause split of slow frames. Series X, 1440p, DLSS Quality, frame generation off, same save. Standing world+30..150 s, right stick held 150..270 s, 360 s runs, in the order A B C A B C. Waits are read from the cumulative lines at the window edges (they print every 1,000 waits, so counts are to ±1,000).
At 270 s, since the start, on the list threads:
B's reserve line at the end of the run (360 s, both runs):
Peak private bytes: A 30.4-31.3 GB, B 30.5-30.6, C 30.4-30.8; free commit low 331-511 MB in all. No device removed, DRED or "did not close" line in any run. Our watch for other games running on the PC found none during these runs. The bench's own check saw a second process of the same program for a few seconds in one C run (at 169 and 241 s) and one A run (238 s): another tool on the PC. Both runs read like their repeats.
What this shows
0ef04ea0never returned a buffer here, so the slot-held case is the normal one in play, not the exception "Not known yet" expected.What it does not show
VICTORY_RESIDENT_LATER=1were not tested.AI use: Claude Code (Claude Opus 5.5) ran these on our bench queue, parsed the run logs with its own scripts, and wrote this comment.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-12-01T06:21:41Z.
Follow-up on the bench's "0 back, 20-22k let go" for the placed constants' buffers. Fixed in
5cdf7051, a new commit on this branch (on main5fabb46e).Why: the descriptor slots really do hold the buffers, and so does the retirement of a slot's old view. The check counted them correctly. What was wrong was letting them go there.
draw.rsbinds placed constants through descriptor tables withconstant_at. That keeps a reference in the slot (HostHeap::keep_ref,VICTORY_SLOT_HOLDS). One buffer holds many snapshots, so one table slot is enough to hold it.retire_resource. It is kept until the submissions running then have finished, plus the bury lag (16 submissions on PCs with up to 32 GB, 64 above).Fix:
retire_uavs, as at the reset.Tests (RTX 5080):
placed_constants_buffers_go_back_to_the_card_pool_once_nothing_shows_themshows the buffer through a real descriptor slot withconstant_at, then resets the list. The buffer stays out of the pool while the slot shows it and is back once the slot lets go. With the old path (held buffers let go at the reset), it fails at that last check, the same 0 the bench saw.cargo test -p victory-gpu --libon the touched modules: 30 passed, 0 failed. Clippy shows nothing on touched lines.Not run in game yet. Two camera-turn runs of this head are queued on our bench. The line should show most parked buffers coming back later, and the card pool's hits should rise well above this morning's 836-863. If they don't, I'll drop both placed-constants commits from this PR. The fps question stays as the bench left it: the reserve moves about 70 % of the residency waits off the list threads, and the frames don't change.
AI use: Claude Code (Claude Opus 5.5) traced the holders in the code, wrote the fix and its tests, ran them with a negative control, and wrote this comment.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-12-01T08:27:34Z.
Follow-up with the new head
5cdf7051(placed constants' return path). Two more runs of the same camera turn as my comment above: same PC, profile, save and cache, release build, this morning. Compared with B there (078070e7, the first version of this PR).078070e7(2 runs)5cdf7051(2 runs)For reference, main
84bd61e2had 44,000-45,000 resident waits (18.0-19.4 s) and 33,400-33,600 mapping waits (4.4 s) on the list threads by 270 s, with 23.4-23.8 fps while turning.No device removed, DRED or "did not close" line. No other game was running on the PC, and no run was flagged.
What this shows
What it does not show
AI use: Claude Code (Claude Opus 5.5) ran these on our bench queue, parsed the run logs with its own scripts, and wrote this comment.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:44:21Z.
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed