Repository navigation
disk tooling: opt-in cold store parks idle build trees on an external disk instead of deleting them - #1340
Merged
Conversation
The build-entry preflight stalled 20-35 minutes in IO wait on a Mac whose 21 lane worktrees sit on a slow USB disk: collect() sized, mtime-walked, git-probed and lock-probed every tree, and only afterwards did never() throw out the ones on another volume than the build. Removing such a lane frees nothing on the volume that is short, so none of that read was ever useful. - disk-budget.py collect(): ask the one device lookup (device_of, which tests stub) first; a tree on another device is listed with its dev, kind, checkout and owner and nothing else (no measure, newest_mtime, tracked_under, lock probes, or lane git facts). never() keeps rejecting it; the report prints it as "other volume (not sized)". size_foreign is unrelated (it sizes a /tmp tree with no PlxNative marker) and is documented as such. - build-gc.sh: --auto's --worktrees pass skips a lane on another device than ROOT before worktree_reason / idle_lane read it; by hand it is judged as before. New path_dev / on_other_volume helpers (GNU stat first: on Linux `stat -f %d` is a free-inode count). - make disk: on macOS one line says whether the hourly launchd agent com.plxnative.build-gc is loaded, and that `make disk-watch` loads it (it sat unloaded for ~19 h with 19 GiB unreclaimed, silently). - docs/disk-budget.md and the --worktrees help text say so. - Tests: raising readers/probes for a foreign-dev lane and fleet tree (ci/test_disk_budget.py), a foreign-device lane skipped by --auto without a find over it, and the agent line (ci/test_build_gc.py). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first pass skipped a tree on another volume, but a fleet tree (~/plx-fleet/<lane>, the lane's CARGO_TARGET_DIR) is on the build's volume while its lane's worktree can sit on the slow USB disk, and three readers still walked that worktree: - disk-budget.py collect(): is_merged / is_clean (a squash check and a `git status` over the whole worktree) now run only for a checkout on the build's volume; a foreign one reads neither merged nor clean (the conservative side). The `make check` lock is still probed: it is a flock on a local file named by a hash of the checkout's path, reads nothing on the slow disk, and a check running there builds into this very tree. - build-gc.sh --evict: ev_lane_active counts a checkout on another volume as active instead of `find -mmin` over it, so its fleet tree is spared, and the skip line says why. - build-gc.sh report (`make disk`): a worktree on another volume prints `-` columns and "other volume, not sized" instead of running du over its checkout, its target trees and its incremental dirs. Tests: OtherVolume in ci/test_disk_budget.py (only the worktree foreign, fleet tree local; every git reader raises), ci/test_build_gc.py (a logging find and du shim behind a fake stat). docs/disk-budget.md says so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Park an idle derived build tree on a second volume (a big external disk) and
bring it back when its owner builds again. Off unless a per-user `cold-store`
config names a root: unconfigured, every entry point returns before creating a
file anywhere.
- config (key=value in the tv-config.sh directory, PLX_COLD_STORE{,_CONFIG}),
available() with its six ordered reasons, an SSD index plus a cold-side
record, park (rename into a same-volume parking dir, ditto to .partial,
verify count + apparent bytes, record, rename), unpark (absent origin only,
cost rule, sibling copy, verify, rename), prune and residue recovery.
- the one copy primitive is `ditto --norsrc`; tests swap in a hard-link
preserving shutil walk, and one darwin-only test drives the real ditto
(regular-file and directory ns mtimes, modes and hard links survive; a
symlink's mtime does not, which nothing reads).
- no caller yet: the --auto park-ahead stage and the preflight unpark land
with the next workstreams.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and the floor Co-Authored-By: Claude Opus 5.5 <[email protected]>
`build-gc.sh --auto` gains one stage between --orphans and --worktrees: with a cold store configured and free space under park_below_gib (40 GiB, above the 20 GiB comfort line), `disk-budget.py park --auto` moves the planner's idle whole-tree candidates (rungs 3 and 4 of ladder() --no-build, oldest first, never garbage, the main checkout, the seed, live or young trees, merged lanes or anything on another volume) to the cold volume, up to park_max_gib_per_run, then recovers parking residue and prunes copies that no longer earn their space. Each tree is asked once more, right before the rename, with probe_tree (the executor's checks) plus a lane-idle rule (a source edit counts, .git does not). The pass releases and re-takes build-gc's auto lock between trees and stops after the current tree when a preflight is waiting: wait_on_holder writes a <lock>.waiting.<pid> flag the pass reads. `--park [-n]` is the same pass by hand. Unconfigured, `--auto` prints and logs exactly what it did before (golden test). Also: ColdStore.rate_for takes the slower of the measured rate and the floor, and a dry-run park creates nothing on either volume (available(write_probe=False)). `make disk` shows the cold store state, parked count/bytes and parking residue. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re the SSD copy goes, guard the post-copy steps Review fixes on the park pass. - A park holds build-gc's auto lock for a whole ditto (minutes) while a preflight waits 60 s and then judges on free space with no eviction. `--auto` now parks only from the comfort line (PLX_GC_MIN_FREE_GIB) up to park_below_gib; below it the stage prints one line and the ladder deletes as before, and the pass re-reads free space before each tree and stops when it fell under the line. recover(), prune() and the reap take a `stop` callback (the waiting flag) and end between items; the pass hands the lock back instead of sweeping the slow disk with a build waiting. - After the copy verifies, one flush of the cold volume (os.sync, then F_FULLFSYNC through the cold record file; fsync where there is none) runs before the index is written and the SSD copy deleted. - The steps after the copy (set-aside, record, rename into place, flush, index) are guarded: any OSError puts the tree back and reports FAILED; a copy already renamed in becomes .dead debris so recover reaps it rather than adopting it. run_park_pass turns any other exception into a logged FAILED that ends the pass. - unpark set-asides use unique `.consumed.<pid>.<ns>` names (the second unpark of a tree used to fail its rename and leak a stale copy), the reap matches debris names as a whole suffix, and a park sets an unrecorded stale copy aside under a unique name too. - unpark logs one line before its copy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # tools/build-gc.sh
GLinnik21
added a commit
that referenced
this pull request
Nov 11, 2026
GLinnik21
added a commit
that referenced
this pull request
Nov 11, 2026
GLinnik21
added a commit
that referenced
this pull request
Nov 11, 2026
When a build's own cargo tree is absent and the opt-in cold store (#1340) indexes a parked copy of it, the disk preflight copies it back before cargo runs. The check is first in `disk-budget.py preflight`, ahead of the PLX_DISK_BUDGET_DONE and PLX_MIN_FREE_MB=0 exits, so make check/install/build-bench children are covered; the fast path stays import-free (one lstat, ~0.5 ms). - Off or unmounted cold store: one line, no lock wait. - Under build-gc's lock the preflight only claims the copy (atomic rename of the index entry to .unparking.<pid>); the copy runs unlocked, so two trees restore in parallel; a second build of the same tree is told it is being restored and rebuilds; a dead claimer's entry is put back by the next claim or recover. - Restores only when size / the slower of measured and floor rate beats the tree's rebuild time and free space after the copy, counting copies in flight, stays above the comfort line. - One deadline covers the unpark wait and the ordinary lock wait; any failure prints one line and the build goes on as if the cold store were off. Measured on the owner's Mac: a parked 208.7 MiB target came back in 0.3 s and cargo reported Fresh 114, Dirty 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This adds an opt-in cold store. When the internal SSD runs low, idle cargo build trees are copied to a slow external disk instead of the disk-budget ladder deleting them. A later PR copies a parked tree back when a build that needs it starts.
Off by default
cold-store(with aroot=line) exists in the same config dir astv-host(~/.config/plxnative/).PLX_COLD_STORE=off|<root>andPLX_COLD_STORE_CONFIG=<file>override it.build-gc.sh --autoprints and logs exactly what it did before, above and below the threshold.dittois missing;min_free_gib;Parking
--autostage, after--orphans. It runs only between the comfort line (20 GiB free) andpark_below_gib(40 GiB). Below the comfort line it parks nothing and the ladder deletes as before, because a copy to a spinning disk takes minutes and a waiting build gives up after 60 s./tmptrees, idle lane and fleet trees), oldest first, up topark_max_gib_per_run. Each tree is re-probed for liveness, and its lane must have been idle forpark_idle_min.dittoit to<root>/trees/<id>.partial;syncandF_FULLFSYNC);recover.--autolock is released and re-taken between trees. The pass yields, and so dorecoverandprune, when a build preflight is waiting.max_days, or the cold volume is short of space.build-gc.sh --park [-n]runs the pass, andtools/cold-store.py status|list|park|unpark|prune|recovergives direct control.make diskshows whether the cold store is on (or why not), what is parked, and any leftovers.Why
The internal 228 GiB SSD keeps running out when several worktrees build at once. The external disk has terabytes free but is a spinning USB disk (12 MB/s reads under load), so nothing a running build touches goes there.
Measured on the owner's Mac: copying a tree back takes 0.18-0.59x a cold rebuild (4-12 s against 16-29 s for 212-804 MiB trees). After a
dittoround trip cargo sees every unit asFresh(114/114, 0 Dirty), and all 2160 hard links survive.Verification
All on the committed tree:
ci/test_cold_store.py: 63 tests OK. They cover:ci/test_disk_budget.py: 142 tests OK.ci/test_build_gc.py: 81 tests OK, including the unconfigured golden runs and the park stage above and below the comfort line.ci/test_disk_preflight.py: 32 tests OK.ci/test_ci_split.py: 16 tests OK.One Opus review of this diff found three issues, and all were fixed:
A real-disk run (W4's) found two more, also fixed:
.consumedname collision when the same tree was parked twice;🤖 Generated with Claude Code