fileback, shadow: clean up orphaned cpu-mirrors .tmp files on startup #4715

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

@⁠nidea1 on GitHub · 2026-12-01 03:10 UTC · original
nidea1:fix/cpu-mirrors-orphan-cleanup → main · +117 −1 · 2 files · 1 commits · open

What it changes

VICTORY_CARD_CPU_FILE=1 backs two-sided CPU mirrors with tempfile::tempfile_in (FILE_FLAG_DELETE_ON_CLOSE), which cleans up automatically on normal exit or process crash, but leaves orphaned .tmp* files behind in cache/cpu-mirrors after a Windows BSOD or hard power loss. Over repeated unclean shutdowns this can accumulate thousands of stale files (gigabytes of disk space).

  • Adds best-effort startup cleanup fileback::cleanup_orphans(folder: &Path) -> (usize, u64) in crates/victory-gpu/src/fileback.rs, invoked once from shadow::cpu_mirror_files (crates/victory-gpu/src/shadow.rs) when the mirror directory is configured.
  • Removes only unlocked regular non-symlink files matching tempfile's .tmp prefix (len > 4); live mirrors held open by another running instance (tempfile::tempfile_in opens with share_mode(0) so removal fails cleanly), directories, symlinks, and unrelated files are left untouched.
  • Logs the removed file count and reclaimed MiB without logging local filesystem paths.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB / 32 GB RAM, Series S profile, DLSS Quality, FSR 3 frame generation (--fg-type fsr --framegen 3), ray tracing off, VICTORY_SAMPLED_EVICT=1, VICTORY_WINDOW_GROW=1.
  • Before: Unclean system shutdowns left orphaned .tmp* files permanently in cache/cpu-mirrors (3,700 stale files / 995.5 MB present on disk before first launch with this fix).
  • After:
    • First live startup logged removed orphaned file-backed CPU mirror temp files on startup removed=3700 mb=995, freeing 3,700 orphaned .tmp* files (995.5 MB) cleanly; cache/cpu-mirrors stayed at 0 orphaned files across subsequent launches and a full 12-minute (720.7 s in-world) live soak (0 crashes, 0 Victory errors).
    • Unit tests verify orphaned .tmp* cleanup, preservation of non-.tmp files and subdirectories, clean skipping of in-use MappedStorage handles, and graceful handling of missing directories.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes)
  • cargo test passed for the crates it touches: yes (on 7c7d567c, base 7d93ee0759)
    • cargo test -j 2 -p victory-gpu --locked --lib fileback::tests: 5 passed, 0 failed (new: cleanup_orphans_removes_unlocked_tmp_files_and_preserves_other_entries, cleanup_orphans_skips_in_use_mapped_storage_without_error, cleanup_orphans_ignores_missing_folder)
    • cargo test -j 2 -p victory-gpu --locked --lib shadow::: 84 passed, 0 failed, 6 ignored
    • cargo clippy -j 2 -p victory-gpu --all-targets --locked -- -D warnings and --all-features: 0 warnings on 7d93ee0759 (note: current main 5fabb46e has 5 pre-existing clippy errors in font.rs/menu.rs/panel.rs from #4634, tracked in #4679 / #4707).
    • cargo xtask policy: 464 files ok (--staged: 2 files ok).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none found
    • Searched open PRs for fileback.rs, cpu-mirrors, VICTORY_CARD_CPU_FILE, and shadow::cpu_mirror_files; no open PR touches fileback.rs or cleans up orphaned cpu-mirrors temp files.
**@⁠nidea1** on GitHub · 2026-12-01 03:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4714) `nidea1:fix/cpu-mirrors-orphan-cleanup` → `main` · +117 −1 · 2 files · 1 commits · open ## What it changes `VICTORY_CARD_CPU_FILE=1` backs two-sided CPU mirrors with `tempfile::tempfile_in` (`FILE_FLAG_DELETE_ON_CLOSE`), which cleans up automatically on normal exit or process crash, but leaves orphaned `.tmp*` files behind in `cache/cpu-mirrors` after a Windows BSOD or hard power loss. Over repeated unclean shutdowns this can accumulate thousands of stale files (gigabytes of disk space). - Adds best-effort startup cleanup `fileback::cleanup_orphans(folder: &Path) -> (usize, u64)` in `crates/victory-gpu/src/fileback.rs`, invoked once from `shadow::cpu_mirror_files` (`crates/victory-gpu/src/shadow.rs`) when the mirror directory is configured. - Removes only unlocked regular non-symlink files matching `tempfile`'s `.tmp` prefix (`len > 4`); live mirrors held open by another running instance (`tempfile::tempfile_in` opens with `share_mode(0)` so removal fails cleanly), directories, symlinks, and unrelated files are left untouched. - Logs the removed file count and reclaimed MiB without logging local filesystem paths. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB / 32 GB RAM, Series S profile, DLSS Quality, FSR 3 frame generation (`--fg-type fsr --framegen 3`), ray tracing off, `VICTORY_SAMPLED_EVICT=1`, `VICTORY_WINDOW_GROW=1`. - Before: Unclean system shutdowns left orphaned `.tmp*` files permanently in `cache/cpu-mirrors` (`3,700` stale files / `995.5 MB` present on disk before first launch with this fix). - After: - First live startup logged `removed orphaned file-backed CPU mirror temp files on startup removed=3700 mb=995`, freeing `3,700` orphaned `.tmp*` files (`995.5 MB`) cleanly; `cache/cpu-mirrors` stayed at `0` orphaned files across subsequent launches and a full 12-minute (`720.7 s` in-world) live soak (`0` crashes, `0` Victory errors). - Unit tests verify orphaned `.tmp*` cleanup, preservation of non-`.tmp` files and subdirectories, clean skipping of in-use `MappedStorage` handles, and graceful handling of missing directories. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes) - `cargo test` passed for the crates it touches: yes (on `7c7d567c`, base `7d93ee0759`) - `cargo test -j 2 -p victory-gpu --locked --lib fileback::tests`: 5 passed, 0 failed (new: `cleanup_orphans_removes_unlocked_tmp_files_and_preserves_other_entries`, `cleanup_orphans_skips_in_use_mapped_storage_without_error`, `cleanup_orphans_ignores_missing_folder`) - `cargo test -j 2 -p victory-gpu --locked --lib shadow::`: 84 passed, 0 failed, 6 ignored - `cargo clippy -j 2 -p victory-gpu --all-targets --locked -- -D warnings` and `--all-features`: 0 warnings on `7d93ee0759` (note: current `main` `5fabb46e` has 5 pre-existing clippy errors in `font.rs`/`menu.rs`/`panel.rs` from `#4634`, tracked in `#4679` / `#4707`). - `cargo xtask policy`: 464 files ok (`--staged`: 2 files ok). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none found - Searched open PRs for `fileback.rs`, `cpu-mirrors`, `VICTORY_CARD_CPU_FILE`, and `shadow::cpu_mirror_files`; no open PR touches `fileback.rs` or cleans up orphaned `cpu-mirrors` temp files.
VICTORY_CARD_CPU_FILE=1 backs two-sided CPU mirrors with
tempfile::tempfile_in (FILE_FLAG_DELETE_ON_CLOSE), which leaves orphaned
.tmp* files behind in cache/cpu-mirrors after a BSOD or hard power loss.

Add best-effort startup cleanup in fileback::cleanup_orphans called from
shadow::cpu_mirror_files once the mirror folder is configured. Only
unlocked regular files matching tempfile's .tmp prefix are removed;
live mirrors from concurrent instances (opened with share_mode(0)),
directories, symlinks, and unrelated files are left untouched.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 03:16:28 +00:00
Author
Owner

@⁠nidea1 on GitHub · 2026-12-01 12:33 UTC · original

Live post-crash startup verification on 7c7d567c (RTX 3060 Ti 8 GB (ReBAR off, driver 621.40), 32 GB RAM, Windows 11, Series S, DLSS Quality, FSR 3 FG, RT off, VICTORY_SAMPLED_EVICT=1, VICTORY_WINDOW_GROW=1, VICTORY_POOL_SMALL=0, VICTORY_RIPE_BLOCKS=12 — 5-minute (300 s in-world, 357 s total) live validation on a combined 15-PR release build over origin/main (5fabb46eaf).):

  • An earlier host BSOD had left 3,701 orphaned cpu-mirrors temp files (995.6 MB) on disk before launch.
  • On startup, #4714 immediately cleaned all of them in one pass:
    INFO victory_gpu::fileback: removed orphaned file-backed CPU mirror temp files on startup removed=3701 mb=995
  • Clean exit with 0 cpu-mirrors files (0 MB) remaining, 0 Victory errors, and 0 nvlddmkm events.

Caveat: verified in a combined 15-PR build (5-minute opening/cell session, not an isolated A/B).

**@⁠nidea1** on GitHub · 2026-12-01 12:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4714#issuecomment-7311318427) Live post-crash startup verification on `7c7d567c` (RTX 3060 Ti 8 GB (ReBAR off, driver `621.40`), 32 GB RAM, Windows 11, Series S, DLSS Quality, FSR 3 FG, RT off, `VICTORY_SAMPLED_EVICT=1`, `VICTORY_WINDOW_GROW=1`, `VICTORY_POOL_SMALL=0`, `VICTORY_RIPE_BLOCKS=12` — 5-minute (`300 s` in-world, `357 s` total) live validation on a combined 15-PR release build over `origin/main` (`5fabb46eaf`).): - An earlier host BSOD had left **`3,701` orphaned `cpu-mirrors` temp files (`995.6 MB`)** on disk before launch. - On startup, `#4714` immediately cleaned all of them in one pass: `INFO victory_gpu::fileback: removed orphaned file-backed CPU mirror temp files on startup removed=3701 mb=995` - Clean exit with `0` `cpu-mirrors` files (`0 MB`) remaining, `0` Victory errors, and `0` `nvlddmkm` events. *Caveat:* verified in a combined 15-PR build (5-minute opening/cell session, not an isolated A/B).
Author
Owner

@⁠cloph-dsp on GitHub · 2026-12-01 18:51 UTC · original

Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree.

Base 5fabb46eaf6ed8771321787f8871051abde69b9b (current main), head 7c7d567c0bebcfca538127d9f59fc5ab00d5bf88. The PR's own change is two files: crates/victory-gpu/src/fileback.rs 110/0 and crates/victory-gpu/src/shadow.rs 7/1.

One thing to know before the numbers: this branch sits on an older main, so a two-dot diff against today's main also shows menu.rs, panel.rs, font.rs and README.md going back to the pre-F1-menu state (that is the merge base difference, not part of the proposal). I therefore read and checked only the two files above; the merge itself keeps main's version of the menu files because the branch does not touch them.

All three tests are new on the base (git grep -F <name> 5fabb46e -- . exit 1 for each):
cleanup_orphans_removes_unlocked_tmp_files_and_preserves_other_entries, cleanup_orphans_skips_in_use_mapped_storage_without_error, cleanup_orphans_ignores_missing_folder.

git diff --check "5fabb46e..7c7d567c" -- crates/victory-gpu/src/fileback.rs crates/victory-gpu/src/shadow.rs → no output, exit 0.

$env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4714'
cargo test --locked -p victory-gpu --lib -- fileback::tests::cleanup_orphans_removes_unlocked_tmp_files_and_preserves_other_entries --exact --test-threads=1 --quiet
cargo test --locked -p victory-gpu --lib -- fileback::tests::cleanup_orphans_skips_in_use_mapped_storage_without_error --exact --test-threads=1 --quiet
cargo test --locked -p victory-gpu --lib -- fileback::tests::cleanup_orphans_ignores_missing_folder --exact --test-threads=1 --quiet

Result, each: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1201 filtered out.

What they cover, from the bodies: the first builds a temp tree with two .tmpXXXXXXXX orphans plus the near misses (.tmp bare, other.tmp, a subdir, and a .tmpDir directory holding a nested .tmpNested) and asserts cleanup_orphans returns (2, 4096 + 123) — both counts and bytes — then that only the two orphans are gone; the second keeps a MappedStorage open on a .tmp file and asserts cleanup neither errors nor removes it; the third calls it on a path that was never created and expects (0, 0).

The caveat: the first test probes the symlink arm opportunistically (symlink_file result captured as has_symlink), so on a machine without the privilege to create symlinks that part is skipped rather than passed.

Temp dirs only, no title files, no device; GPU/driver N/A. No game data.

**@⁠cloph-dsp** on GitHub · 2026-12-01 18:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4714#issuecomment-7321685061) Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree. Base `5fabb46eaf6ed8771321787f8871051abde69b9b` (current main), head `7c7d567c0bebcfca538127d9f59fc5ab00d5bf88`. The PR's own change is two files: `crates/victory-gpu/src/fileback.rs` 110/0 and `crates/victory-gpu/src/shadow.rs` 7/1. One thing to know before the numbers: this branch sits on an older main, so a two-dot diff against today's main also shows `menu.rs`, `panel.rs`, `font.rs` and `README.md` going back to the pre-F1-menu state (that is the merge base difference, not part of the proposal). I therefore read and checked only the two files above; the merge itself keeps main's version of the menu files because the branch does not touch them. All three tests are new on the base (`git grep -F <name> 5fabb46e -- .` exit 1 for each): `cleanup_orphans_removes_unlocked_tmp_files_and_preserves_other_entries`, `cleanup_orphans_skips_in_use_mapped_storage_without_error`, `cleanup_orphans_ignores_missing_folder`. `git diff --check "5fabb46e..7c7d567c" -- crates/victory-gpu/src/fileback.rs crates/victory-gpu/src/shadow.rs` → no output, exit 0. ``` $env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4714' cargo test --locked -p victory-gpu --lib -- fileback::tests::cleanup_orphans_removes_unlocked_tmp_files_and_preserves_other_entries --exact --test-threads=1 --quiet cargo test --locked -p victory-gpu --lib -- fileback::tests::cleanup_orphans_skips_in_use_mapped_storage_without_error --exact --test-threads=1 --quiet cargo test --locked -p victory-gpu --lib -- fileback::tests::cleanup_orphans_ignores_missing_folder --exact --test-threads=1 --quiet ``` Result, each: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1201 filtered out`. What they cover, from the bodies: the first builds a temp tree with two `.tmpXXXXXXXX` orphans plus the near misses (`.tmp` bare, `other.tmp`, a `subdir`, and a `.tmpDir` directory holding a nested `.tmpNested`) and asserts `cleanup_orphans` returns `(2, 4096 + 123)` — both counts and bytes — then that only the two orphans are gone; the second keeps a `MappedStorage` open on a `.tmp` file and asserts cleanup neither errors nor removes it; the third calls it on a path that was never created and expects `(0, 0)`. The caveat: the first test probes the symlink arm opportunistically (`symlink_file` result captured as `has_symlink`), so on a machine without the privilege to create symlinks that part is skipped rather than passed. Temp dirs only, no title files, no device; GPU/driver N/A. No game data.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/4715/head:github-bot/gh-4714'
git switch 'github-bot/gh-4714'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4714'
git switch 'github-bot/gh-4714'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4714'
git switch 'github-bot/gh-4714'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4714'
git switch 'main'
git merge --squash 'github-bot/gh-4714'
git switch 'main'
git merge --ff-only 'github-bot/gh-4714'
git switch 'main'
git merge 'github-bot/gh-4714'
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/trustno1-coder--VIctory-NVIDIA!4715
No description provided.