GPU: taking a page while another mapping of it is busy drops it from the changed pages and its saved bytes #2454

Closed
opened 2026-11-26 05:06:23 +00:00 by github-bot · 2 comments
Owner

@⁠BastienRodz on GitHub · 2026-11-25 13:49 UTC · original

What happens

A physical page can show at two addresses, a (tracked by a host copy) and b (a pool view), linked by title_memory_aliased. While a write the guards do not see is under way through b (watch::writing(b, len): a kernel read or a DirectStorage write into the pool), b is in busy and stays open. If the copy takes the page meanwhile (Tracked::take at a refresh, or Tracked::taken after a copy-back), guard_aliases calls protect on b and ignores its result: b is skipped as busy, yet a is guarded, removed from the changed pages, and its saved bytes are dropped (Changed::taken).

Then:

  • bytes written through the still-open b before the write ends do not mark the copy, so its next refresh misses them (stale copy);
  • when the write ends, Writing::drop marks the page changed without saving. If the page is armed for marked writes, copy_back_marked finds it changed with nothing saved and keeps the title's bytes, which drops the shaders' writes to it.

title_memory_aliased ignores protect's result the same way when the new mapping of a guarded page cannot be guarded.

Expected

watch.rs: "taking a page guards every address showing it", and protect: "a page that is mapped but cannot be guarded is left out (it stays changed)". A page with a mapping that could not be guarded should stay changed and keep its saved bytes until every mapping can be guarded.

Where

crates/victory-gpu/src/watch.rs: guard_aliases, Tracked::take, Tracked::taken, title_memory_aliased.

AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.

**@⁠BastienRodz** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/2454) ### What happens A physical page can show at two addresses, `a` (tracked by a host copy) and `b` (a pool view), linked by `title_memory_aliased`. While a write the guards do not see is under way through `b` (`watch::writing(b, len)`: a kernel read or a DirectStorage write into the pool), `b` is in `busy` and stays open. If the copy takes the page meanwhile (`Tracked::take` at a refresh, or `Tracked::taken` after a copy-back), `guard_aliases` calls `protect` on `b` and ignores its result: `b` is skipped as busy, yet `a` is guarded, removed from the changed pages, and its saved bytes are dropped (`Changed::taken`). Then: - bytes written through the still-open `b` before the write ends do not mark the copy, so its next refresh misses them (stale copy); - when the write ends, `Writing::drop` marks the page changed without saving. If the page is armed for marked writes, `copy_back_marked` finds it changed with nothing saved and keeps the title's bytes, which drops the shaders' writes to it. `title_memory_aliased` ignores `protect`'s result the same way when the new mapping of a guarded page cannot be guarded. ### Expected `watch.rs`: "taking a page guards every address showing it", and `protect`: "a page that is mapped but cannot be guarded is left out (it stays changed)". A page with a mapping that could not be guarded should stay changed and keep its saved bytes until every mapping can be guarded. ### Where `crates/victory-gpu/src/watch.rs`: `guard_aliases`, `Tracked::take`, `Tracked::taken`, `title_memory_aliased`. AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:23 +00:00
Author
Owner

@⁠shawshanker18 on GitHub · 2026-11-25 16:41 UTC · original

Tested both fixes for this, each merged onto main (67e8ae1), on Windows 11 with an RTX 4050 Laptop. Command: cargo test -p victory-gpu --lib.

Merges onto main Its new tests Other failures
#2455 clean a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes: ok none beyond main's 2 (the 1,000,000 view-heap cap on NVIDIA)
#2561 clean a_page_whose_other_mapping_is_busy_is_not_taken, linking_an_unguardable_mapping_keeps_the_tracked_page_changed: ok same 2

The two conflict with each other. Both make the same change to Tracked::take and Tracked::taken: guard_aliases returns the pages it could not guard, and those stay changed. They differ in one place: in title_memory_aliased, when the new mapping cannot be guarded, #2455 calls changed(.., true) and #2561 calls changed(.., false).

  • With true, a tracker that is armed but has nothing saved yet saves the page at link time. The kernel write through the busy mapping may already be landing, so title bytes can be saved as "before", and a marked shader write over them then wins.
  • With false, nothing is saved, so a marked copy-back keeps the title's bytes and drops the shader's write there. That is the same outcome as Writing::drop in the issue.

Neither is lossless in that window. false is the conservative one for title data.

One more difference: #2561's tests unlink and open their alias pages at the end; #2455's test does not. That could matter for full-workspace runs where tests reuse pages (compare #1882, #2252).

#2415 (for #2414) merges cleanly with either of them.

**@⁠shawshanker18** on GitHub · 2026-11-25 16:41 UTC · [original](https://github.com/Marvisak/VIctory/issues/2454#issuecomment-7168375116) Tested both fixes for this, each merged onto `main` (`67e8ae1`), on Windows 11 with an RTX 4050 Laptop. Command: `cargo test -p victory-gpu --lib`. | | Merges onto `main` | Its new tests | Other failures | |---|---|---|---| | #2455 | clean | `a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes`: ok | none beyond `main`'s 2 (the 1,000,000 view-heap cap on NVIDIA) | | #2561 | clean | `a_page_whose_other_mapping_is_busy_is_not_taken`, `linking_an_unguardable_mapping_keeps_the_tracked_page_changed`: ok | same 2 | The two conflict with each other. Both make the same change to `Tracked::take` and `Tracked::taken`: `guard_aliases` returns the pages it could not guard, and those stay changed. They differ in one place: in `title_memory_aliased`, when the new mapping cannot be guarded, #2455 calls `changed(.., true)` and #2561 calls `changed(.., false)`. - With `true`, a tracker that is armed but has nothing saved yet saves the page at link time. The kernel write through the busy mapping may already be landing, so title bytes can be saved as "before", and a marked shader write over them then wins. - With `false`, nothing is saved, so a marked copy-back keeps the title's bytes and drops the shader's write there. That is the same outcome as `Writing::drop` in the issue. Neither is lossless in that window. `false` is the conservative one for title data. One more difference: #2561's tests unlink and open their alias pages at the end; #2455's test does not. That could matter for full-workspace runs where tests reuse pages (compare #1882, #2252). #2415 (for #2414) merges cleanly with either of them.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:49 UTC · original

Automated triage for the maintainers.

Confirmed in main. In crates/victory-gpu/src/watch.rs, guard_aliases calls protect(g, &others) and discards the list it returns. protect filters out pages in g.busy, and says in its docs that a page it could not guard "is left out (it stays changed)". So the tracked page is taken even though another mapping of it is still open.

There are two open PRs, and they conflict with each other:

Both make Tracked::take and Tracked::taken keep such pages changed. They differ only in title_memory_aliased: #2455 calls changed(.., true) and #2561 calls changed(.., false). The comment above explains the trade-off. #2415 (for #2414) merges cleanly with either.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/2454#issuecomment-7171458750) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T16:41:12Z at=2026-11-25T19:00:00Z --> Automated triage for the maintainers. Confirmed in main. In `crates/victory-gpu/src/watch.rs`, `guard_aliases` calls `protect(g, &others)` and discards the list it returns. `protect` filters out pages in `g.busy`, and says in its docs that a page it could not guard "is left out (it stays changed)". So the tracked page is taken even though another mapping of it is still open. There are two open PRs, and they conflict with each other: - #2455 - #2561 Both make `Tracked::take` and `Tracked::taken` keep such pages changed. They differ only in `title_memory_aliased`: #2455 calls `changed(.., true)` and #2561 calls `changed(.., false)`. The comment above explains the trade-off. #2415 (for #2414) merges cleanly with either. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#2454
No description provided.