From aeb3bff3fae35b8eae3b86f45b2ae6383ae8a7fc Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 04:33:21 +0100 Subject: [PATCH] Release the shared build lock when the work volume is low on space --- mesa/BOOTSTRAP.md | 3 +++ tools/vinix-ninja.v | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/mesa/BOOTSTRAP.md b/mesa/BOOTSTRAP.md index 0c30edf..dd35939 100644 --- a/mesa/BOOTSTRAP.md +++ b/mesa/BOOTSTRAP.md @@ -17,6 +17,7 @@ Compile `tools/vinix-ninja.v` as `vinix-ninja` on the build host. Its default in ```sh export VINIX_BUILD_LOCK="$worker_state/compile.lock" VINIX_BUILD_LOCK_FD=9 export VINIX_BUILD_SLICE_SECONDS=180 +export VINIX_BUILD_MIN_FREE_MIB=6912 exec 9>>"$VINIX_BUILD_LOCK" flock -x 9 vpac --native-build "$ports/llvm19-libs/PKGBUILD.vile" "$receipts/llvm19.manifest" @@ -24,6 +25,8 @@ vpac --native-build "$ports/llvm19-libs/PKGBUILD.vile" "$receipts/llvm19.manifes The helper obtains the object prerequisites from Ninja’s graph and completes them in batches of eight. Once a batch exceeds the time slice, it hands the lock to waiting workers. The next batch resumes in the same verified source and build directory. Ninja rechecks the full requested dependency graph and runs the final links while holding the lock. The surrounding vpac process keeps ownership through its checks and archive creation. +`VINIX_BUILD_MIN_FREE_MIB` is an optional free-space threshold for the build filesystem. Before starting each batch or final link, the helper checks the available space. If it falls below this threshold, the helper releases the lock and checks every 30 seconds. Set the threshold above the required reserve to leave room for the next batch. The example leaves a 768 MiB margin above a 6 GiB reserve. The worker test confirmed a waiting build produced no object, a second process acquired the lock, and a build with sufficient space completed. Receipts are in `~/.local/state/vinix/ports/musl-busybox-CqkBEA/xorg/worker/ninja-free-space`. + Monitor the build log for the last completed batch. A clean wait for the lock leaves the original vpac process alive. If the process or host is terminated, preserve its logs and start a fresh native build from the pinned recipe. Use the completed manifest, verify the archive digest, then sign and install it into a clean target root before using the result. A native vpac build of libdrm 2.4.123 yielded after 8, 24 and 32 of its 53 object targets on November 30. A second process acquired the same lock between batches. The calling process still held it after vpac wrote the archive. A check with an unrelated lock file failed. The test archive SHA-256 is `caec67ab38c181231b0ded61a570cd4c8bf3cdf1ec65fc72a8a76caa6306b8bb`. diff --git a/tools/vinix-ninja.v b/tools/vinix-ninja.v index 8787c18..b50964d 100644 --- a/tools/vinix-ninja.v +++ b/tools/vinix-ninja.v @@ -31,6 +31,27 @@ fn build(ninja string, directory string, targets []string) ! { } } +fn wait_for_space(fd int, directory string, minimum_mib u64) ! { + if minimum_mib == 0 { + return + } + mut reported := false + for { + disk := os.disk_usage(directory)! + available_mib := disk.available / (1024 * 1024) + if available_mib >= minimum_mib { + return + } + if !reported { + eprintln('Waiting for ${minimum_mib} MiB of free space in ${directory}; ${available_mib} MiB available.') + reported = true + } + lock(fd, C.LOCK_UN)! + time.sleep(30 * time.second) + lock(fd, C.LOCK_EX)! + } +} + fn run(directory string, targets []string) ! { ninja := os.find_abs_path_of_executable('ninja')! shared := os.getenv('VINIX_BUILD_LOCK') @@ -51,6 +72,7 @@ fn run(directory string, targets []string) ! { if seconds < 1 { return error('VINIX_BUILD_SLICE_SECONDS must be positive') } + minimum_mib := strconv.parse_uint(os.getenv_opt('VINIX_BUILD_MIN_FREE_MIB') or { '0' }, 10, 64)! lock(fd, C.LOCK_EX)! mut query := [ninja, '-C', directory, '-t', 'inputs'] query << targets @@ -63,6 +85,7 @@ fn run(directory string, targets []string) ! { objects := inputs.output.split_into_lines().filter(it.ends_with('.o')) mut since := time.sys_mono_now() for first := 0; first < objects.len; first += 8 { + wait_for_space(fd, directory, minimum_mib)! end := if first + 8 < objects.len { first + 8 } else { objects.len } build(ninja, directory, objects[first..end])! if end < objects.len && time.sys_mono_now() - since >= u64(seconds) * 1_000_000_000 { @@ -75,6 +98,7 @@ fn run(directory string, targets []string) ! { } // Ninja rechecks every dependency and performs the requested final links. // Its caller still owns the same locked file description for packaging. + wait_for_space(fd, directory, minimum_mib)! build(ninja, directory, targets)! } -- 2.56.1