Skip to content

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

Open
Lyrnc wants to merge 3 commits into
trustno1-coder:mainfrom
Lyrnc:perf/send-trim-floor

Conversation

@Lyrnc

@Lyrnc Lyrnc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

On a 32 GB PC, walking got much slower after 158d317. 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.
  • Card copies go from 3.4 to 6.6 ms a frame, because the send buffers that are made again are counted there.
  • Page-ins are 2-4 times as many.

A bench-only check, where trim() returns early unless critical_commit() holds, gave:

main trim only at critical commit
fps 21.5 23.3
frames over 100 ms, per 1,000 42 35
longest frame 723 ms 224 ms
card copies, per frame 6.6 ms 3.4 ms
page-ins, per second 7.9k 2.5k

That check is not this branch (see "Verification" and "Not tested").

Root cause

158d317 ("Small hosts of RAM: the L0 caches of ours sized down…", 2026-11-28) added send::trim() to the once-a-second sweep. It runs whenever residency::pressured() holds: free RAM under 5 GB, or commit under 6 GB.

  • The pressure never clears. With the title at ~31 GB private, a 32 GB PC is under pressure all the time. Play leaves 0.1-0.8 GB of RAM free.
  • The trim drops the working set. Each sweep cuts the submissions' send spares down to the 16 MiB hot floor. A frame sends ~46 MB (VICTORY_SEND_OWN), so the next frames make the 8-64 MiB upload buffers again: a fresh map, zeroed pages, and later another release.
  • The release is slow, and blocks the submitting thread. The sweep runs there, and the old trim also dropped the buffers while it held the spares' lock.
  • The biggest go first. The pool is sorted biggest first and trimmed from the front, so the spare left at the floor is never the one the next large submission needs.

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 in host.rs and a docs/bug-journal.md entry.

  • What was in use lately, counted per size class. Send memory comes in 10 size classes (doubles from 8 MiB up to 2 GiB, and one for larger).
    • InUse counts, per class, how many buffers submissions hold now and the most they held at once since the last sweep.
    • It also counts the bytes those requests needed at once, each at the size it would be made at. That is not the size of a bigger spare a small request took.
    • It records the bytes in use at the sweep.
    • memory() lends a buffer and give_back() returns it. A Drop on Memory covers a plan given up without coming back.
    • Every sweep, under pressure or not, send::tick() pushes this into a window of the last VICTORY_SEND_KEEP_SECONDS sweeps (10 by default, once a second).
  • What stays under ordinary pressure (trim_line + staying, both pure):
    1. Whatever RAM is free, each class keeps as many spares as were in use at once in the window, so a class shrinks only when it went unused for the whole window.
    2. Also whatever RAM is free, the spares are at least the window's largest need-at-once, less what is in use at the sweep (filled with the smallest others), or the 16 MiB hot floor.
    3. Only spares beyond that are held to 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.
    • At critical commit (critical_commit(), under 1.5 GiB) everything goes, as before.
    • VICTORY_SEND_KEEP_SECONDS=0 gives exactly the old rule: the hot floor alone. A test checks that, so the bench can A/B in one build.
  • Memory past 256 MiB is never kept. A world load's sends (one submission of 2112 MiB) are made at their own size in 64 KiB steps, let go as soon as their submission has run, and not counted in what was in use. By doubles such a request was made at 4 GiB, which one upload buffer may not be. From 64 to 256 MiB, memory is made in 64 MiB steps, not by doubles.
  • Released off the submitting thread. What a trim or a give-back (over kept(), or past 256 MiB) lets go is passed, outside the spares' lock, to victory-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.
  • Why not a fixed floor, or one scaled by free RAM.
  • The 158d317 / 16 GB RAM regression on 923e38c: 8 GiB WDDM L0 Shared GPU Memory exhausted in ~95s (CommandList::Close 0x8007000E) + VICTORY_WINDOWS_BAR_MB auto-config dropped #1520 intent is kept.
    • The cap of kept() (128 MiB on a small host, 768 MiB on a large one) is unchanged.
    • Critical commit still empties the pool.
    • Spares no frame used for 10 s go, and so do spares beyond the working set when RAM is short.
    • Load-sized buffers are never kept.
  • A log line at the sweep, only when something was made or let go: "submission send memory since the last sweep", with made, made_mib, let_go, let_go_mib, spare_mib and needed_at_once_mib.
  • One buffer per submission is kept. Splitting a submission's sends over buffers of at most 64 MiB each would bound them to one step. But Own::record, its scatter pass and the copy queue's copy of Own::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 marked shortcut: at made_for. With memory past 256 MiB never kept, the slack only matters below 256 MiB, where it is under 64 MiB.
  • Two small refactors make the decision testable: fit (the least spare that holds a request) and made_for.

Verification

Our bench, walking in-world on the 32 GB PC (RTX 5080, Series X 1440p), 300 s each:

697590a (by use, no RAM line) 1ecaa98 (everything held to the RAM-scaled line)
send buffers made / let go 7 / 6 524 / 522 (19.5 GiB each way)
card copies, per frame 3.4 ms 5.0 ms
fps 23.1 22.6
frames over 100 ms (per 1,000) 36 41
  • On 697590a the 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. 1ecaa98 was meant for that, but brought the churn back.
  • On 1ecaa98, needed_at_once was 128-144 MiB against 168-232 MiB of spares, so each sweep made 2-5 buffers and let 1-4 go.
  • 8b80173 has the in-use rule of 697590a (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 (8b80173), measured in game on the same 32 GB PC, walking, Series X native 1440p, DLSS off, world +30..330 s:

build fps >100 ms per 1,000 sweep: send trim send buffers made / let go in 300 s card copies
our fork's main (has 158d317) 21.3 / 22.0 43.9 / 41.1 80-83 ms per sweep (every second) 7.3 / 6.9 ms
that main + sweep spreading + this + #3272's let_go_idle (2 runs) 23.8 / 24.1 10.9 / 10.2 0.1-0.2 ms 3 / 1 and 2 / 1 3.5 ms

Largest kept spare in those runs: 464-504 MiB; needed_at_once 184-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 829188e + #3347, walk, first round of two; one run each, so noisy):

arm fps >100 ms per 1,000 send trim per sweep card copies
base 19.5 55.4 68.0 ms 10.6 ms
this (8b80173) 20.3 52.1 0.0 ms 6.1 ms
#3381 21.7 35.0 9.3 ms 6.3 ms
#3411 20.2 52.5 4.9 ms 6.3 ms

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, on 8b80173:

  • cargo check -p victory-gpu --locked: passes. None of its warnings are in host/send.rs or at the sweep line in host.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 of memory(), give_back() (with its cap), tick() and trim() over 7 seconds of 20 frames, three frames in the air.
      • Each submission's send moves across the sizes made, frame to frame (34 MB takes 64 MiB, 9 MB takes 16 MiB), and one frame in five also sends 66 MB.
      • With 0, 0.5 and 16 GiB free: 13 buffers made in the first second and none after, with 352 MiB of spares.
      • With the hot floor alone, 4 are made again every second.
      • 1ecaa98's rule, modelled the same way (outside the suite), made one again every second with 224 MiB of spares, close to the bench's 168-232.
    • 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 300 MB buffer is made at its own size and never kept.
      • The 128 MiB one stays while its class was in use in the window. With no RAM free it then goes; with room, it stays.
      • A load's 2112 MiB is made once and never kept.
    • the_trim_line_keeps_what_the_window_used_and_scales_only_the_rest_by_free_ram: room at 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.
    • Also: 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 warnings was not used, because main already fails it elsewhere.
  • The branch merges cleanly with vnv/main 41adb55 (git merge-tree).

NOT tested

  • The shootout's second round (results above are round one). The numbers above for the two earlier commits only.
  • The spares the tip keeps were not measured in game. In the model they are 352 MiB with three frames in the air and sends that move across sizes. In play they are bounded by kept() (768 MiB).
  • The 10-sweep window, the 8 GiB line of room and the 256 MiB line are choices, not measurements.
  • Not run on a 16 GB PC. The 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 16 GB RAM regression on 923e38c: 8 GiB WDDM L0 Shared GPU Memory exhausted in ~95s (CommandList::Close 0x8007000E) + VICTORY_WINDOWS_BAR_MB auto-config dropped #1520 was not measured.
  • Only the host::send:: tests were run. The rest of the victory-gpu lib suite was not, and neither was cargo xtask policy (the change is .rs and .md only).
  • Release timing on the free thread. Whether releasing on victory-send-free while 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, 158d317):

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 158d317, #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

Lyrnc and others added 3 commits November 30, 2026 10:51
…and go on a thread of their own

158d317 trimmed the submissions' send spares to the 16 MiB hot floor
at every sweep while the host memory is pressured. On a 32 GB PC with
the title at ~31 GB private the pressure never clears (free RAM under
5 GB), and a frame sends ~46 MB (VICTORY_SEND_OWN), so the next frames
made the 8-64 MiB upload buffers again, every second. Walking (RTX 5080,
9800X3D, Series X at 1440p) the trim took ~71 ms of the sweep each
second, single sweeps 79-98 ms on the submitting thread; the card copies
went from 3.4 to 6.6 ms a frame with the fresh buffers counted there,
and page-ins were 2-4 times as many.

- Send memory in use is counted by size class (doubles from 8 MiB):
  how many submissions hold now, and the most at once between sweeps
  (InUse; a Drop on Memory covers a plan given up). Each sweep, under
  pressure or not, send::tick() keeps those peaks for the last
  VICTORY_SEND_KEEP_SECONDS sweeps (10 by default).
- Under ordinary pressure a trim keeps, of each class, as many spares as
  were in use at once in that window, then the smallest others up to
  the 16 MiB hot floor if that keeps more; what no frame of the window
  used goes. At critical commit all go, as before. The small host's cap
  (kept()) is unchanged. VICTORY_SEND_KEEP_SECONDS=0 is the floor alone,
  exactly the rule before (a test replays it).
- What a trim or a give-back past kept() lets go is released outside
  the spares' lock on a thread of its own (victory-send-free), not on
  the submitting thread; in place if that thread cannot be made.
- The sweep says what send memory was made and let go, when any was.

Eight new tests in host::send, among them a model of five seconds of
steady frames under pressure that never clears: nothing is made again
after the first second, against the 32 and 16 MiB buffers made again
every second with the floor alone. Not measured in game on this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e RAM, and made in 64 MiB steps past 64 MiB

The bench on the first commit: the send-trim cost is gone and the send
buffers made and let go fell to a handful in 5 minutes of a walk, but
one sweep made 640 MiB at once in two buffers (by doubles, 512 and 128),
and the spares then sat at ~656 MiB on a 32 GB PC that pages heavily: a
burst's buffers were in use in the window, so they stayed for all of it.

- What was in use is counted in the bytes the requests needed at once
  too, each at the size made for it (not the size of a bigger spare a
  small request took). A trim keeps within a line: all of what the last
  sweep needed (the working set, made again within a frame if it goes,
  so letting it go saves nothing; with two frames in the air, the busiest
  frame twice over), and of the window's busiest moment beyond that only
  kept() scaled by the share of 8 GiB of RAM that is free (the copy
  sources' keeps_under_pressure line); at least the hot floor. Past the
  line the biggest go first, in use or not.
- Send memory past 64 MiB is made in 64 MiB steps, not by doubles: at
  most 64 MiB more than asked for (512 MiB for a request just past 256
  before). A submission's sends stay in one buffer (shortcut: record,
  its scatter pass and the copy queue each address one).
- The sweep's line also says the bytes needed at once.

host::send: 15 passed, 1 ignored; among them a walk with two frames in
the air and a burst of 300 + 100 MB: 320 + 128 MiB made, kept one sweep,
then 184 MiB with 2 GiB free (504 with 16), 56 once the window passed,
nothing made again. Not run in game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st 256 MiB is never kept

The bench on 1ecaa98: with 0.1-0.8 GB of RAM free in play on the 32 GB
PC the free-RAM-scaled part of the line was ~0, so all that stayed was
what the last sweep needed at once (128-144 MiB) while the spares the
frames use were 168-232 MiB: 524 buffers made and 522 let go in 300 s
(19.5 GiB each way) against 7 and 6 on 697590a, card copies 3.4 to
5.0 ms, fps 23.1 to 22.6, frames over 100 ms 36 to 41.

- Whatever RAM is free, of each class as many spares stay as were in
  use at once in the window (a class shrinks only when it went unused
  for all of it), and at least what the window's busiest moment needed
  at once less what is in use at the sweep, or the hot floor. Only
  spares beyond that are held to kept() scaled by the free RAM.
- Send memory past 256 MiB is made at its own size (64 KiB steps) and
  let go as soon as its submission has run, not kept nor counted in what
  was in use: at load one of 2112 MiB was made and dropped by a sweep.
  From 64 to 256 MiB, 64 MiB steps as before.

host::send: a walk whose sends move across sizes, three frames in the
air, with 0, 0.5 and 16 GiB free: 13 made in the first second, none
after (the rule of 1ecaa98, modelled the same way, made one again every
second with 224 MiB of spares). Not run in game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Lyrnc

Lyrnc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Shootout, final (2 runs per arm): RTX 5080 + 9800X3D, 32 GB, vnv 829188e + #3347, walking, Series X native 1440p, DLSS off, world +30..330 s. Every arm has the same local per-step sweep timing.

arm fps (2 runs) >100 ms per 1,000 send trim per sweep (submitting thread) card copies send buffers made / let go in 300 s largest kept spare
base 19.5 / 19.7 55.4 / 51.6 68.0 / 73.5 ms 10.6 / 10.0 ms (every second) n/a
#3994 (8b80173) 20.3 / 21.4 52.1 / 39.0 0.0 / 0.0 ms 6.1 / 6.2 ms 6/4, 7/4 416–480 MiB
#3381 21.7 / 20.1 35.0 / 46.3 9.3 / 9.2 ms 6.3 / 6.5 ms n/a n/a
#3411 (bundle) 20.2 / 20.8 52.5 / 45.4 4.9 / 4.9 ms 6.3 / 6.1 ms n/a n/a

AI use: Claude Code (Claude Opus 5.5).

stasadance added a commit to stasadance/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
…ast 256 MiB is never kept, and releases go to the bury thread (upstream trustno1-coder#3994)

Since 158d317 send::trim() cut the submissions' send spares to the
16 MiB hot floor at every sweep under host memory pressure. On a 32 GB
PC with the title at ~31 GB private the pressure never clears, and a
frame sends ~46 MB, so the next frames made the 8-64 MiB upload buffers
again every second: ~71 ms of the sweep, card copies 3.4 -> 6.6 ms a
frame, page-ins 2-4x. Upstream (RTX 5080, walking): fps 21.5 -> 23.3,
longest frame 723 -> 224 ms.

Ported from upstream trustno1-coder#3994 (Lyrnc: 697590a, 1ecaa98, 8b80173), as
its tip:

- Send memory in use is counted by size class (doubles from 8 MiB),
  with the bytes needed at once (InUse; a Drop on Memory covers a plan
  given up). send::tick() runs at every sweep (in sweep_parts, so on the
  victory-sweep thread when the sweep runs beside) and keeps the last
  VICTORY_SEND_KEEP_SECONDS sweeps (10 by default; 0 = the hot floor
  alone, the rule of 158d317).
- Under ordinary pressure a trim keeps, whatever RAM is free, of each
  class as many spares as were in use at once in the window, and at
  least the window's busiest need less what is in use (or the hot
  floor); only spares beyond that are held to kept() scaled by the share
  of 8 GiB of RAM free. Critical commit lets all go, as before.
- Send memory is made by doubles to 64 MiB, in 64 MiB steps to 256 MiB,
  and past 256 MiB at its own size (64 KiB steps), let go as soon as its
  submission has run and never kept.
- The sweep logs what send memory was made and let go, when any was.

Adapted to this branch:

- Releases: upstream starts a victory-send-free thread of its own. Here
  let_go() hands them to super::release_apart (the trustno1-coder#3951 port, 7c30f85),
  so they drop on victory-bury with the sweep's other trims; one release
  thread, and VICTORY_RELEASE_APART=0 drops them in place for both.
  give_back's lets-go (past kept(), past 256 MiB) now go there too.
- Replaces this branch's send-pool low-water trim (SparePool, 96cf1b1)
  and made_size (ceaad09, "past what is kept at its own size") with
  trustno1-coder#3994's window and made_for. The 4 GiB upload-buffer note moves to
  made_for. On a small host (kept() 64/128 MiB) memory from 128 to
  256 MiB is now made in 64 MiB steps rather than at its own size, and
  still let go by give_back as soon as it comes back.
- memory() takes a spare with remove, not swap_remove (the order fix of
  the trustno1-coder#3947 port); give_back's cap now evicts the biggest first, as
  upstream.
- The made_size test is replaced by upstream's twelve.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant