[pr-fix][memory] CPU mirror files a PC reset left behind are removed at the next start #101

Manually merged
TrustNo1 merged 1 commit from iboom72/fix/cpu-mirror-leftovers into main 2026-12-03 20:54:58 +00:00 AGit
Contributor

What it changes

With DARNER_CARD_CPU_FILE=1 (the default in darner.exe), the CPU mirrors of two-sided GPU buffers are temporary files in the cache's cpu-mirrors folder. They are deleted when their handles close. A run that ends with the PC itself (a hard reset, a power cut) closes nothing, so the files stay, and on Windows nothing removed them afterwards: only the tmpfs folder under Linux was cleared at start.

Seen on one Windows 11 PC after a run that ended in a hard reset (Kernel-Power 41): 4,428 files, 7.1 GB, all created by that run, fully allocated on disk.

cpu_mirror_files now removes the files in the folder that no process holds, for both folders, so the Linux-only loop in linux_tmpfs_mirrors is gone. A file a running process maps is opened without sharing (tempfile uses share mode 0), so its removal is refused and it stays. The README row and docs/windows-memory.md say so.

Not covered: with DARNER_CARD_CPU_FILE off, the folder is not looked at, so leftovers from earlier runs stay until it is on again.

How it was tested

  • Tested revision: 3751c06c on main 1a5286a7. The clippy gates and the tests ran on the same tree before it was committed.
  • Commands and results:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
    • cargo test --locked -p darner-gpu --lib fileback::: 3 passed, including the new leftovers_go_and_a_mapped_file_stays (a leftover file is removed, a mapped one stays and is still writable).
    • cargo test --locked -p darner: 131 passed, 1 ignored, plus its integration tests.
    • shadow::file_backing_tests::two_sided_mirrors_preserve_gpu_copies_and_later_cpu_writes, run with --ignored and DARNER_CARD_CPU_FILE=1, DARNER_CARD_BUFFERS_MIN_KB=64, DARNER_SEND_OWN=1 on an RTX 4070 Ti, with a leftover file planted in the mirror folder: passed, and the folder was empty afterwards.
    • cargo xtask policy: 553 files ok.
  • Gameplay, when relevant: not run in the game.
  • Before and after, when relevant: none.
  • Shader wave sizes tested, when relevant: not relevant.
  • Coverage gaps: cargo test --workspace --locked was not run in full. Nothing was run under Linux/Proton, where the clean-up now runs from the shared code instead of linux_tmpfs_mirrors. Two darner.exe processes sharing one cache folder were not run together; the test covers a mapped file in the same process.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found for the same problem. Sharing a file only: #37, #56 and #62 (shadow.rs); #9, #12, #16, #36, #59, #75 and #80 (play.rs); several add README rows. None touches fileback.rs or docs/windows-memory.md.

🤖 Generated with Claude Code

## What it changes With `DARNER_CARD_CPU_FILE=1` (the default in `darner.exe`), the CPU mirrors of two-sided GPU buffers are temporary files in the cache's `cpu-mirrors` folder. They are deleted when their handles close. A run that ends with the PC itself (a hard reset, a power cut) closes nothing, so the files stay, and on Windows nothing removed them afterwards: only the tmpfs folder under Linux was cleared at start. Seen on one Windows 11 PC after a run that ended in a hard reset (Kernel-Power 41): 4,428 files, 7.1 GB, all created by that run, fully allocated on disk. `cpu_mirror_files` now removes the files in the folder that no process holds, for both folders, so the Linux-only loop in `linux_tmpfs_mirrors` is gone. A file a running process maps is opened without sharing (`tempfile` uses share mode 0), so its removal is refused and it stays. The README row and `docs/windows-memory.md` say so. Not covered: with `DARNER_CARD_CPU_FILE` off, the folder is not looked at, so leftovers from earlier runs stay until it is on again. ## How it was tested - Tested revision: 3751c06c on `main` 1a5286a7. The clippy gates and the tests ran on the same tree before it was committed. - Commands and results: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. - `cargo test --locked -p darner-gpu --lib fileback::`: 3 passed, including the new `leftovers_go_and_a_mapped_file_stays` (a leftover file is removed, a mapped one stays and is still writable). - `cargo test --locked -p darner`: 131 passed, 1 ignored, plus its integration tests. - `shadow::file_backing_tests::two_sided_mirrors_preserve_gpu_copies_and_later_cpu_writes`, run with `--ignored` and `DARNER_CARD_CPU_FILE=1`, `DARNER_CARD_BUFFERS_MIN_KB=64`, `DARNER_SEND_OWN=1` on an RTX 4070 Ti, with a leftover file planted in the mirror folder: passed, and the folder was empty afterwards. - `cargo xtask policy`: 553 files ok. - Gameplay, when relevant: not run in the game. - Before and after, when relevant: none. - Shader wave sizes tested, when relevant: not relevant. - Coverage gaps: `cargo test --workspace --locked` was not run in full. Nothing was run under Linux/Proton, where the clean-up now runs from the shared code instead of `linux_tmpfs_mirrors`. Two `darner.exe` processes sharing one cache folder were not run together; the test covers a mapped file in the same process. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found for the same problem. Sharing a file only: #37, #56 and #62 (`shadow.rs`); #9, #12, #16, #36, #59, #75 and #80 (`play.rs`); several add README rows. None touches `fileback.rs` or `docs/windows-memory.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A run that ends with the PC (a reset, a power cut) closes none of its
temporary mirror files (DARNER_CARD_CPU_FILE=1), so nothing deletes them:
4,428 files, 7.1 GB, in the cache's cpu-mirrors folder after one such run
on Windows. Only the tmpfs folder under Linux was cleared at start.

cpu_mirror_files now removes what no process holds, in either folder. A
file a running process maps is opened without sharing, so its removal is
refused and it stays (tested).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
TrustNo1 manually merged commit 71f4518633 into main 2026-12-03 20:54:58 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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
TrustNo1/Darner!101
No description provided.