Skip to content

GPU: cap idle snapshot pool memory (#472 rebased; 2 GB RAM in the world) - #2153

Open
desplmfao wants to merge 3 commits into
Marvisak:mainfrom
desplmfao:fix/snapshot-pool-472
Open

desplmfao wants to merge 3 commits into
Marvisak:mainfrom
desplmfao:fix/snapshot-pool-472

Conversation

@desplmfao

Copy link
Copy Markdown

This is #472 by @SaymonMaster14, brought up to date with main. Their commit is kept as is, with them as author, and only the conflicts are resolved. #472 conflicts with main, and I didn't want to push to someone else's branch. If #472 gets rebased, close this one.

What it does (from #472)

  • shadow.rs, give_back: the idle snapshot pool kept the largest buffers up to 2 GiB (POOL_BYTES = 2 << 30 on main). Now it always keeps the largest buffer, whose reuse saves the page faults, and keeps others only up to 256 MiB, 8 at most.
  • texture.rs: every Staging kept a Vec the size of its whole texture for good. One shared, already-touched SCRATCH buffer replaces them.
  • dstorage.rs: the intermediate buffer of zlib-then-BCPack requests (merged without conflict).

Conflict resolution

Measured

Grand Theft Auto VI (Series X 1.0.2.1) in the world, RTX 5080, Linux, proton-cachyos 11.0. Live allocations of 1 MiB or more by call site, from a counting global allocator (diagnostics, not part of this PR):

in the world main with this PR
Shadow::writing snapshots (pool + live) 2,040 MB in 111 blocks 111–214 MB in 8 blocks
Staging::refresh buffers 137 MB in 24 blocks not among the top sites
frame time (average of 12 frame-rate lines) 442 ms 451 ms; 428–452 ms in a second run

The frame time is within run-to-run noise, so I can't see a slowdown from the smaller pool.

Recommended with it: #2099

Once the pool was capped, VIctory's heap still grew about 200 MB every 30 s in the world. That growth is the descriptor view table, which #2099 (@0xkn0wh3r3) fixes. It merges cleanly with this PR. With both (and #2151), VIctory's own heap stayed flat at about 1.4 GB in the world, against about 4.2 GB and growing before.

Tested

  • cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean.
  • victory-gpu tests on the RTX 5080 under Proton: 129 passed, 13 failed, the same 13 as main on this setup.
  • The game runs into the world.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

The snapshot `Shadow::writing` keeps, to tell later what a submission's shaders
wrote, is grown to span every range the submission declares. Growing it
allocated a second buffer of the new size, copied the old one in, and only then
returned it to the pool: at the largest growth that holds twice the buffer, and
the world's heap is 174 MB, so the peak doubles right where commit is already
tight.

Grow the old buffer in place instead (`reserve_exact` for exactly the growth,
then extend on either side). The pool that feeds the snapshot kept its eight
largest buffers whatever their size, so after the world had grown once it could
hold eight 174 MB buffers, about 1.4 GB idle. Keep the largest (its reuse is
what saves the millions of page faults the 64 KiB pages were chosen for) and
further buffers only up to 256 MiB.

Measured on a 16 GB machine, world load, release build: the process reached
18.0 GB private and died at `memory allocation of 70426816 bytes failed` with
the system commit at 48.8 GB of a 49.0 GB limit. It is not a fix for that
limit, and not comparable to earlier runs (those measured the page file, not
`PrivateMemorySize64`) — the counters to compare it against do not exist yet.

Refs Marvisak#407: this is bridge work, which that issue proposes to delete. It stays
valid until stage 2 there (xmem asks a GPU-visible arena first) replaces the
copies.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Idle snapshot pool memory capped (#472 rebased, 2 GB RAM) — memory-cap fix for long sessions; mixed gpu+hle, Windows-only.

@yualk

yualk commented Nov 25, 2026

Copy link
Copy Markdown

Independent Windows x64 CPU-only probe on parent 940d32f69 vs this exact d23e5d9, using each pin's real pooled/give_back, touched pages, and GetProcessMemoryInfo(PROCESS_MEMORY_COUNTERS_EX). Only the idle shadow pool was exercised; no title, GPU dispatch, texture staging, or DirectStorage inputs.

  • Twelve 8 MiB leases, ABBA: both first and second live sets stayed 96 MiB; retained idle capacity 96 → 64 MiB. Process-private charge fell 32.08 MiB between arms at the idle sample. The refill touched all 12 again: observed page faults 9 → 8,222 and median measured lease/fill/check 3.52 → 5.11 ms.
  • Four 96 MiB leases, ABBA: both live sets stayed 384 MiB; idle 384 → 288 MiB and Windows private charge fell 96.19 MiB. Refill faults 9 → 24,635, measured 14.46 → 18.17 ms.
  • Small fit [8,32,96] kept and reused all leases on both. [384,128,128] kept all 640 MiB on both (largest + 256 MiB spare), so this is not a hard 256 MiB total-idle cap. The absolute values include allocator overhead. These are controlled refill costs, not an FPS or live game commit claim. AI-assisted.

zhaibingye added a commit to zhaibingye/VIctory that referenced this pull request Nov 25, 2026
Adapt the snapshot-pool part of Marvisak#2153 (also Marvisak#472). Do not import the unrelated texture or storage changes. Cap total idle capacity including the largest buffer, preserve the best-fitting allocation path, and limit idle entries to eight. Active snapshot correctness is unchanged.

Portable pool regression and Windows all-feature workspace test source checks passed.

Co-authored-by: Davi Andrei <67552001+SaymonMaster14@users.noreply.github.com>
… fails

A pool miss allocated with Vec::with_capacity, which aborts the process
when the allocation fails, even while the pool still holds idle buffers
(too small to fit, but up to POOL_BYTES plus the largest one). Try the
allocation with try_reserve_exact first; when it fails and the pool is
not empty, drop the idle buffers and make one last attempt with
reserve_exact, which aborts as before if that fails too. Pool hits and
successful misses are unchanged.

Idea from fxceless/victory-fork#360.

Co-Authored-By: avt0m4t48 <56218626+avt0m4t48@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Author

Added d389937: when a new snapshot buffer can't be allocated, the idle pool is freed and the allocation tried once more (try_reserve_exact first, so a failed attempt returns instead of aborting). The idea comes from fxceless/victory-fork#360 (avt0m4t48, credited in the commit). It only changes the out-of-memory path. cargo test -p victory-gpu shadow: 4 passed. Clippy is clean.

@desplmfao

Copy link
Copy Markdown
Author

@yualk thanks for the independent probe. That matches the intent: the largest idle buffer is always kept, and others only up to 256 MiB more, so [384,128,128] keeping 640 MiB is by design, not a total cap. Keeping the largest is what saves most of the page faults on the hot path (the world's big heap snapshot). The extra faults you measured are the cost of refilling the smaller ones. In the game that cost didn't show up in frame time: 428–452 ms per world frame with this PR against 442–451 ms without it (RTX 5080, Linux/Proton), while the idle pool went from 2,040 MB to 111–214 MB.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. Thanks for 0f13780. staging_bytes in dstorage.rs is back to main's version, and the PR no longer touches victory-hle.

What's left, all of which I checked:

  • give_back in crates/victory-gpu/src/shadow.rs always keeps the largest idle snapshot buffer, then others up to 256 MiB and 8 in all. This replaces the 2 GiB POOL_BYTES.
  • pooled tries try_reserve_exact first, and on failure frees the idle pool before the aborting reserve_exact.
  • texture.rs uses one shared SCRATCH in place of a per-texture Last::read. It is taken under each texture's last lock, always in that order, so it adds no lock-order problem.

The measured effect: the idle pool goes from 2,040 MB to 111–214 MB, with world frame time unchanged (428–452 ms against 442–451 ms). The CPU-only probe in the thread shows the refill cost of the smaller buffers. CI check passes at 0f13780.

For the maintainers: this is #472 (by @SaymonMaster14) brought up to date, with credit. #472 does not merge, so whichever lands, the other should be closed.


Generated by Claude Code

The pool cap doesn't need it, and counting a zlib-then-BCPack request's
intermediate buffer against the staging budget changes when the title's
reads start, without evidence that the console counts it. As asked in the
triage, it goes from this PR.

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

Copy link
Copy Markdown
Author

Thanks for the triage. Done in 0f13780: staging_bytes in dstorage.rs is back to main's version, and this PR no longer touches victory-hle. It came along with the #472 rebase. As you say, the pool cap doesn't need it, and I have no evidence that the console counts the intermediate buffer, so it's out rather than moved. What's left is the pool cap (give_back, POOL_BYTES), the idle-pool retry before reserve_exact aborts, and the shared texture SCRATCH. Clippy is clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants