[pr-fix][memory] CPU mirror files leave 4 GiB free on their drive #339
Loading…
Reference in a new issue
No description provided.
Delete branch "Andreww2009/Darner-Opt:claude/cpu-mirror-room-left"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What it changes
DARNER_CARD_CPU_FILE=1(adarner playdefault) the CPU mirrors are temporary files in the cache'scpu-mirrorsfolder, made without a look at the drive's free space, so on an almost full drive they take its last bytes. One session here (v2026.12.03.01, Series X, the cache on C:):file_mib=994as the world began tofile_mib=3385ten minutes later, and C: reached 0 bytes free (the mirrors were 3.3 GB of what filled it; other programs wrote there too);file-backed CPU mirror unavailableline); 7 of the 8 host pipeline library saves between 09:10 and 09:22 UTC did (host pipeline library not saved error=... (os error 112)), and oneshared pipeline lists not saved. A save writes a whole new copy of the library (1,180,832,868 bytes in the one that landed) before renaming it;MappedStorage::new(crates/darner-gpu/src/fileback.rs) now reads the drive's free space (GetDiskFreeSpaceExW) before it makes a file, and refuses one that would leave less than 4 GiB free (io::ErrorKind::StorageFull, with the numbers in the message). The callers already handle a failed file:CardCpu::allocatewarns once (file-backed CPU mirror unavailable; falling back to private memory) and keeps that mirror in private memory, andCardCpu::lazykeeps its reserved-only mirror. Each later mirror tries a file again, so files resume when the drive has room. A drive whose free space cannot be read is not refused. In this crate's unit tests no room is kept, since they make files in whatever temp folder the runner has.docs/windows-memory.mdsays the same in one sentence.Nothing changes on a drive with more than 4 GiB plus the file free.
shadow.rsand the launchers are untouched; the 4 GiB is a constant, not a new switch.How it was tested
f3840d73(the tests and gates ran on the same tree just before it was committed)cargo test --locked -p darner-gpu --lib fileback -- --nocapture --test-threads=1: 5 passed (the 3 there were, and 2 new: the room arithmetic, and a file that would leave too little room is refused withStorageFull, no OS error, and no file made).cargo test --locked -p darner-gpu --lib a_mirror_let_go_keeps_its_address: 1 passed (it makes a mirror file throughMappedStorage::new).cargo test --locked -p darner-gpu --lib, both test binaries built once and run alternately, 8 times each (order swapped every run):mainf3840d73: 2 passed, 5 failed, 1 still running after 300 s (stopped). Failed:watch::tests::ask_once_by_res_splits_reservations_without_refusals(3),watch::tests::a_late_fault_leaves_the_guard_taken_since(2),watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock(1),host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end(1).host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end(4),watch::tests::ask_once_by_res_splits_reservations_without_refusals(3),watch::tests::a_late_fault_leaves_the_guard_taken_since(1),host::refresh_tests::chunked_nothing_new_with_matches_individual(1).watch::tests::ask_once_by_res_splits_reservations_without_refusalsanddescriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync(#274 also saw that one fail once with its own change).filebacktests anda_mirror_let_go_keeps_its_addressmake a mirror file.mainfails by chance too (#274 saw 7 of 8mainruns fail; #224 and #262 work on such failures).GetDiskFreeSpaceExWtook 9.2 µs a call (median of 5 × 20,000) on the cache's drive and 15.2 µs on C:, against 440–580 µs for making, mapping and deleting one mirror-sized file the same way (both timed through Python ctypes, so a little high). With the ~4,400 files of a session (#101's count) that is about 40–70 ms in a whole session.cargo xtask policy(555 files ok). Gate 3 not run as a whole:cargo test -p darner-gpu --libabove instead, the only crate changed./dev/shm(DARNER_MIRRORS_TMPFS), where the same check would keep 4 GiB of tmpfs free; not tested there.Checklist
main.docs/asset-policy.md.Checked for overlap
🤖 Generated with Claude Code
6a9b0df covers the UNC gap in the free-space query. The launcher canonicalizes the mirror directory, which can produce a verbatim UNC path. The Windows API requires the trailing backslash for UNC directories, and a query failure takes this PR's fallback path. GetDiskFreeSpaceExW parameter documentation
The same argument test failed on
3e6e6c2and passed on the follow-up for ordinary UNC, verbatim UNC, a path already ending in a backslash, and a local drive path. The real Windows free-space query succeeded on the local directory before and after. UNC validation used synthetic paths. Focusedcargo check, the asset policy and the diff check passed.If you cherry-pick or rebase this commit, please keep the Git author. If you fold it into your own commit, please add this trailer.
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>Code review only (read the diff at
3e6e6c27), nothing built or run.shadow.rs:244), which is commit, the thing the file mirrors exist to save (docs/windows-memory.md). When the cache and the page file share a nearly full drive, Windows can't grow the page file much either. So on those PCs this likely moves some pressure from disk to commit (lazy mirrors that stay reserved-only don't count). Probably still better than a full C:, but a run on a drive with only a few GB free, watching available commit and the fallback count, would show it. A sentence in the docs would help testers who hit "out of memory" afterwards.GetDiskFreeSpaceExWdocs (UNC needs a trailing backslash). Without a fix, a UNC mirror folder skips the check (fails open, harmless). I haven't read their commit.Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
I added the requested note in f838569. The low-disk fallback can raise system commit, and a page file on the same nearly full drive may have little room to grow. The docs now tie the reduction in private commit to the file-backed mirrors.
The docs commit is based on
3e6e6c27and merges cleanly with the earlier UNC path fix6a9b0df. Asset policy and diff checks passed. The UNC fix was checked with synthetic UNC paths and a local Windows volume. A live share and a near-full drive remain untested.If you cherry-pick or rebase this commit, please keep the Git author. If you fold it into another commit, please add this trailer.
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.