fix(gpu): let the device-loss report see long live allocations #435

Manually merged
github merged 1 commit from github-bot/gh-435 into main 2026-12-05 17:31:11 +00:00 AGit
Owner

@⁠Luxuride on GitHub · 2026-12-04 02:46 UTC · original
Luxuride:fix/gpu-book-holders → main · +36 −4 · 1 files · 1 commits · merged 2026-12-05 17:27 UTC

What is wrong

Book keeps two maps for one question: by_start for entries that fit in a window, and long for the entries longer than LONG (64 MiB) that cannot be found by scanning a window at all (crates/victory-gpu/src/book.rs:32-37).

/// Longer than anything of ours: how far below an address its owner starts.
const LONGEST: u64 = 2 << 30;
/// Entries longer than this are few and looked through one by one.
const LONG: u64 = 64 << 20;

alive consults both (book.rs:136-148), ending in || self.long.iter().any(holds). holders, its sibling with the same documented meaning — "the live entries that hold at" — scans only the 2 GiB window below at (book.rs:151-161):

        let from = at.saturating_sub(LONGEST);
        self.by_start
            .range((from, 0)..=(at, u64::MAX))

A live allocation longer than 64 MiB whose start is more than 2 GiB below the fault address is therefore invisible to it, while alive still says it is there. The two constants contradict each other: if LONGEST really were "longer than anything of ours", alive's long fallback would be dead code.

Concrete failure

holders has one caller, the device-loss report (book.rs:715-718), which prints every holder under ; BOOK: alive there: and every released entry under ; gone there. When the DRED fault address (fault.PageFaultVA, crates/victory-gpu/src/host.rs:4857) falls inside a large live allocation more than 2 GiB from its start, the report lists it under neither heading — it says the book never had that address, which is the one conclusion that is certainly false, in the one report someone reads after a device loss.

This is the shape the bug hides in: an allocation has to be >64 MiB and the fault >2 GiB past its start. Just under 2 GiB works today, which is why no capture shows it.

The change

One predicate, both sources, same order (last start first), same 8-entry cap:

        let holds = |e: &&Entry| at >= e.start && at - e.start < e.size;
        …
        for id in &self.long {
            if let Some(e) = self.live.get(id).filter(holds)
                && !out.iter().any(|o| o.start == e.start && o.size == e.size)
            {
                out.push(e);
            }
        }
        out.sort_by_key(|e| std::cmp::Reverse(e.start));
        out.truncate(8);

The identity check keeps an entry that is both in the window and in long from being printed twice. Nothing changes while every live entry is ≤ 64 MiB: long is empty then.

Plus a regression test that books a 3 GiB entry at 0x7f00_0000_0000, asserts the fault at +2 GiB + 4 KiB has exactly one holder that alive agrees is alive, and that the address one byte past the end has none (the at - start < size boundary is what the old filter got right).

Validation

  • cargo check -p victory-gpu --tests --target x86_64-pc-windows-msvc — Finished.
  • The module is Windows-only (windows crate, DRED), so the test cannot execute on this Linux host; the behaviour was proved with a standalone harness that copies Entry/add/remove/alive/holders/gone_at verbatim from this file and books the same 3 GiB entry: old holders = 0, patched = 1, fate = Alive, and the just-under-2-GiB and past-the-end cases stay correct.

Overlap

crates/victory-gpu/src/book.rs appears in none of the 100 open PRs (checked by gh pr list --json files plus a per-PR diff grep for book.rs, holders, LONGEST), and no issue mentions LONGEST or the device-loss report.

book is behind the diagnostics feature: cargo test -p victory-gpu --lib does not compile it, so the tests here run with cargo test -p victory-gpu --tests --features diagnostics.

**@⁠Luxuride** on GitHub · 2026-12-04 02:46 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/435) `Luxuride:fix/gpu-book-holders` → `main` · +36 −4 · 1 files · 1 commits · merged 2026-12-05 17:27 UTC ### What is wrong `Book` keeps two maps for one question: `by_start` for entries that fit in a window, and `long` for the entries longer than `LONG` (64 MiB) that cannot be found by scanning a window at all (`crates/victory-gpu/src/book.rs:32-37`). ```rust /// Longer than anything of ours: how far below an address its owner starts. const LONGEST: u64 = 2 << 30; /// Entries longer than this are few and looked through one by one. const LONG: u64 = 64 << 20; ``` `alive` consults both (`book.rs:136-148`), ending in `|| self.long.iter().any(holds)`. `holders`, its sibling with the same documented meaning — "the live entries that hold `at`" — scans only the 2 GiB window below `at` (`book.rs:151-161`): ```rust let from = at.saturating_sub(LONGEST); self.by_start .range((from, 0)..=(at, u64::MAX)) ``` A live allocation longer than 64 MiB whose start is more than 2 GiB below the fault address is therefore invisible to it, while `alive` still says it is there. The two constants contradict each other: if `LONGEST` really were "longer than anything of ours", `alive`'s `long` fallback would be dead code. ### Concrete failure `holders` has one caller, the device-loss report (`book.rs:715-718`), which prints every holder under `; BOOK: alive there:` and every released entry under `; gone there`. When the DRED fault address (`fault.PageFaultVA`, `crates/victory-gpu/src/host.rs:4857`) falls inside a large live allocation more than 2 GiB from its start, the report lists it under neither heading — it says the book never had that address, which is the one conclusion that is certainly false, in the one report someone reads after a device loss. This is the shape the bug hides in: an allocation has to be >64 MiB **and** the fault >2 GiB past its start. Just under 2 GiB works today, which is why no capture shows it. ### The change One predicate, both sources, same order (last start first), same 8-entry cap: ```rust let holds = |e: &&Entry| at >= e.start && at - e.start < e.size; … for id in &self.long { if let Some(e) = self.live.get(id).filter(holds) && !out.iter().any(|o| o.start == e.start && o.size == e.size) { out.push(e); } } out.sort_by_key(|e| std::cmp::Reverse(e.start)); out.truncate(8); ``` The identity check keeps an entry that is both in the window and in `long` from being printed twice. Nothing changes while every live entry is ≤ 64 MiB: `long` is empty then. Plus a regression test that books a 3 GiB entry at `0x7f00_0000_0000`, asserts the fault at `+2 GiB + 4 KiB` has exactly one holder that `alive` agrees is alive, and that the address one byte past the end has none (the `at - start < size` boundary is what the old `filter` got right). ### Validation - `cargo check -p victory-gpu --tests --target x86_64-pc-windows-msvc` — `Finished`. - The module is Windows-only (`windows` crate, DRED), so the test cannot execute on this Linux host; the behaviour was proved with a standalone harness that copies `Entry`/`add`/`remove`/`alive`/`holders`/`gone_at` verbatim from this file and books the same 3 GiB entry: old `holders` = 0, patched = 1, `fate = Alive`, and the just-under-2-GiB and past-the-end cases stay correct. ### Overlap `crates/victory-gpu/src/book.rs` appears in none of the 100 open PRs (checked by `gh pr list --json files` plus a per-PR diff grep for `book.rs`, `holders`, `LONGEST`), and no issue mentions `LONGEST` or the device-loss report. `book` is behind the `diagnostics` feature: `cargo test -p victory-gpu --lib` does not compile it, so the tests here run with `cargo test -p victory-gpu --tests --features diagnostics`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 02:49:11 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 03:14 UTC · original

Tested this natively on Windows 11 (MSVC) with one NVIDIA desktop card.

The bug is real on main. I dropped your 3 GiB case into the base tree as a throwaway test and holders returns nothing for the fault 2 GiB + 4 KiB in, while alive says true. With the PR the new test and the existing book tests pass.

Heads up that book is behind the diagnostics feature, so cargo check -p victory-gpu --tests without it does not compile book.rs at all, and a plain cargo test -p victory-gpu --lib skips these tests. I ran them with --features diagnostics. The full gpu lib suite fails the same tests on this branch as on main here, and clippy has no new warnings.

Small nit on the dedup. It matches on start and size, so two live long entries with the same start and size (say a heap and a resource placed over all of it) collapse into one when the fault is more than 2 GiB past their start. I checked it with two 3 GiB entries at the same address and got 1 holder far out, 2 near the start. Comparing with std::ptr::eq, or skipping long entries whose start is already inside the window (e.start >= from), keeps both.

Also holders has a second caller in the slot reach loop of the same report (it sizes a texture from its holders), so that one gets the fix too.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 03:14 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/435#issuecomment-7399845082) Tested this natively on Windows 11 (MSVC) with one NVIDIA desktop card. The bug is real on main. I dropped your 3 GiB case into the base tree as a throwaway test and `holders` returns nothing for the fault 2 GiB + 4 KiB in, while `alive` says true. With the PR the new test and the existing book tests pass. Heads up that `book` is behind the `diagnostics` feature, so `cargo check -p victory-gpu --tests` without it does not compile book.rs at all, and a plain `cargo test -p victory-gpu --lib` skips these tests. I ran them with `--features diagnostics`. The full gpu lib suite fails the same tests on this branch as on main here, and clippy has no new warnings. Small nit on the dedup. It matches on start and size, so two live long entries with the same start and size (say a heap and a resource placed over all of it) collapse into one when the fault is more than 2 GiB past their start. I checked it with two 3 GiB entries at the same address and got 1 holder far out, 2 near the start. Comparing with `std::ptr::eq`, or skipping long entries whose start is already inside the window (`e.start >= from`), keeps both. Also `holders` has a second caller in the slot reach loop of the same report (it sizes a texture from its holders), so that one gets the fix too. AI-assisted: yes
github-bot force-pushed github-bot/gh-435 from a2a8a867c7 to 401e2d5821 2026-12-04 10:26:26 +00:00 Compare
github-bot force-pushed github-bot/gh-435 from 401e2d5821 to 23b39b827b 2026-12-04 11:13:32 +00:00 Compare
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 11:12 UTC · original

Fixed: the dedup is by identity now (std::ptr::eq(*o, e)), not by start and size, so two live entries over the same range stay two holders. The dedup itself is needed because a long entry of at most LONGEST is in by_start as well as in long; only the ones past it are reachable solely through long, which is the whole reason alive looks at both.

Thanks as well for the --features diagnostics note — book.rs is behind that feature, so cargo test -p victory-gpu --lib silently skips these tests, and I have made the PR description say which invocation actually runs them.

**@⁠Luxuride** on GitHub · 2026-12-04 11:12 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/435#issuecomment-7409771477) Fixed: the dedup is by identity now (`std::ptr::eq(*o, e)`), not by start and size, so two live entries over the same range stay two holders. The dedup itself is needed because a long entry of at most `LONGEST` is in `by_start` as well as in `long`; only the ones past it are reachable solely through `long`, which is the whole reason `alive` looks at both. Thanks as well for the `--features diagnostics` note — `book.rs` is behind that feature, so `cargo test -p victory-gpu --lib` silently skips these tests, and I have made the PR description say which invocation actually runs them.
github-bot force-pushed github-bot/gh-435 from 23b39b827b to 0c0aea1e1d 2026-12-04 11:19:21 +00:00 Compare
github manually merged commit ce5ceafc33 into main 2026-12-05 17:31:10 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.