gpu(land): batch each copy's landing pieces and open guard runs #195

Closed
Androtim wants to merge 0 commits from upstream-pr/195 into main
Androtim commented 2026-11-30 03:48:51 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-30T03:48:51Z.


Summary

  • Groups each copy's landing pieces into a single Shadow::land_card batch (land::jobs over (copy, title_address, bytes), keeping big copies distributed up to threads()).
  • Splits land::piece into piece_scan (identifying differing pages / guard range) and piece_put (merging into title memory / held snapshot), and adds land::runs + land::open_guard so contiguous guard ranges are coalesced and opened once per run instead of per piece (with VICTORY_LAND_BATCH=0 opt-out for A/B comparison).
  • Replaces linear per-piece skip filtering in Shadow::land_card with outside_sorted_into over joined skip ranges, and replaces the HashSet seen lookup in Host::relay_card_back with sorted Vec binary search / insertion.
  • Adds unit tests for land::runs and batched land::jobs partitioning.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy: 311 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib land:: -- --test-threads=1: 10 passed; 0 failed; 1 ignored
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib shadow:: -- --test-threads=1: 43 passed; 0 failed; 2 ignored
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib host:: -- --test-threads=1: 146 passed; 0 failed; 17 ignored
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings: pass
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings: pass
  • Live GPU 75s Series S (-PlayParity): all 6 gates PASS (12.6 fps, copyback 12.5 ms, used_max=6437/6869 MB, over=0 MB, final_waiting=1644, mapped_rate=8.21 ms/s, lit=17/24, magenta=0.0%, 0 crashes, guard open/note 1.24–1.57 ms/frame, late frames crisp)
  • Live GPU 75s Series X 1440p (-PlayParity): 10.9 fps, used_max=6615/6872 MB, over=0 MB, room_false=88.9%, lit=18/24, magenta=0.0%, 0 crashes, guard open/note 1.89–2.04 ms/frame, late frames crisp
<!-- greyfinch-sync:Androtim/MiniVI:issue:5558625499 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/195). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-30T03:48:51Z. --- ### Summary - Groups each copy's landing pieces into a single `Shadow::land_card` batch (`land::jobs` over `(copy, title_address, bytes)`, keeping big copies distributed up to `threads()`). - Splits `land::piece` into `piece_scan` (identifying differing pages / guard range) and `piece_put` (merging into title memory / held snapshot), and adds `land::runs` + `land::open_guard` so contiguous guard ranges are coalesced and opened once per run instead of per piece (with `VICTORY_LAND_BATCH=0` opt-out for A/B comparison). - Replaces linear per-piece skip filtering in `Shadow::land_card` with `outside_sorted_into` over joined skip ranges, and replaces the `HashSet` seen lookup in `Host::relay_card_back` with sorted `Vec` binary search / insertion. - Adds unit tests for `land::runs` and batched `land::jobs` partitioning. ### Verification - `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy`: `311 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib land:: -- --test-threads=1`: `10 passed; 0 failed; 1 ignored` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib shadow:: -- --test-threads=1`: `43 passed; 0 failed; 2 ignored` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib host:: -- --test-threads=1`: `146 passed; 0 failed; 17 ignored` - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings`: pass - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings`: pass - Live GPU 75s Series S (`-PlayParity`): all 6 gates PASS (`12.6 fps`, `copyback 12.5 ms`, `used_max=6437/6869 MB`, `over=0 MB`, `final_waiting=1644`, `mapped_rate=8.21 ms/s`, `lit=17/24`, `magenta=0.0%`, `0` crashes, guard open/note `1.24–1.57 ms/frame`, late frames crisp) - Live GPU 75s Series X 1440p (`-PlayParity`): `10.9 fps`, `used_max=6615/6872 MB`, `over=0 MB`, `room_false=88.9%`, `lit=18/24`, `magenta=0.0%`, `0` crashes, guard open/note `1.89–2.04 ms/frame`, late frames crisp
Androtim commented 2026-11-30 05:03:43 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-30T05:03:43Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-work · CI (check): passing

Review Summary

Good direction on reducing per-piece lock and guard-open overhead in Shadow::land_card (piece_scan / piece_put / land::runs / outside_sorted_into look clean), but grouping jobs by (copy, block) breaks the 64 KiB block exclusivity invariant in land.rs when two copies overlap the same 64 KiB title memory block.

Findings

  1. Data race & ordering bug when two Shadow copies share a 64 KiB title block (crates/victory-gpu/src/host.rs, crates/victory-gpu/src/land.rs)

    • crates/victory-gpu/src/land.rs:19-21 documents the concurrency invariant: pieces in the same 64 KiB block of title memory must stay in one job in the order given, because two copies may hold the same title memory (see also land::ordered checking alone per 64 KiB block).
    • Both Host::relay_card_back (re-sorting pieces by (shadow.id(), block) after land::ordered) and RelayBack::merge (sorting by (copy_idx, block)) now separate pieces from different copies that touch the same 64 KiB block, and land::jobs puts each copy into separate jobs run concurrently by land::each.
    • When two copies overlap the same 64 KiB block in one landing:
      • Two worker threads can concurrently write the same title memory bytes via safecopy::merge in non-deterministic order, violating flight order and introducing a data race.
      • land::Notes::flush (VICTORY_LAND_TAKEN) checks through.all(|other| other == copy) assuming all writes to a block in the landing are recorded in the same job's Notes. Splitting two copies that touch the same block across different jobs causes each job to believe it was the sole writer to block and potentially call copy.landed(block, before, now) concurrently with the other copy's write.
    • Note that batch_tests::jobs_keep_copies_apart_and_fill_the_threads explicitly exercises overlapping blocks (0..16) for copy 7 and copy 9 being placed in separate jobs.
  2. VICTORY_LAND_BATCH=0 opt-out still re-sorts by copy (crates/victory-gpu/src/host.rs)

    • In both Host::relay_card_back and RelayBack::merge, order.sort_by_key(...) unconditionally sorts by (copy, block) even when !land::batch_on(), so VICTORY_LAND_BATCH=0 does not restore the previous block-grouped job layout for overlapping copies.
  3. Minor nit (crates/victory-gpu/src/host.rs)

    • In Host::relay_card_back, seen.binary_search(&(copy, lo, hi)) already returns Err(pos) with the sorted insertion index, so the subsequent seen.partition_point(...) lookup is redundant.

To change the verdict:

  • Preserve the 64 KiB block serialization invariant across copies: ensure any 64 KiB title block touched by more than one copy in a landing stays in a single job in original order (e.g., keep shared-block pieces in block-ordered job(s) and only batch/split exclusive-block pieces per copy, or group copies that share any 64 KiB block into the same job).
  • Guard the (copy, block) re-sorting in Host::relay_card_back and RelayBack::merge behind land::batch_on() so VICTORY_LAND_BATCH=0 is a clean A/B fallback.
  • Add a unit test verifying that two copies overlapping the same 64 KiB block are not split across concurrent jobs.

Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7269320928 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/195#issuecomment-7269320928). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-30T05:03:43Z. --- <!-- minivi-triage v1 head=d69c0ae341a60af4027f0c4a53e539738d00e619 verdict=needs-work ci=passing at=2026-11-30T05:04:16Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-work` · **CI (`check`):** `passing` ### Review Summary Good direction on reducing per-piece lock and guard-open overhead in `Shadow::land_card` (`piece_scan` / `piece_put` / `land::runs` / `outside_sorted_into` look clean), but grouping jobs by `(copy, block)` breaks the 64 KiB block exclusivity invariant in `land.rs` when two copies overlap the same 64 KiB title memory block. ### Findings 1. **Data race & ordering bug when two `Shadow` copies share a 64 KiB title block (`crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/land.rs`)** - `crates/victory-gpu/src/land.rs:19-21` documents the concurrency invariant: pieces in the same 64 KiB block of title memory must stay in one job in the order given, because two copies may hold the same title memory (see also `land::ordered` checking `alone` per 64 KiB block). - Both `Host::relay_card_back` (re-sorting `pieces` by `(shadow.id(), block)` after `land::ordered`) and `RelayBack::merge` (sorting by `(copy_idx, block)`) now separate pieces from different copies that touch the same 64 KiB block, and `land::jobs` puts each copy into separate jobs run concurrently by `land::each`. - When two copies overlap the same 64 KiB block in one landing: - Two worker threads can concurrently write the same title memory bytes via `safecopy::merge` in non-deterministic order, violating flight order and introducing a data race. - `land::Notes::flush` (`VICTORY_LAND_TAKEN`) checks `through.all(|other| other == copy)` assuming all writes to a `block` in the landing are recorded in the same job's `Notes`. Splitting two copies that touch the same block across different jobs causes each job to believe it was the sole writer to `block` and potentially call `copy.landed(block, before, now)` concurrently with the other copy's write. - Note that `batch_tests::jobs_keep_copies_apart_and_fill_the_threads` explicitly exercises overlapping blocks `(0..16)` for copy `7` and copy `9` being placed in separate jobs. 2. **`VICTORY_LAND_BATCH=0` opt-out still re-sorts by copy (`crates/victory-gpu/src/host.rs`)** - In both `Host::relay_card_back` and `RelayBack::merge`, `order.sort_by_key(...)` unconditionally sorts by `(copy, block)` even when `!land::batch_on()`, so `VICTORY_LAND_BATCH=0` does not restore the previous block-grouped job layout for overlapping copies. 3. **Minor nit (`crates/victory-gpu/src/host.rs`)** - In `Host::relay_card_back`, `seen.binary_search(&(copy, lo, hi))` already returns `Err(pos)` with the sorted insertion index, so the subsequent `seen.partition_point(...)` lookup is redundant. ### To change the verdict: - Preserve the 64 KiB block serialization invariant across copies: ensure any 64 KiB title block touched by more than one copy in a landing stays in a single job in original order (e.g., keep shared-block pieces in block-ordered job(s) and only batch/split exclusive-block pieces per copy, or group copies that share any 64 KiB block into the same job). - Guard the `(copy, block)` re-sorting in `Host::relay_card_back` and `RelayBack::merge` behind `land::batch_on()` so `VICTORY_LAND_BATCH=0` is a clean A/B fallback. - Add a unit test verifying that two copies overlapping the same 64 KiB block are not split across concurrent jobs. --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-12-01 01:39:06 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-01T01:39:06Z.


Closing stale/conflicted backlog PR per #276. Superseded by the active root-architecture replacement pillars with isolated plain --release A/B verification.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7297740498 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/195#issuecomment-7297740498). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-01T01:39:06Z. --- Closing stale/conflicted backlog PR per #276. Superseded by the active root-architecture replacement pillars with isolated plain --release A/B verification.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Androtim/MiniVI!195
No description provided.