Repository navigation
disk preflight: restore a parked build tree from the cold store when a build needs it - #1341
Merged
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]>
…and zero-reserve exits The check is the first thing fast_preflight does: two stat calls (the tree, then its SSD index entry) and the PLX_COLD_STORE=off test, nothing imported. Only an absent tree with an index entry takes the full command, which loads cold-store.py, takes build-gc's auto lock (waiting up to --wait-secs, with the waiting flag), asks ColdStore.unpark with a free-space-after-copy-stays-above-comfort rule, prints one line and goes on to the ordinary decision. It sits before the exits because make check, install and build-bench run their children with PLX_DISK_BUDGET_DONE=1. Any failure costs one line, never the build. 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
The failed-copy case now logs the estimate line before the copy as well as the one outcome line, so assert one of each rather than one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e wait deadline; no-gos before the wait Review findings on the preflight unpark: 1. cmd_preflight takes ONE --wait-secs deadline at its start; the unpark's wait for build-gc's auto lock and wait_on_holder both spend what is left of it, so a build never waits twice the budget on a held lock. 2. The cheap no-gos come first: ColdStore.unusable() (the config, ditto, the cold volume mounted: available()'s first three steps) ends the unpark with one line before any lock is waited for. 3. The auto lock is no longer held across the copy. ColdStore.claim() decides (the cost rule and the caller's free-space rule, which now also counts what other live claims are still to copy) and atomically renames the index record to index/<id>.json.unparking.<pid>; unpark(claimed=...) copies without the lock and consumes the claim, or gives it back on any failure. A claimed entry is invisible to a second unparker (told "being restored by pid N"), to recover's adoption and to the park pass; a dead claimer's claim is put back by the next claim of that tree and by recover. The fast path also looks for a claim, so the build says who has the tree. 4. The free-space rule has its own test: a copy that would leave less than the comfort line free is declined and the entry stays. make disk and cold-store.py status list a claim as "restoring". 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
When a build starts and its own cargo tree is absent, the disk preflight now copies the tree back from the opt-in cold store (#1340), if a parked copy is indexed for it.
tools/disk-budget.py preflight, before thePLX_DISK_BUDGET_DONEandPLX_MIN_FREE_MB=0exits. That way the children ofmake check,installandbuild-bench(all run with DONE=1) also get their tree back. Only the entry's ownDISK_TREEcomes back. A directcargoreaches no preflight and rebuilds cold.lstatof the tree, plus an indexstatorlistdironly when the tree is absent. That adds about 0.5 ms; the median was 23.2 → 23.7 ms over 20 runs. The import-set test still pinsos/sysonly..unparking.<pid>.make checkrestore in parallel.recover. A failure, a decline or an exception gives the claim back without overwriting a newer record.cmd_preflightuses a single deadline for the unpark wait and the ordinary lock wait, so a build never waits 2 ×--wait-secs.Why
This is the last piece of the cold store. Parking an idle tree only pays off if it comes back when that lane builds again. Measured on the owner's Mac:
targetparked on the external disk came back in 0.3 s atmake check-nodef.Finished in 0.05s.Verification
All on the committed tree:
ci/test_disk_preflight.py: 54 tests, OK. The tests cover:cold-store.pyload when the tree is present, when there is no index entry, or when the cold store is off;cold-store.py's.ci/test_cold_store.py: 74 tests, OK.ci/test_disk_budget.py: 142 tests, OK.ci/test_build_gc.py: 81 tests, OK.ci/test_ci_split.py: 16 tests, OK.One Opus review found four minor issues, and all four are fixed:
--wait-secs;🤖 Generated with Claude Code