Skip to content

memory: keep a packed structure's pages when another one replaces it at the same address - #1878

Open
xteral67 wants to merge 1 commit into
trustno1-coder:mainfrom
xteral67:fix-packed-replace
Open

xteral67 wants to merge 1 commit into
trustno1-coder:mainfrom
xteral67:fix-packed-replace

Conversation

@xteral67

@xteral67 xteral67 commented Nov 29, 2026 •

Copy link
Copy Markdown

No issue filed: found while profiling city driving with ray tracing on.

What it changes

What was wrong. With ray tracing on, driving fast through a city made the game drop to 0.3-2 fps for 5-60 s at a time. Often it did not recover even when standing still, and on the release build it often ended in a device removal (0x887A0005, the card hung past the TDR delay). GPU timing showed the ray walk shaders (indirect-walk) going from 2-15 ms to 340-670 ms a frame. The builder itself stayed cheap.

Memory dumps (VICTORY_MEMORY_DUMP) taken during the slowdown showed 23-36 instances of the walked top level structures pointing at bottom level structures whose arena pages still held the packed header (0x...81020006). Rays walked packed bytes as nodes until their iteration limit.

A per-structure history of Memory::land showed the same sequence for every one of them:

  1. Structure A streams in at an address, lands, is unpacked, and works.
  2. Structure B streams in at the same address. land sees another header and calls gone(A): A's pages go back to the free list and their directory entries become 0.
  3. The re-insert places B's pages again. The free list hands them out last-in first, so they come back at other places in the arenas.
  4. That submission has already asked the write watch, so the card's directory still names the old places when the builder unpacks B. B's packed bytes go up to the new places, and nothing unpacks them again.

Structures landing at a fresh address never broke. Only replacements at the same address did. That happens a lot when streaming in fast.

What this does. When a known packed structure gives way to another one at the same address, the new Memory::replaced drops it like gone does, but keeps its pages where they are. The new structure takes the same places, so the directory does not change and the builder unpacks where the rays later read.

Works together with #1161 (merged, off by default). This fix only shows when the compacted sizes reach the title's copies (VICTORY_BVH_SIZE_COPY=1). Without that, the copies of compacted structures are still wrong and the slowdown stays, with or without this change. Neither of the two alone stops it; together they do (numbers below).

Trade-off. If the new structure is shorter than the old one, the old one's tail pages stay held with no owner until the address is reused. This is a small, bounded leak, traded for not touching the directory in the middle of a submission.

How it was tested

  • GPU and profile: RTX 3080 Ti, Windows 11, Series X profile, 1440p, DLSS Quality, FSR 3 frame generation, the title's ray tracing on (VICTORY_BVH_BUILDER=1, VICTORY_AMBIENT=0). The same city route at high speed by car in every run. Numbers are fps per 5 s interval, in game only.

v2026.11.28.03 + #1161 cherry-picked (VICTORY_BVH_SIZE_COPY=1):

fps per 5 s interval End
Before (no fix) 9 10 2 11 10 8 9 8 8 8 7 9 8 9 7 9 8 9 7 1 6 6 device removed (0x887A0005)
After 16 12 13 11 9 9 9 8 8 7 8 5 6 6 6 8 8 6 11 7 no crash, no interval under 5 fps

v2026.11.28.03 alone (no #1161): with or without this fix, the slowdown to 0-3 fps and a device removal at speed.

A build close to v2026.11.27.9 that already has the compacted size copies, switching one thing at a time:

fps per 5 s interval
Fix off 10 12 10 11 9 8 9 3 6 1 1 0 2 1 (did not recover)
Fix on (an earlier run, the same kind of driving) steady 10-11, lowest 4.5 at a loading moment
Fix on, size copies off 14 14 7 5 4 6 ... 1 ... 1 ... 2 1

Diagnostics build, same place and route:

Before After
Broken (packed) structures in the dump 23-36 0 (560 replacements in that run)
Mean frame over 5 s intervals ~1,020 ms ~124 ms
Intervals slower than 300 ms 19 2
  • Rebased onto d585f88. There memory.rs gained Memory by address: the arenas' writes are told, the kernel is not asked about them #1062 and gpu: keep faulted pages under a budget #722 (gone now tells the write watch about the directory entries it clears, and faulted pages are kept under a budget); the only conflict was the two new functions sitting next to each other. The driving runs above are on v2026.11.28.03 and on a build close to v2026.11.27.9, cargo test on d4b5d51; this exact rebased commit was not driven again.
  • For shader changes, the wave sizes tested: no shader changes.
  • cargo test passed for the crates it touches: yes, cargo test --release -p victory-gpu on main at d4b5d51 with this change: 550 passed, 0 failed. In one earlier run descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes failed once (view width 6291456 instead of 65536) and passed on the next run with no change; it does not touch title memory by address, so it looks flaky (tests sharing a pool while running in parallel?).

Checked for overlap

🤖 Generated with Claude Code

…at the same address

When a known packed structure gave way to another one at the same address,
`land` called `gone`: the pages went back to the free list (last in, first
out) and the re-insert placed them elsewhere, while the submission had
already asked the write watch. The builder unpacked the new structure where
the card's directory still pointed, the packed bytes went up to the new
places, and rays walked them as nodes until their iteration limit.

`Memory::replaced` drops the structure as `gone` does but keeps its pages
where they are, so the new structure takes the same places.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-fix] memory: keep a packed structure's pages when another one replaces it at the same address memory: keep a packed structure's pages when another one replaces it at the same address Nov 29, 2026
@xteral67

xteral67 commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

A note on #1161, since it is merged but off by default (VICTORY_BVH_SIZE_COPY):

With the title's ray tracing on (VICTORY_BVH_BUILDER=1), the size copies look required rather than optional. In the runs above, city at speed on an RTX 3080 Ti:

  • without the size copies, rays degrade to 4-6 fps with drops to 1 fps, and on v2026.11.28.03 the card is removed (0x887A0005), with or without this PR;
  • with the size copies but without this PR: the freeze to 0-1 fps and a device removal;
  • with both: no freeze, no interval under 5 fps.

So it may be worth turning VICTORY_BVH_SIZE_COPY on whenever the builder is on, or by default.

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

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant