fix(gpu,hle): fix watch::ask_rest races, shadow::unregister retire, lazy leak, and shows_slices (#282) (#276) #359

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

@⁠Androtim on GitHub · 2026-12-02 15:55 UTC · original
Androtim:fix/gpu-watch-shadow-retire-lazy → main · +456 −53 · 5 files · 1 commits · open

Summary

Fixes findings #3, #4, and #5 from #282 (tracking bottleneck backlog #276).

Changes

  • #3 — \watch::ask_rest\ per-interval timestamps & epoch guard (\crates/victory-gpu/src/watch.rs):
    • Replaced single global \Journal::ahead_asked\ with per-interval (first, last, asked_at)\ tuples inside \Journal::ahead\ and added monotonic \Journal::ahead_epoch.
    • \sk_rest_with\ / \sk_rest_all_with\ and
      ecord_rest_pages\ re-read \j.ahead\ under \journal_mut(), abort \j.ahead\ / \j.kept\ updates when \head_epoch\ changed (or when
      equire_kept && !j.kept\ for \sk_once_extend) while still noting any \GetWriteWatch-reset pages in \j.written, and merge only newly queried intervals under
      ow\ without advancing timestamps on unheld pre-existing intervals.
    • Updated \wrote()\ and \ itle_memory_decommitted()\ to advance \sked_at\ only on sub-ranges overlapping written/decommitted pages.
  • #4 — \shadow::unregister\ GPU fence retirement (\crates/victory-gpu/src/shadow.rs):
    • Drop the \BUFFERS\ lock before calling \shadow.mark_retired()\ and pass \shadow\ to \crate::host::retire(shadow)\ so \shadow.buffer\ and \card.before\ hash slices are never synchronously dropped or returned to \HASH_POOL\ while GPU submissions remain in flight.
  • #5 — Bounded \STATES\ map & \xmem::shows_slices\ \LAZY\ check (\crates/victory-gpu/src/host/lazy.rs, \crates/victory-gpu/src/host.rs, \crates/victory-gpu/src/shadow.rs, \crates/victory-hle/src/modules/xmem.rs):
    • Added \lazy::forget(self.id)\ invoked in \Drop for Shadow\ so destroyed \Shadow\ instances do not leak entries in \STATES.
    • Added \has_lazy_overlap(base, len)\ in \Physical::shows_slices\ so non-lazy \XMemMapPhysicalPages\ / \lias_as\ calls never skip materializing ranges that are still backed only by \LAZY\ \MEM_RESERVE\ entries.

Testing

  • \cargo clippy -p victory-gpu -p victory-hle --lib --tests -j 4 -- -D warnings\ (and --all-features): passed cleanly
  • \cargo test -p victory-gpu --lib -j 4 -- --test-threads=1 watch:: shadow:: host::lazy::: 129 passed, 0 failed, 3 ignored (new tests: \head_per_interval_timestamps_and_splitting_preserve_unqueried_ages, \sk_rest_preserves_unheld_ahead_timestamps_and_respects_epoch_end, \unregister_retires_shadow_via_host_retire_instead_of_dropping_synchronously, \drop_forgets_lazy_compare_state, \ orget_removes_shadow_entry_without_disturbing_peers)
  • \cargo test -p victory-hle --lib -j 4: 241 passed (+ 1 subprocess test), 0 failed, 3 ignored (includes
    on_lazy_remap_and_alias_materialize_overlapping_lazy_views)
  • \cargo test -p xtask -j 4: 8 policy tests passed
**@⁠Androtim** on GitHub · 2026-12-02 15:55 UTC · [original](https://github.com/Androtim/MiniVI/pull/359) `Androtim:fix/gpu-watch-shadow-retire-lazy` → `main` · +456 −53 · 5 files · 1 commits · open ## Summary Fixes findings #3, #4, and #5 from #282 (tracking bottleneck backlog #276). ## Changes - **#3 — \watch::ask_rest\ per-interval timestamps & epoch guard (\crates/victory-gpu/src/watch.rs\):** - Replaced single global \Journal::ahead_asked\ with per-interval \(first, last, asked_at)\ tuples inside \Journal::ahead\ and added monotonic \Journal::ahead_epoch\. - \sk_rest_with\ / \sk_rest_all_with\ and \ ecord_rest_pages\ re-read \j.ahead\ under \journal_mut()\, abort \j.ahead\ / \j.kept\ updates when \head_epoch\ changed (or when \ equire_kept && !j.kept\ for \sk_once_extend\) while still noting any \GetWriteWatch\-reset pages in \j.written\, and merge only newly queried intervals under \ ow\ without advancing timestamps on unheld pre-existing intervals. - Updated \wrote()\ and \ itle_memory_decommitted()\ to advance \sked_at\ only on sub-ranges overlapping written/decommitted pages. - **#4 — \shadow::unregister\ GPU fence retirement (\crates/victory-gpu/src/shadow.rs\):** - Drop the \BUFFERS\ lock before calling \shadow.mark_retired()\ and pass \shadow\ to \crate::host::retire(shadow)\ so \shadow.buffer\ and \card.before\ hash slices are never synchronously dropped or returned to \HASH_POOL\ while GPU submissions remain in flight. - **#5 — Bounded \STATES\ map & \xmem::shows_slices\ \LAZY\ check (\crates/victory-gpu/src/host/lazy.rs\, \crates/victory-gpu/src/host.rs\, \crates/victory-gpu/src/shadow.rs\, \crates/victory-hle/src/modules/xmem.rs\):** - Added \lazy::forget(self.id)\ invoked in \Drop for Shadow\ so destroyed \Shadow\ instances do not leak entries in \STATES\. - Added \has_lazy_overlap(base, len)\ in \Physical::shows_slices\ so non-lazy \XMemMapPhysicalPages\ / \lias_as\ calls never skip materializing ranges that are still backed only by \LAZY\ \MEM_RESERVE\ entries. ## Testing - \cargo clippy -p victory-gpu -p victory-hle --lib --tests -j 4 -- -D warnings\ (and \--all-features\): passed cleanly - \cargo test -p victory-gpu --lib -j 4 -- --test-threads=1 watch:: shadow:: host::lazy::\: 129 passed, 0 failed, 3 ignored (new tests: \head_per_interval_timestamps_and_splitting_preserve_unqueried_ages\, \sk_rest_preserves_unheld_ahead_timestamps_and_respects_epoch_end\, \unregister_retires_shadow_via_host_retire_instead_of_dropping_synchronously\, \drop_forgets_lazy_compare_state\, \ orget_removes_shadow_entry_without_disturbing_peers\) - \cargo test -p victory-hle --lib -j 4\: 241 passed (+ 1 subprocess test), 0 failed, 3 ignored (includes \ on_lazy_remap_and_alias_materialize_overlapping_lazy_views\) - \cargo test -p xtask -j 4\: 8 policy tests passed
Fix findings #3, #4, and #5 from #282:

- (#3) watch.rs: replace the single global Journal::ahead_asked with per-interval (first, last, asked_at) entries and add Journal::ahead_epoch so ask_rest/ask_rest_all never advance timestamps over unheld pre-existing intervals and cannot resurrect a cleared journal after ask_once_end (while still preserving reset GetWriteWatch dirty bits). Update wrote() and title_memory_decommitted() to advance only overlapping ahead slices.
- (#4) shadow.rs: release BUFFERS before retiring and pass the removed Shadow to crate::host::retire(shadow) after shadow.mark_retired() in shadow::unregister so GPU buffers and hash slices are never dropped or reused while still in flight.
- (#5) host/lazy.rs + shadow.rs + xmem.rs: add lazy::forget(self.id) invoked in Drop for Shadow to bound STATES map growth, and check LAZY overlaps in Physical::shows_slices so non-lazy XMemMapPhysicalPages/alias_as never skip materializing lazy views.
- Add unit tests in watch.rs, host/lazy.rs, shadow.rs, and xmem.rs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 16:00:51 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 17:05 UTC · original

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Logic, concurrency, and test coverage look solid across all three fixes for #282:

  1. watch::ask_rest per-interval timestamps & epoch guard (crates/victory-gpu/src/watch.rs):

    • Replacing the single Journal::ahead_asked with per-interval (first, last, asked_at) entries in Journal::ahead plus a monotonic ahead_epoch cleanly closes both races: record_rest_pages preserves timestamps on unheld intervals via insert_ahead_interval, unconditionally notes any GetWriteWatch-reset pages into j.written before checking ahead_epoch/require_kept, and aborts j.ahead/j.kept updates if ask_once_end or another epoch transition occurred concurrently.
    • ahead_asked_at returns the conservative minimum asked_at across contiguous covering intervals; wrote and title_memory_decommitted advance timestamps only on overlapping sub-ranges via advance_ahead_range.
    • ask_ahead now avoids clobbering j.ahead if j.kept became true, while still noting written pages.
  2. shadow::unregister GPU fence retirement (crates/victory-gpu/src/shadow.rs, crates/victory-gpu/src/host.rs):

    • Removing the entry and releasing the BUFFERS lock before calling shadow.mark_retired() and crate::host::retire(shadow) ensures Shadow::drop (and HASH_POOL recycling of card.before) waits for in-flight GPU submissions + bury_lag() rather than dropping synchronously.
  3. Bounded STATES map & xmem::shows_slices lazy check (crates/victory-gpu/src/host/lazy.rs, crates/victory-gpu/src/shadow.rs, crates/victory-hle/src/modules/xmem.rs):

    • Drop for Shadow invokes crate::host::lazy::forget(self.id) before the self.place.is_some() early return, preventing unbounded growth in STATES without lock-order issues (STATES holds no Shadow references).
    • Physical::shows_slices checks has_lazy_overlap(base, len) using the maybe_lazy fast path and LAZY.read() (respecting the documented PHYSICAL → LAZY lock order), preventing non-lazy map_pages/alias_as calls from short-circuiting over MEM_RESERVE lazy views.

CI is passing and the added unit tests exercise the interval splitting, epoch abort, deferred host::retire, lazy::forget, and non-lazy remap/alias materialization paths. Because this touches the D3D12 host shadow retirement, write-watch submission sync, and physical-memory view materialization hot paths, a local real-GPU smoke test is recommended before merging.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-12-02 17:05 UTC · [original](https://github.com/Androtim/MiniVI/pull/359#issuecomment-7352877735) <!-- minivi-triage v1 head=38d58eb967f1b9ff811f92df7aaba0f5b13a67de verdict=needs-gpu-test ci=passing at=2026-12-02T17:05:39Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic, concurrency, and test coverage look solid across all three fixes for #282: 1. **`watch::ask_rest` per-interval timestamps & epoch guard** (`crates/victory-gpu/src/watch.rs`): - Replacing the single `Journal::ahead_asked` with per-interval `(first, last, asked_at)` entries in `Journal::ahead` plus a monotonic `ahead_epoch` cleanly closes both races: `record_rest_pages` preserves timestamps on unheld intervals via `insert_ahead_interval`, unconditionally notes any `GetWriteWatch`-reset pages into `j.written` before checking `ahead_epoch`/`require_kept`, and aborts `j.ahead`/`j.kept` updates if `ask_once_end` or another epoch transition occurred concurrently. - `ahead_asked_at` returns the conservative minimum `asked_at` across contiguous covering intervals; `wrote` and `title_memory_decommitted` advance timestamps only on overlapping sub-ranges via `advance_ahead_range`. - `ask_ahead` now avoids clobbering `j.ahead` if `j.kept` became true, while still noting `written` pages. 2. **`shadow::unregister` GPU fence retirement** (`crates/victory-gpu/src/shadow.rs`, `crates/victory-gpu/src/host.rs`): - Removing the entry and releasing the `BUFFERS` lock before calling `shadow.mark_retired()` and `crate::host::retire(shadow)` ensures `Shadow::drop` (and `HASH_POOL` recycling of `card.before`) waits for in-flight GPU submissions + `bury_lag()` rather than dropping synchronously. 3. **Bounded `STATES` map & `xmem::shows_slices` lazy check** (`crates/victory-gpu/src/host/lazy.rs`, `crates/victory-gpu/src/shadow.rs`, `crates/victory-hle/src/modules/xmem.rs`): - `Drop for Shadow` invokes `crate::host::lazy::forget(self.id)` before the `self.place.is_some()` early return, preventing unbounded growth in `STATES` without lock-order issues (`STATES` holds no `Shadow` references). - `Physical::shows_slices` checks `has_lazy_overlap(base, len)` using the `maybe_lazy` fast path and `LAZY.read()` (respecting the documented `PHYSICAL` → `LAZY` lock order), preventing non-lazy `map_pages`/`alias_as` calls from short-circuiting over `MEM_RESERVE` lazy views. CI is passing and the added unit tests exercise the interval splitting, epoch abort, deferred `host::retire`, `lazy::forget`, and non-lazy remap/alias materialization paths. Because this touches the D3D12 host shadow retirement, write-watch submission sync, and physical-memory view materialization hot paths, a local real-GPU smoke test is recommended before merging. --- _Generated with Antigravity CLI (`agy`)._
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-hle/src/modules/xmem.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/359/head:github-bot/gh-359'
git switch 'github-bot/gh-359'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-359'
git switch 'github-bot/gh-359'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-359'
git switch 'github-bot/gh-359'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-359'
git switch 'main'
git merge --squash 'github-bot/gh-359'
git switch 'main'
git merge --ff-only 'github-bot/gh-359'
git switch 'main'
git merge 'github-bot/gh-359'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/Androtim--MiniVI!359
No description provided.