From fe18ae43cfcd417c34ac60d367606ef247537f85 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 20 Apr 2026 16:54:03 +0200 Subject: [PATCH] Fix enlarge_swap.sh starving deploys of disk space (#162) Swap size was free(/)-25, which took ~99 GB on the 145 GB root fs. Remaining ~25 GB then ran out mid-deploy during Playwright image pulls (ENOSPC). Replace with a fixed 16 GB cap and use mountpoint to detect a real /mnt partition instead of [ -d /mnt ], which matched the empty placeholder dir on single-partition runners. Co-Authored-By: Claude Opus 4.7 --- .../artefact/files/github/workflow.md | 6 +- scripts/github/enlarge_swap.sh | 69 ++++++++++--------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/docs/contributing/artefact/files/github/workflow.md b/docs/contributing/artefact/files/github/workflow.md index 430ac8425f..807a9d09f9 100644 --- a/docs/contributing/artefact/files/github/workflow.md +++ b/docs/contributing/artefact/files/github/workflow.md @@ -68,13 +68,13 @@ Set an option back to `false` only when a new host-side step in the same workflo Deploy test workflows enlarge host swap via [enlarge_swap.sh](../../../../../scripts/github/enlarge_swap.sh) to absorb transient memory spikes (e.g. PeerTube plugin install [#162](https://github.com/infinito-nexus/core/issues/162)) that would otherwise trip the host OOM-killer on the 16 GB GitHub-hosted runner. -The script **prefers `/`** for deterministic placement and falls back to `/mnt` only when `/` does not have enough headroom. Preferring `/` avoids surprises from runners where `/mnt` is unexpectedly pre-populated (larger-runner images, custom Docker-data-root relocations, self-hosted setups). +The script **prefers `/mnt`** when it is a separate partition (classic `ubuntu-latest` layout with `/dev/sdb` mounted at `/mnt`) and falls back to `/` otherwise. Current public runners no longer expose a separate `/mnt`, so the swapfile lands on `/` and must not starve the root filesystem. -Swap size is computed dynamically: `free(/) - buffer`. The buffer reserves space for nested Docker layers, the checkout, and the runner cache. With the aggressive `free-disk-space` options above, a ~25 GB buffer typically leaves a 25–30 GB swapfile on `ubuntu-latest`, which is far more than any workload the deploy jobs currently trigger. +Swap size is a **fixed constant**, not a "free space minus buffer" calculation. An earlier version took ~99 GB on a 145 GB root partition, leaving so little headroom that later Docker layer writes (Playwright test image pull) failed with `no space left on device`. A fixed cap is large enough to absorb the peertube spike and small enough that Docker layer writes keep succeeding throughout the 30+ min deploy. | Argument | Default | Reason | |---|---|---| -| `buffer-gb` (positional) | `25` | Reserves headroom for nested Docker data, checkout and runtime state; pass a smaller value only when you know the job footprint shrinks | +| `size-gb` (positional) | `16` | Empirically sufficient for the peertube memory spike ([#162](https://github.com/infinito-nexus/core/issues/162)); raise only when a workload is proven to need more | Workflow step invocation: diff --git a/scripts/github/enlarge_swap.sh b/scripts/github/enlarge_swap.sh index 4466289605..945266437c 100755 --- a/scripts/github/enlarge_swap.sh +++ b/scripts/github/enlarge_swap.sh @@ -1,13 +1,19 @@ #!/usr/bin/env bash -# Enlarge host swap on a GitHub-hosted runner. Consumes all remaining -# space on / minus a reserved buffer for Docker layers, checkout and -# runtime data. Falls back to /mnt when / is too small. Replaces -# whatever swap was already active. Needed on 16 GB runners where -# transient spikes (e.g. peertube plugin install, issue #162) otherwise -# trip the host OOM-killer. +# Enlarge host swap on a GitHub-hosted runner. Replaces the runner's +# default ~4 GB swap with a fixed-size swapfile so transient memory +# spikes (e.g. peertube plugin install, issue #162) don't trip the host +# OOM-killer, WITHOUT starving the rest of the job of disk space. # -# Usage: enlarge_swap.sh [buffer-gb] -# Default buffer: 25 GB (nested Docker images + checkout + runner cache). +# Prefers /mnt when it is a separate partition (classic ubuntu-latest +# layout with /dev/sdb mounted at /mnt). On current public runners +# there is no separate /mnt partition — everything lives on /, so we +# place the swapfile there. The swap size is a hard constant, never a +# "free minus buffer" computation: a previous version consumed ~99 GB +# on a 145 GB root, leaving so little headroom that later Docker layer +# writes (Playwright test image pull) failed with ENOSPC. See #162. +# +# Usage: enlarge_swap.sh [size-gb] +# Default: 16 GB (empirically sufficient for the peertube spike). # # Debug toggle: set SKIP_SWAP=1 to leave the runner's default swap # untouched (A/B probe for issues caused by this script itself). @@ -23,44 +29,43 @@ if [ "${SKIP_SWAP:-0}" = "1" ]; then exit 0 fi -BUFFER_GB="${1:-25}" -MIN_SWAP_GB=4 # refuse to create a swapfile smaller than this +SWAP_GB="${1:-16}" +MIN_FREE_GB=$((SWAP_GB + 4)) # need the target size plus a little slack "$DUMP" "before swap resize" sudo swapoff -a || true sudo rm -f /mnt/swapfile /swapfile -root_free=$(df --output=avail -B1G / | tail -n1 | tr -d ' ') -mnt_free=0 -if [ -d /mnt ]; then +# Only treat /mnt as a candidate if it is actually a separate mount. +# On current ubuntu-latest public runners /mnt is an empty directory +# on the root fs, which would double-count free space. +if mountpoint -q /mnt 2>/dev/null; then mnt_free=$(df --output=avail -B1G /mnt | tail -n1 | tr -d ' ') -fi - -root_swap=$((root_free - BUFFER_GB)) -mnt_swap=$((mnt_free - BUFFER_GB)) - -echo "Candidates: / has ${root_free}G free → up to ${root_swap}G swap; /mnt has ${mnt_free}G free → up to ${mnt_swap}G swap (buffer ${BUFFER_GB}G)" - -if [ "$root_swap" -ge "$MIN_SWAP_GB" ]; then - target=/swapfile - size=$root_swap - chosen="/ (preferred)" -elif [ "$mnt_swap" -ge "$MIN_SWAP_GB" ]; then - target=/mnt/swapfile - size=$mnt_swap - chosen="/mnt (fallback)" else - echo "Neither / nor /mnt has ${MIN_SWAP_GB}+${BUFFER_GB} GB free for swap" >&2 + mnt_free=0 +fi +root_free=$(df --output=avail -B1G / | tail -n1 | tr -d ' ') + +echo "Target swap: ${SWAP_GB}G. Free: / ${root_free}G, /mnt ${mnt_free}G (separate mount: $(mountpoint -q /mnt 2>/dev/null && echo yes || echo no))" + +if [ "$mnt_free" -ge "$MIN_FREE_GB" ]; then + target=/mnt/swapfile + chosen="/mnt (separate partition)" +elif [ "$root_free" -ge "$MIN_FREE_GB" ]; then + target=/swapfile + chosen="/ (no separate /mnt)" +else + echo "Neither / nor /mnt has ${MIN_FREE_GB} GB free for a ${SWAP_GB} GB swapfile" >&2 df -h / /mnt >&2 exit 1 fi -echo "Chose ${chosen}: creating ${size}G swapfile at ${target}" +echo "Chose ${chosen}: creating ${SWAP_GB}G swapfile at ${target}" -sudo fallocate -l "${size}G" "$target" +sudo fallocate -l "${SWAP_GB}G" "$target" sudo chmod 600 "$target" sudo mkswap "$target" sudo swapon "$target" -"$DUMP" "after swap resize → ${size}G at ${target}" +"$DUMP" "after swap resize → ${SWAP_GB}G at ${target}"