gpu: reclaim draining texture blocks under memory pressure #501

Open
github-bot wants to merge 4 commits from github-bot/gh-501 into main AGit
Owner

@⁠maple-quartz18 on GitHub · 2026-12-04 19:27 UTC · original
maple-quartz18:pr/texture-block-reclamation → main · +645 −106 · 2 files · 4 commits · draft

Problem

Under sustained card-memory pressure, texture blocks selected for draining can remain occupied by active host copies, and a drained block that becomes empty can be kept as a spare instead of being returned. On shared-memory APUs, this can retain memory during world streaming.

Change

  • At 90% of the reported card budget, request at least one block for reclamation when no fully drained block is already being retired. Continue using the existing evacuation path and its per-pass budget.
  • Retire an emptied, previously draining texture block even when the spare limit would otherwise retain it. Keep the existing ownership, quarantine, and retirement paths; this does not forcibly release a block that remains referenced or in use.
  • VICTORY_POOL_FORCE_RELEASE=0 disables the behavior. The current patch enables it by default; feedback on making this opt-in is welcome.

Dependency and validation

Draft, based on #393. This branch includes its three commits and is not intended to merge before that PR. It adapts the change from a local tree that also has other patches; this exact rebased tree has not yet been built or run in game.

On the local integrated tree, a Windows-target release build passed, and two focused Wine tests passed: pressure/pending policy and a drained block remaining held before its fence threshold and becoming reclaimable after it. No gameplay, memory-pressure, image-correctness, long-run stability, or FPS comparison has been done. Real workloads may retain references indefinitely or increase texture reuploads and stutter. The existing time-based fallback remains unchanged.

**@⁠maple-quartz18** on GitHub · 2026-12-04 19:27 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/501) `maple-quartz18:pr/texture-block-reclamation` → `main` · +645 −106 · 2 files · 4 commits · draft ## Problem Under sustained card-memory pressure, texture blocks selected for draining can remain occupied by active host copies, and a drained block that becomes empty can be kept as a spare instead of being returned. On shared-memory APUs, this can retain memory during world streaming. ## Change - At 90% of the reported card budget, request at least one block for reclamation when no fully drained block is already being retired. Continue using the existing evacuation path and its per-pass budget. - Retire an emptied, previously draining texture block even when the spare limit would otherwise retain it. Keep the existing ownership, quarantine, and retirement paths; this does not forcibly release a block that remains referenced or in use. - `VICTORY_POOL_FORCE_RELEASE=0` disables the behavior. The current patch enables it by default; feedback on making this opt-in is welcome. ## Dependency and validation **Draft, based on #393.** This branch includes its three commits and is not intended to merge before that PR. It adapts the change from a local tree that also has other patches; this exact rebased tree has not yet been built or run in game. On the local integrated tree, a Windows-target release build passed, and two focused Wine tests passed: pressure/pending policy and a drained block remaining held before its fence threshold and becoming reclaimable after it. No gameplay, memory-pressure, image-correctness, long-run stability, or FPS comparison has been done. Real workloads may retain references indefinitely or increase texture reuploads and stutter. The existing time-based fallback remains unchanged.
take() and take_ripe() took the blocks take_piece() let go of and dropped
them where they stood: a 64 MiB heap block past the spares was unmapped
live instead of going back to the caller for host::retire (and never
counted in GOING/GONE). Both were dead code outside the tests, so they are
test-only now and return what went with the piece.

take_piece() returns what went instead of taking it as a seventh argument
(clippy::too_many_arguments, the one lint pool.rs had), and its two
searches (blocks that stay, blocks being emptied) are kept() and
emptying(). No behaviour change.
A texture's piece given back rested five seconds before it could be used
again (REST; the module doc said two), by the clock alone. Under pressure
that is a loop: the sweep lets host copies go to give blocks back, their
pieces rest, the blocks cannot go back, new textures go into new blocks,
the card fills, more is let go and made again (a 16 GB card on Boat and
Prison: 94 % of its budget, 1,325 passes without room, 14,721 copies made
again).

The pool of textures is fenced now: a piece is free once the card finished
FENCE_LAG (128, as host::BURY_LAG) submissions after the newest one that
may name what it held (STARTED + queued(), as host::retire counts it),
rested or not. Staging buffers are the PC's memory: they rest by the clock
alone. REST stays as the fallback for a card that finishes nothing.

When it is looked for: for want of room in take_piece(), before a block
being emptied is refilled or a new one made; and in the once-a-second
sweep of room(), so that a block the sweep emptied is back on the card two
frames on. The least free_from gates the walk of what rests: a look that
finds nothing costs nothing.

Tests: one short of FENCE_LAG a piece is not touched, at FENCE_LAG the same
piece is used again with no block made, a pool that is not fenced rests,
only what the card is through with goes, blocks made whole go back past
the spares at once (the sweep's look and for want of room), and 4,000
pseudo-random steps on a card of eight blocks check that pieces never
overlap and none is used again before it rested or the card is through
with it.
Port of PR #279 to the current pool: staging pieces come back with the
last list that names them (finished by then), so the upload heap can rest
250 ms instead of 5 s and be reused and retired sooner during streaming
bursts. Texture pieces keep the 5 s clock and the fence path (PR #364).

(cherry picked from commit 7cff9880a07bc70dc50f5c595c630c6e89f1a80a)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 19:32:33 +00:00
Author
Owner

@⁠YaBulochka on GitHub · 2026-12-04 19:39 UTC · original

A negative result from the page side that may be worth knowing before draining blocks.

On an 8 GiB card (RX 7600 XT, RADV, Series S + FSR) I measured what the page table holds: 156–166 k pages of 64 KiB in um::lazy's TABLE, of which only 19–21 k had a view at the title's address. The rest — 8.6 to 9.1 GB, and growing — is BOUND without REAL.

I read that as the reclaim target and tried it: unbind(page << 16, K64) for pages that are BOUND, not REAL, not KEPT, not wanted, and not shown for 40 s.

  • first pass gave back 65 077 pages (4 GB) at once → device loss immediately;
  • 128 pages per second (8 MB per pass) → device loss after about 20 s, 0x80000003.

So in this tree BOUND && !REAL is not unused memory: the card reads through the aliases, and a page stays BOUND after the title drops its own view, because recorded lists still name it. Neither wanted() nor the SEEN bit covered those pages reliably enough.

If #501 drains whole texture blocks, the hazard is probably the same one step up: a block can hold pages that recorded lists still name. What would settle it either way is a counter of "blocks whose pieces are free but whose pages some list in flight still names", measured next to no_room_passes on a small card.

Numbers and the two crash runs are in a local probe set; I can paste the log lines if useful. The measurement line that came out of it is one line in um::lazy::line(): held but not mapped: N pages (M MB), K mapped at the title.

**@⁠YaBulochka** on GitHub · 2026-12-04 19:39 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/501#issuecomment-7422210823) A negative result from the page side that may be worth knowing before draining blocks. On an 8 GiB card (RX 7600 XT, RADV, Series S + FSR) I measured what the page table holds: 156–166 k pages of 64 KiB in `um::lazy`'s `TABLE`, of which only 19–21 k had a view at the title's address. The rest — 8.6 to 9.1 GB, and growing — is `BOUND` without `REAL`. I read that as the reclaim target and tried it: `unbind(page << 16, K64)` for pages that are `BOUND`, not `REAL`, not `KEPT`, not `wanted`, and not shown for 40 s. - first pass gave back 65 077 pages (4 GB) at once → device loss immediately; - 128 pages per second (8 MB per pass) → device loss after about 20 s, `0x80000003`. So in this tree `BOUND && !REAL` is not unused memory: the card reads through the aliases, and a page stays `BOUND` after the title drops its own view, because recorded lists still name it. Neither `wanted()` nor the `SEEN` bit covered those pages reliably enough. If #501 drains whole texture blocks, the hazard is probably the same one step up: a block can hold pages that recorded lists still name. What would settle it either way is a counter of "blocks whose pieces are free but whose pages some list in flight still names", measured next to `no_room_passes` on a small card. Numbers and the two crash runs are in a local probe set; I can paste the log lines if useful. The measurement line that came out of it is one line in `um::lazy::line()`: `held but not mapped: N pages (M MB), K mapped at the title`.
Author
Owner

@⁠maple-quartz18 on GitHub · 2026-12-05 04:47 UTC · original

A negative result from the page side that may be worth knowing before draining blocks.

On an 8 GiB card (RX 7600 XT, RADV, Series S + FSR) I measured what the page table holds: 156–166 k pages of 64 KiB in um::lazy's TABLE, of which only 19–21 k had a view at the title's address. The rest — 8.6 to 9.1 GB, and growing — is BOUND without REAL.

I read that as the reclaim target and tried it: unbind(page << 16, K64) for pages that are BOUND, not REAL, not KEPT, not wanted, and not shown for 40 s.

  • first pass gave back 65 077 pages (4 GB) at once → device loss immediately;
  • 128 pages per second (8 MB per pass) → device loss after about 20 s, 0x80000003.

So in this tree BOUND && !REAL is not unused memory: the card reads through the aliases, and a page stays BOUND after the title drops its own view, because recorded lists still name it. Neither wanted() nor the SEEN bit covered those pages reliably enough.

If #501 drains whole texture blocks, the hazard is probably the same one step up: a block can hold pages that recorded lists still name. What would settle it either way is a counter of "blocks whose pieces are free but whose pages some list in flight still names", measured next to no_room_passes on a small card.

Numbers and the two crash runs are in a local probe set; I can paste the log lines if useful. The measurement line that came out of it is one line in um::lazy::line(): held but not mapped: N pages (M MB), K mapped at the title.

Can you use APU?

**@⁠maple-quartz18** on GitHub · 2026-12-05 04:47 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/501#issuecomment-7432127585) > A negative result from the page side that may be worth knowing before draining blocks. > > On an 8 GiB card (RX 7600 XT, RADV, Series S + FSR) I measured what the page table holds: 156–166 k pages of 64 KiB in `um::lazy`'s `TABLE`, of which only 19–21 k had a view at the title's address. The rest — 8.6 to 9.1 GB, and growing — is `BOUND` without `REAL`. > > I read that as the reclaim target and tried it: `unbind(page << 16, K64)` for pages that are `BOUND`, not `REAL`, not `KEPT`, not `wanted`, and not shown for 40 s. > > * first pass gave back 65 077 pages (4 GB) at once → device loss immediately; > * 128 pages per second (8 MB per pass) → device loss after about 20 s, `0x80000003`. > > So in this tree `BOUND && !REAL` is not unused memory: the card reads through the aliases, and a page stays `BOUND` after the title drops its own view, because recorded lists still name it. Neither `wanted()` nor the `SEEN` bit covered those pages reliably enough. > > If [#501](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/501) drains whole texture blocks, the hazard is probably the same one step up: a block can hold pages that recorded lists still name. What would settle it either way is a counter of "blocks whose pieces are free but whose pages some list in flight still names", measured next to `no_room_passes` on a small card. > > Numbers and the two crash runs are in a local probe set; I can paste the log lines if useful. The measurement line that came out of it is one line in `um::lazy::line()`: `held but not mapped: N pages (M MB), K mapped at the title`. Can you use APU?
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pool.rs
  • crates/victory-gpu/src/resource.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/501/head:github-bot/gh-501'
git switch 'github-bot/gh-501'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-501'
git switch 'github-bot/gh-501'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-501'
git switch 'github-bot/gh-501'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-501'
git switch 'main'
git merge --squash 'github-bot/gh-501'
git switch 'main'
git merge --ff-only 'github-bot/gh-501'
git switch 'main'
git merge 'github-bot/gh-501'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.