Title memory by address: give back the numbers of copies named longest ago (VICTORY_MEMORY_RECLAIM) #1082

Open
github-bot wants to merge 1 commit from github-bot/gh-1082 into main AGit
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-25 18:45 UTC · original
SpaghettiMaster545:pr/memory-reclaim → main · +248 −26 · 1 files · 1 commits · open

What was wrong

Title memory reached by raw address (memory.rs) gives each copy a number in the directory, and a number is never given back. There are 1023 of them (COPIES). With the structure builder on (VICTORY_BVH_BUILDER=1) they run out within seconds of its start, mostly on 4 MiB windows of real card memory: in one of our runs, 1010 windows and 13 buffers, 4,300 MiB. From then on every page that has no number yet reads zeros and its stores are dropped, for the rest of the run ("no number left for another copy").

More numbers only put it off. With finer windows and 8191 numbers the count kept growing the whole time: 4096 numbers 50 s after the builder started, all 8191 at three minutes (8146 windows, 2,671 MiB).

How it shows

With the builder on, the walks over the structures read zeros wherever their pages came after the last number. Builder off (the default), a run rarely gets near the limit.

What the change does

Numbers are given back.

  • When: once a frame, when fewer than a sixteenth of the numbers are left.
  • Which: the eighth of the copies that dispatches named longest ago. "Named" means a root view, a root constant, an address taken from a view, or a fault.
  • Giving back: a number's directory entries are emptied, the number word before the offset, so no shader pairs an old offset with a new number. A shader that still reaches those pages faults, and they are numbered again the next frame.
  • Quarantine: a number goes back into use only after 8 frames. By then no list recorded before can still read the directory or the old view. The old copy is held for 8 more frames after its number is reused.
  • Views: each heap's run of views rewrites the views of numbers taken again.
  • Off switch: VICTORY_MEMORY_RECLAIM=0 keeps every number for the run, as before.

Limitation: a copy reached only through pointers read out of memory looks old to the host while it is still read. It can lose its number, and its pages then read zeros for a frame until they are numbered again.

The pure parts, choosing the oldest copies and deciding when a number's quarantine is over, have a unit test: numbers_named_longest_ago_go_back_and_wait_out_a_quarantine.

How it was tested

  • On this branch (based on main d510ee4): cargo test --locked -p victory-gpu --lib memory passes (15, the new test among them). cargo clippy -p victory-gpu --all-targets -- -D warnings reports nothing in memory.rs; it stops on lints main already has elsewhere in victory-gpu.
  • In game, in our integration tree, where the same change has run since today: builder off (the default), 166.8 ms a frame in the first room, no GPU failure.
  • Builder on with 8191 numbers: the numbers held. About every 16 frames 1023 numbers went back and were taken again, with no crash in the run.
  • Builder on with this tree's 1023 numbers: the builder's first frame alone took all of them, so numbers go back and come again every frame. It no longer stops for good, but it thrashes. A switch for more numbers is a separate change.
  • One limit if you try more numbers through the card's own heaps: an RTX 5070 Ti opens a 4,095 MiB heap and refuses 4,096 MiB.
  • GPU and driver: NVIDIA GeForce RTX 5070 Ti, driver 621.40, Windows 11.
**@⁠SpaghettiMaster545** on GitHub · 2026-11-25 18:45 UTC · [original](https://github.com/fxceless/victory-fork/pull/1082) `SpaghettiMaster545:pr/memory-reclaim` → `main` · +248 −26 · 1 files · 1 commits · open ## What was wrong Title memory reached by raw address (`memory.rs`) gives each copy a number in the directory, and a number is never given back. There are 1023 of them (`COPIES`). With the structure builder on (`VICTORY_BVH_BUILDER=1`) they run out within seconds of its start, mostly on 4 MiB windows of real card memory: in one of our runs, 1010 windows and 13 buffers, 4,300 MiB. From then on every page that has no number yet reads zeros and its stores are dropped, for the rest of the run ("no number left for another copy"). More numbers only put it off. With finer windows and 8191 numbers the count kept growing the whole time: 4096 numbers 50 s after the builder started, all 8191 at three minutes (8146 windows, 2,671 MiB). ## How it shows With the builder on, the walks over the structures read zeros wherever their pages came after the last number. Builder off (the default), a run rarely gets near the limit. ## What the change does Numbers are given back. - **When:** once a frame, when fewer than a sixteenth of the numbers are left. - **Which:** the eighth of the copies that dispatches named longest ago. "Named" means a root view, a root constant, an address taken from a view, or a fault. - **Giving back:** a number's directory entries are emptied, the number word before the offset, so no shader pairs an old offset with a new number. A shader that still reaches those pages faults, and they are numbered again the next frame. - **Quarantine:** a number goes back into use only after 8 frames. By then no list recorded before can still read the directory or the old view. The old copy is held for 8 more frames after its number is reused. - **Views:** each heap's run of views rewrites the views of numbers taken again. - **Off switch:** `VICTORY_MEMORY_RECLAIM=0` keeps every number for the run, as before. Limitation: a copy reached only through pointers read out of memory looks old to the host while it is still read. It can lose its number, and its pages then read zeros for a frame until they are numbered again. The pure parts, choosing the oldest copies and deciding when a number's quarantine is over, have a unit test: `numbers_named_longest_ago_go_back_and_wait_out_a_quarantine`. ## How it was tested - On this branch (based on `main` d510ee4): `cargo test --locked -p victory-gpu --lib memory` passes (15, the new test among them). `cargo clippy -p victory-gpu --all-targets -- -D warnings` reports nothing in `memory.rs`; it stops on lints `main` already has elsewhere in `victory-gpu`. - In game, in our integration tree, where the same change has run since today: builder off (the default), 166.8 ms a frame in the first room, no GPU failure. - Builder on with 8191 numbers: the numbers held. About every 16 frames 1023 numbers went back and were taken again, with no crash in the run. - Builder on with this tree's 1023 numbers: the builder's first frame alone took all of them, so numbers go back and come again every frame. It no longer stops for good, but it thrashes. A switch for more numbers is a separate change. - One limit if you try more numbers through the card's own heaps: an RTX 5070 Ti opens a 4,095 MiB heap and refuses 4,096 MiB. - GPU and driver: NVIDIA GeForce RTX 5070 Ti, driver 621.40, Windows 11.
When fewer than a sixteenth of the numbers are left, the eighth of the
copies that dispatches named longest ago give theirs back: their directory
entries are emptied (a shader that still reaches those pages faults and they
are numbered again the next frame), and the number is taken again after 8
frames, when no list recorded before can read the directory or the view as
they were. Each heap's run rewrites the views of numbers taken again.
VICTORY_MEMORY_RECLAIM=0 keeps every number for the run, as before.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:11 +00:00
Author
Owner

@⁠drchef420 on GitHub · 2026-11-26 05:06 UTC · original

AI-assisted (Claude Code). Numbers and log lines only, no game data.

Two data points: without #994, 8191 numbers ran a 32 GB PC out of memory; with #994, main's 1023 held for six minutes.

RTX 5070 12 GB, 32 GB RAM (fixed 32 GB paging file), Windows 11 26300. Fork main a183ea2, COPIES raised from 1023 to 8191, builder on with a quarantine (no copy-backs of builder copies), no reclaim.

  • Copies numbered: 64 at the builder's start, 512 at +0.4 s, 1,024 at +12 s, 2,048 at +83 s; nearly all 4 MiB windows.
  • Shared video memory: 1.5 GB before the builder, 10.5 GB 35 s after, 15.7 GB at 8 minutes; the card's own 5.5 -> 9.5 GB of an 11 GB budget.
  • At 8.5 minutes: no shared buffer / no upload buffer with 0x8007000E, the title's own crash reporter recording 99% memory load and 442 MB of 69.5 GB commit free, then a crash.

And with #994 the numbers hold without this. On the same machine, main 988aa41 + #994 (7af465b), COPIES at main's 1023, no reclaim, no quarantine: 6 min 17 s with the builder on and no number left for another copy never logged; shared video memory levelled at about 10.2 GB. So most of the exhaustion we and others saw came with the overrun #994 fixes (2.2 GiB of empty nodes past its levels). The reclaim may still matter for longer runs or other scenes; we did not run it.

**@⁠drchef420** on GitHub · 2026-11-26 05:06 UTC · [original](https://github.com/fxceless/victory-fork/pull/1082#issuecomment-7183180337) *AI-assisted (Claude Code). Numbers and log lines only, no game data.* **Two data points: without #994, 8191 numbers ran a 32 GB PC out of memory; with #994, main's 1023 held for six minutes.** RTX 5070 12 GB, 32 GB RAM (fixed 32 GB paging file), Windows 11 26300. Fork `main` `a183ea2`, `COPIES` raised from 1023 to 8191, builder on with a quarantine (no copy-backs of builder copies), no reclaim. - Copies numbered: 64 at the builder's start, 512 at +0.4 s, 1,024 at +12 s, 2,048 at +83 s; nearly all 4 MiB windows. - Shared video memory: 1.5 GB before the builder, 10.5 GB 35 s after, 15.7 GB at 8 minutes; the card's own 5.5 -> 9.5 GB of an 11 GB budget. - At 8.5 minutes: `no shared buffer` / `no upload buffer` with `0x8007000E`, the title's own crash reporter recording 99% memory load and 442 MB of 69.5 GB commit free, then a crash. **And with #994 the numbers hold without this.** On the same machine, `main` `988aa41` + #994 (`7af465b`), `COPIES` at main's 1023, no reclaim, no quarantine: 6 min 17 s with the builder on and `no number left for another copy` never logged; shared video memory levelled at about 10.2 GB. So most of the exhaustion we and others saw came with the overrun #994 fixes (2.2 GiB of empty nodes past its levels). The reclaim may still matter for longer runs or other scenes; we did not run it.
Author
Owner

@⁠drchef420 on GitHub · 2026-11-26 06:10 UTC · original

AI-assisted (Claude Code). Numbers and log lines only, no game data.

Correction: the "with #994" run in my comment above used #994's COPIES = 2047, not main's 1023.

And 2047 isn't enough for a long session. Same build, 58 minutes from a save: no number left for another copy ... COPIES=2047 at 22 min 47 s after the builder came up. Shared memory had levelled at about 12 GB by then, so on a 32 GB PC numbers, not memory, are what run out first. That's the case for giving numbers back. Rendering went wrong for the player later in the run; we can't tie it to the zero pages from the log alone.

**@⁠drchef420** on GitHub · 2026-11-26 06:10 UTC · [original](https://github.com/fxceless/victory-fork/pull/1082#issuecomment-7184168359) *AI-assisted (Claude Code). Numbers and log lines only, no game data.* **Correction:** the "with #994" run in my comment above used #994's `COPIES = 2047`, not `main`'s 1023. **And 2047 isn't enough for a long session.** Same build, 58 minutes from a save: `no number left for another copy ... COPIES=2047` at 22 min 47 s after the builder came up. Shared memory had levelled at about 12 GB by then, so on a 32 GB PC numbers, not memory, are what run out first. That's the case for giving numbers back. Rendering went wrong for the player later in the run; we can't tie it to the zero pages from the log alone.
Author
Owner

@⁠drchef420 on GitHub · 2026-11-26 07:56 UTC · original

AI-assisted (Claude Code). Numbers and log lines only, no game data.

Run with this PR on top of #994: copy numbers given back 20 times over 80 minutes with the builder on, live copies held at about 1,800 of 2047, shared memory flat, no crash.

Tree. Fork main 988aa41 + #994 (7af465b) + this PR (b26d793). The only conflict is memory.rs. I kept #994's per-dispatch tracking: map returns the copy; only named copies and list upload memory are brought up to date; VICTORY_MEMORY_ALL. On top of that I kept this PR's numbering: Copy, number, reclaim, retire, and used updated on every directory hit. One point needed care. #994 brings new copies by numbered..copies.len(), and with reuse that range misses numbers taken again. I used this PR's m.fresh instead, and a fresh copy is brought whatever its per-list keys say, since its number may have held another copy earlier in the same list. COPIES stays at #994's 2047. cargo test -p victory-shader 272 passed; cargo test -p victory-gpu -- --test-threads=1 208 passed (this PR's test included).

Run. Same machine as before (RTX 5070 12 GB, 32 GB RAM, Windows 11 26300). VICTORY_BVH_BUILDER=1 VICTORY_FIRSTLANE_OWN=1, no quarantine, a new game with no save. 87 min 31 s in all; the builder came up at 7 min 56 s.

  • Copies numbered: 1,024 at +1 min 24 s. First give-back at +17 min 38 s (frame 15126): given=255 oldest=13500 newest=14039. Then 19 more, each given=255, every 1 to 20 minutes depending on where the player went. made=4096 live=1801 of=2047 at +51 min.
  • no number left for another copy logged once, in the frame of the first give-back (the given-back numbers were still in their 8-frame quarantine). It is logged only the first time, so we can't tell how often a dispatch found none during later quarantines. A per-frame count would show it.
  • Shared video memory: 10.1 GB 6 minutes after the builder came up, then between 10.3 and 12.0 GB for the remaining 73 minutes; the card's own 9.2 to 9.9 GB of about 10.7 GB. No 0x8007000E, no device removal, no ERROR lines. When the window was closed the title ended with title did not finish suspending in time; ending the title.
  • no free dynamic descriptor slots: a table is not made n=27 once, at +50 min (logged once).
  • Frames: 350 to 900 ms each at 2,000 to 10,000 draws, about the same as without this PR.

For comparison, without this PR (same tree minus b26d793, from a save, 58 minutes): numbers ran out 22 min 47 s after the builder came up, and stayed out. Shared memory levelled at about 12 GB as well, so here giving numbers back costs no memory.

Not fixed by this, as far as we can tell: a boat's engine is destroyed as soon as the player takes it, in both runs, and some character surfaces render black in later scenes. Both happen with and without this PR. We'll try the same place with the builder off to see whether the builder is involved at all.

**@⁠drchef420** on GitHub · 2026-11-26 07:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/1082#issuecomment-7185999448) *AI-assisted (Claude Code). Numbers and log lines only, no game data.* **Run with this PR on top of #994: copy numbers given back 20 times over 80 minutes with the builder on, live copies held at about 1,800 of 2047, shared memory flat, no crash.** **Tree.** Fork `main` `988aa41` + #994 (`7af465b`) + this PR (`b26d793`). The only conflict is `memory.rs`. I kept #994's per-dispatch tracking: `map` returns the copy; only named copies and list upload memory are brought up to date; `VICTORY_MEMORY_ALL`. On top of that I kept this PR's numbering: `Copy`, `number`, `reclaim`, `retire`, and `used` updated on every directory hit. One point needed care. #994 brings new copies by `numbered..copies.len()`, and with reuse that range misses numbers taken again. I used this PR's `m.fresh` instead, and a fresh copy is brought whatever its per-list keys say, since its number may have held another copy earlier in the same list. `COPIES` stays at #994's 2047. `cargo test -p victory-shader` 272 passed; `cargo test -p victory-gpu -- --test-threads=1` 208 passed (this PR's test included). **Run.** Same machine as before (RTX 5070 12 GB, 32 GB RAM, Windows 11 26300). `VICTORY_BVH_BUILDER=1 VICTORY_FIRSTLANE_OWN=1`, no quarantine, a new game with no save. 87 min 31 s in all; the builder came up at 7 min 56 s. - Copies numbered: 1,024 at +1 min 24 s. First give-back at +17 min 38 s (frame 15126): `given=255 oldest=13500 newest=14039`. Then 19 more, each `given=255`, every 1 to 20 minutes depending on where the player went. `made=4096 live=1801 of=2047` at +51 min. - `no number left for another copy` logged once, in the frame of the first give-back (the given-back numbers were still in their 8-frame quarantine). It is logged only the first time, so we can't tell how often a dispatch found none during later quarantines. A per-frame count would show it. - Shared video memory: 10.1 GB 6 minutes after the builder came up, then between 10.3 and 12.0 GB for the remaining 73 minutes; the card's own 9.2 to 9.9 GB of about 10.7 GB. No `0x8007000E`, no device removal, no `ERROR` lines. When the window was closed the title ended with `title did not finish suspending in time; ending the title`. - `no free dynamic descriptor slots: a table is not made n=27` once, at +50 min (logged once). - Frames: 350 to 900 ms each at 2,000 to 10,000 draws, about the same as without this PR. For comparison, without this PR (same tree minus `b26d793`, from a save, 58 minutes): numbers ran out 22 min 47 s after the builder came up, and stayed out. Shared memory levelled at about 12 GB as well, so here giving numbers back costs no memory. **Not fixed by this, as far as we can tell:** a boat's engine is destroyed as soon as the player takes it, in both runs, and some character surfaces render black in later scenes. Both happen with and without this PR. We'll try the same place with the builder off to see whether the builder is involved at all.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/memory.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/1082/head:github-bot/gh-1082'
git switch 'github-bot/gh-1082'

Merge

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