Sends: under host memory pressure the spares the frames use stay, memory past 256 MiB is never kept, and releases leave the submitting thread (a 32 GB PC made them again every second) #3994
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3994"
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-30T14:01:00Z.
Problem
On a 32 GB PC, walking got much slower after
158d3177. Measured on an RTX 5080 + 9800X3D, Series X at 1440p, walking:send::trim()takes ~71 ms of the sweep every second. Single sweeps take 79-98 ms, and they run on the submitting thread.A bench-only check, where
trim()returns early unlesscritical_commit()holds, gave:That check is not this branch (see "Verification" and "Not tested").
Root cause
158d3177("Small hosts of RAM: the L0 caches of ours sized down…", 2026-11-28) addedsend::trim()to the once-a-second sweep. It runs wheneverresidency::pressured()holds: free RAM under 5 GB, or commit under 6 GB.VICTORY_SEND_OWN), so the next frames make the 8-64 MiB upload buffers again: a fresh map, zeroed pages, and later another release.Letting go of buffers the next frames make again saves no memory at the frame's peak, however little RAM is free. It only adds the cost of making and releasing them every second.
Fix
All in
crates/victory-gpu/src/host/send.rs, plus one line in the sweep inhost.rsand adocs/bug-journal.mdentry.InUsecounts, per class, how many buffers submissions hold now and the most they held at once since the last sweep.memory()lends a buffer andgive_back()returns it. ADroponMemorycovers a plan given up without coming back.send::tick()pushes this into a window of the lastVICTORY_SEND_KEEP_SECONDSsweeps (10 by default, once a second).trim_line+staying, both pure):kept()(the host cap) scaled by the share of 8 GiB of RAM that is free. That is the line the copy sources' spares use too (keeps_under_pressure): 768 MiB with 8 GiB free, 0 with none.critical_commit(), under 1.5 GiB) everything goes, as before.VICTORY_SEND_KEEP_SECONDS=0gives exactly the old rule: the hot floor alone. A test checks that, so the bench can A/B in one build.kept(), or past 256 MiB) lets go is passed, outside the spares' lock, tovictory-send-free, a thread started on first use that only drops them. If that thread cannot be started, they are dropped in place as before.spare_trim_to, #1520 / PR #57) keep a fixed one: 16 MiB, orSPARE_MOSTwith 8 GiB of RAM free. That works for 4 MiB scratch chunks. A frame's sends are ~46 MB in buffers of up to 64 MiB, so any fixed floor small enough for a 16 GB PC is too small for the working set.1ecaa98a). With 0.1-0.8 GB free it trimmed the working set every sweep and the churn came back (see "Verification").158d3177/ #1520 intent is kept.kept()(128 MiB on a small host, 768 MiB on a large one) is unchanged.made,made_mib,let_go,let_go_mib,spare_mibandneeded_at_once_mib.Own::record, its scatter pass and the copy queue's copy ofOwn::source(upq) each address one buffer, so the split would change the path the card reads its bytes from. That is not done here; it is markedshortcut:atmade_for. With memory past 256 MiB never kept, the slack only matters below 256 MiB, where it is under 64 MiB.fit(the least spare that holds a request) andmade_for.Verification
Our bench, walking in-world on the 32 GB PC (RTX 5080, Series X 1440p), 300 s each:
697590ad(by use, no RAM line)1ecaa98a(everything held to the RAM-scaled line)697590adthe send-trim cost was gone. But one sweep made 640 MiB at once in two buffers, and the spares then stayed at ~656 MiB on a PC that pages heavily.1ecaa98awas meant for that, but brought the churn back.1ecaa98a,needed_at_oncewas 128-144 MiB against 168-232 MiB of spares, so each sweep made 2-5 buffers and let 1-4 go.8b801739has the in-use rule of697590ad(regardless of RAM), plus the need floor, the RAM-scaled part for spares beyond those, and no keeping past 256 MiB. It is measured in game below.The tip (
8b801739), measured in game on the same 32 GB PC, walking, Series X native 1440p, DLSS off, world +30..330 s:158d3177)let_go_idle(2 runs)Largest kept spare in those runs: 464-504 MiB;
needed_at_once184-192 MiB. With the camera turning (standing, steady turn), this alone takes the turn from ~15 to 17.8 fps and card copies from 12.5 to 6.3 ms.Side by side with the other open fixes for the same churn (on vnv
829188e9+ #3347, walk, first round of two; one run each, so noisy):8b801739)All three remove most of the churn. #3381 had the better fps in this round; this branch is the only one that takes the send trim to zero and frees off the submitting thread. The second round is running; I'll add it here. If #3381 holds its lead, merging it and keeping this branch's per-size window and off-thread release on top would be the combination to consider.
Windows 11, MSVC, own target dir,
-j 6, on8b801739:cargo check -p victory-gpu --locked: passes. None of its warnings are inhost/send.rsor at the sweep line inhost.rs.cargo test -p victory-gpu --lib --locked -- host::send::: 15 passed, 0 failed, 1 ignored (the existing GPU scatter test). The 12 new tests:with_no_ram_free_a_walk_whose_sends_move_makes_nothing_after_its_first_second. This is the bench's case: a model ofmemory(),give_back()(with its cap),tick()andtrim()over 7 seconds of 20 frames, three frames in the air.under_pressure_that_never_clears_a_steady_frame_makes_nothing_again: steady 30 + 12 + 4 MB frames, with one and two in the air, 16 GiB or no RAM free. Nothing is made after the first second. The old rule makes 2 again every second.a_bursts_buffers_go_with_the_window_or_at_once_past_256_mib: one frame also sends 300 + 100 MB.the_trim_line_keeps_what_the_window_used_and_scales_only_the_rest_by_free_ram:roomat 0, 2, 8 and 32 GiB free. The in-use counts and the need floor are the same whatever RAM is free. Nothing seen gives the hot floor; critical commit gives nothing.a_trim_keeps_what_was_in_use_lately_whatever_ram_is_free: classes kept, the need fill, and the room fill.critical_commit_lets_every_spare_go_and_free_ram_governs_only_the_rest.with_nothing_in_use_lately_a_trim_is_the_hot_floor_of_158d3177: with an empty window the result equals the old rule on five pools.send_memory_classes_are_doubles_from_8_mib,send_memory_is_made_by_doubles_then_in_steps_then_at_its_own_size,in_use_counts_the_most_at_once_between_sweeps,the_window_wants_the_most_of_each_class_in_its_sweeps,what_a_scene_left_behind_goes_once_the_window_has_passed.cargo clippy -p victory-gpu --all-targets --locked: passes. Its warnings are all in code this branch does not touch, none on a line it adds or changes.-D warningswas not used, because main already fails it elsewhere.41adb551(git merge-tree).NOT tested
kept()(768 MiB).roomand the 256 MiB line are choices, not measurements.kept()cap, critical commit and the scaled part beyond what is used are as described. Whether keeping the working set under pressure moves anything toward the 8 GiB shared cap of #1520 was not measured.host::send::tests were run. The rest of thevictory-gpulib suite was not, and neither wascargo xtask policy(the change is.rsand.mdonly).victory-send-freewhile the submitting thread makes new upload buffers still contends in the driver was not measured.Overlap
Open PRs found by title and by touching
host/send.rs(searched: send, trim, spare, send own, L0, upload buffers,158d3177):trim,memoryandgive_back.Mapof new buffers and in releasing them.trim,Memoryandgive_back.VICTORY_SEND_KEEP=1after #3411's idea, plus churn stats. It conflicts intrim.kept(), and the buffer can then still be pooled. Textual conflict: theirmade_size(size, kept)against ourmade_for.on_card/kept/ a spare-bytes reader insend.rs. Small textual conflicts at most, no overlap in what they change.AI use
Claude Code (Claude Opus 5.5) wrote the change, its tests and this description from our bench's measurements and a reading of
158d3177, #1520 / PR #57 (spare_trim_to's floor) and the overlapping PRs. The numbers in "Problem" and the bench rows in "Verification" come from our bench runs, not from the model.🤖 Generated with Claude Code
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T14:13:10Z.
Shootout, final (2 runs per arm): RTX 5080 + 9800X3D, 32 GB, vnv
829188e9+ #3347, walking, Series X native 1440p, DLSS off, world +30..330 s. Every arm has the same local per-step sweep timing.8b801739)AI use: Claude Code (Claude Opus 5.5).