Skip to content

GPU: pipeline library saves run one at a time - #2328

Open
denkencar-sketch wants to merge 2 commits into
Marvisak:mainfrom
denkencar-sketch:fix/plib-001
Open

denkencar-sketch wants to merge 2 commits into
Marvisak:mainfrom
denkencar-sketch:fix/plib-001

Conversation

@denkencar-sketch

@denkencar-sketch denkencar-sketch commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The worker's pipeline library save and the shutdown's could interleave their files: an older blob over a newer one, or beside another save's prebuilt list. Saves now run one at a time. A second commit makes the periodic save, which workers call after every pipeline, leave it to the save running instead of waiting (shutdown's save still waits).

Testing

Tests a_save_waits_for_the_save_running and a_periodic_save_does_not_wait_for_the_save_running fail without the lock and without try_lock respectively, and pass with this change. The wait in the first test is timing-based.

cargo test --workspace --locked passes apart from known flakes: modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too, and so does a parallel-run flake in victory-gpu's lib tests (watch:: and descriptor::host:: tests, 2 of 40 runs on pristine main).

A skipped periodic save leaves its dirty marks for the next save. It touches save() like #2326 and #2327 do and conflicts with them only in adjacent test blocks in library.rs. Not tried: a run in the game.

AI-assisted.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pipeline library saves run one at a time (SAVING mutex, try_lock for periodic, blocking for shutdown). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same cluster; prevents blob/prebuilt interleaving.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090:

  • Serializing pipeline library saves while letting periodic saves skip when a save is already running avoids concurrent write races cleanly.
  • cargo test -p victory-gpu pipeline::library::tests: 10/10 passed (including a_periodic_save_does_not_wait_for_the_save_running and a_save_waits_for_the_save_running).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: merge candidate. Thanks for the rebase. At a662de9, pipeline::library::save (crates/victory-gpu/src/pipeline/library.rs) holds a SAVING mutex from the LAST check to the last file write. Shutdown's save(true) waits for it, and a worker's save(false) returns at once when another save is running.

The race is real on main. Serialize runs under the library state lock, but the three write_atomically calls run after that lock is released. Two saves can therefore finish their files in the wrong order, leaving an older blob or a prebuilt list beside the wrong bytes. A skipped periodic save leaves added/USED_CHANGED set, so the next save picks the changes up. The two tests check the waiting and non-waiting cases. The first relies on a 300 ms sleep, which is acceptable for a negative check.

CI: passing (check). Merges cleanly.


Generated by Claude Code

Ingenioeren added a commit to Ingenioeren/VIctory that referenced this pull request Nov 25, 2026
Since Marvisak#1660 each cache write stages in `<file>.tmp-<pid>-<n>`, and a write
cut by an exit (TerminateProcess) leaves that file for good: no later run
reuses the name and nothing removed it.

`use_pipeline_cache()` sweeps the staging files of the three cache files:
this process's at once, other processes' after 10 minutes untouched (the
folder is shared and nothing stops a second instance). Only regular files
named exactly `<cache file>.tmp-<digits>-<digits>` go.

The other half of Marvisak#2496 (an exit save that waits for a running one) is
left to Marvisak#2328.

Fixes Marvisak#2496

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ingenioeren added a commit to Ingenioeren/VIctory that referenced this pull request Nov 25, 2026
Since Marvisak#1660 each cache write stages in `<file>.tmp-<pid>-<n>`, and a write
cut by an exit (TerminateProcess) leaves that file for good: no later run
reuses the name and nothing removed it.

`use_pipeline_cache()` sweeps the staging files of the three cache files:
this process's at once, other processes' after 10 minutes untouched (the
folder is shared and nothing stops a second instance). Only regular files
named exactly `<cache file>.tmp-<digits>-<digits>` go.

Part of Marvisak#2496: its other half (an exit save that waits for a running
one) is Marvisak#2328.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The worker's save and the shutdown's could interleave their files: an older
blob over a newer, or beside another's prebuilt list.
The workers call it after every pipeline; waiting for the files of another
save would stall them. Shutdown's save still waits.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed a662de92591345f983324ffef25365d7b5bf8a46 (merged cleanly onto 63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1).

The SAVING guard covers the full save sequence (early list, prebuilt list, and library blob) with consistent lock ordering (SAVING -> LAST -> state -> USED -> WRITING), keeping periodic saves non-blocking on contention while shutdown waits for an active save to finish.

Non-blocking notes for coordination / follow-up:

  • #2803 already extends LAST with the same blocking/try_lock policy over the save window (so if both land, keeping a single outer lock avoids stacking two save mutexes), and #2327 handles dirty-state restoration if a file replacement fails after clearing marks.
  • Replacing the 300 ms sleep in a_save_waits_for_the_save_running with an explicit synchronization point (keeping a timeout only as a watchdog) would make the concurrency tests immune to scheduler jitter.

Verification

  • cargo run -p xtask -- policy (191 files ok), cargo clippy (default & --all-features) clean, new lines rustfmt-clean.
  • victory-gpu pipeline::library:: with VICTORY_D3D12_DEBUG=1: 13/13 passed on both RTX 5090 and WARP (at both PR head and merged onto 63bcca43).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants