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

Open
nidea1 wants to merge 1 commit from upstream-pr/4714 into main
nidea1 commented 2026-12-01 03:10:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-12-01T03:10:27Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5578180967 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4714). Originally posted by [nidea1](https://github.com/nidea1) on 2026-12-01T03:10:27Z. --- ## 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.
nidea1 commented 2026-12-01 12:33:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-12-01T12:33:45Z.


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7311318427 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4714#issuecomment-7311318427). Originally posted by [nidea1](https://github.com/nidea1) on 2026-12-01T12:33:45Z. --- 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).
cloph-dsp commented 2026-12-01 18:51:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by cloph-dsp on 2026-12-01T18:51:29Z.


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, a .tmpDir directory holding a nested .tmpNested, and a .tmpLink symlink to keep.bin), asserts cleanup_orphans returns (2, 4096 + 123) — both counts and bytes — and then that the two orphans are gone while every near miss survives. The second keeps a MappedStorage open, fills it with a byte pattern, drops an unrelated .tmp orphan beside it, and asserts cleanup returns (1, 2048), that one file remains in the folder ("live mirror file stays"), that the mapped bytes are unchanged after cleanup, and that dropping the storage leaves the folder empty. The third calls it on a path that was never created and expects (0, 0).

Two caveats. The symlink arm of the first test is probed rather than required (symlink_file result captured as has_symlink), so on a machine that cannot create symlinks that assertion is skipped. And cleanup_orphans_skips_in_use_mapped_storage_without_error proves the file survives clean-up, not that the survival comes from the lock check rather than from MappedStorage creating its file under a name the scan skips — worth knowing if the file-naming rule ever changes.

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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321685061 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4714#issuecomment-7321685061). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-12-01T18:51:29Z. --- 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`, a `.tmpDir` directory holding a nested `.tmpNested`, and a `.tmpLink` symlink to `keep.bin`), asserts `cleanup_orphans` returns `(2, 4096 + 123)` — both counts and bytes — and then that the two orphans are gone while every near miss survives. The second keeps a `MappedStorage` open, fills it with a byte pattern, drops an unrelated `.tmp` orphan beside it, and asserts cleanup returns `(1, 2048)`, that one file remains in the folder ("live mirror file stays"), that the mapped bytes are unchanged after cleanup, and that dropping the storage leaves the folder empty. The third calls it on a path that was never created and expects `(0, 0)`. Two caveats. The symlink arm of the first test is probed rather than required (`symlink_file` result captured as `has_symlink`), so on a machine that cannot create symlinks that assertion is skipped. And `cleanup_orphans_skips_in_use_mapped_storage_without_error` proves the file survives clean-up, not that the survival comes from the lock check rather than from `MappedStorage` creating its file under a name the scan skips — worth knowing if the file-naming rule ever changes. Temp dirs only, no title files, no device; GPU/driver N/A. No game data.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/4714:upstream-pr/4714'
git switch 'upstream-pr/4714'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/4714'
git switch 'upstream-pr/4714'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/4714'
git switch 'upstream-pr/4714'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/4714'
git switch 'main'
git merge --squash 'upstream-pr/4714'
git switch 'main'
git merge --ff-only 'upstream-pr/4714'
git switch 'main'
git merge 'upstream-pr/4714'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!4714
No description provided.