Skip to content

Commit b040885

Browse files
committed
CI: use alternative disks if available
cleaning up disk space takes a lot of time
1 parent a8664a1 commit b040885

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/ci/scripts/free-disk-space-linux.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,47 @@ cleanSwap() {
247247
free -h
248248
}
249249

250+
# Try to find a different drive to put our data on so we don't need to run cleanup.
251+
# The availability of the disks we're probing isn't guaranteed,
252+
# so this is opportunistic.
253+
checkAlternative() {
254+
local mountpoint="/mnt"
255+
256+
# we need ~50GB of space
257+
local space_target_kb=$((50 * 1024 * 1024))
258+
local available_space_kb=$(df -k "$mountpoint" --output=avail | tail -n 1)
259+
260+
local mntopts="defaults,discard,async_journal_commit,barrier=0,noauto_da_alloc,lazytime,data=writeback"
261+
262+
# GHA has a 2nd disk mounted at /mnt that is almost empty
263+
if mountpoint /mnt && [ "$available_space_kb" -ge "$space_target_kb" ]; then
264+
local blkdev=$(df -k "$mountpoint" --output=source | tail -n 1)
265+
echo "Sufficient space available on $blkdev mounted at $mountpoint"
266+
sudo swapoff -a || true
267+
mkdir ./obj
268+
# remount with O_EATMYDATA while we're at it
269+
sudo umount /mnt
270+
sudo mount $blkdev ./obj -o $mntopts || sudo dmesg | tail -n 20
271+
272+
exit 0
273+
fi
274+
275+
# ephemeral NVMe drives on AWS
276+
for dev in /dev/nvme*n1; do
277+
if [ -b "$dev" ] && [ "$(mount | grep "$dev" | wc -l)" -eq 0 ]; then
278+
echo "Found unused block device $dev, creating filesystem"
279+
sudo mkfs.ext4 -E lazy_itable_init=1,lazy_journal_init=1 "$dev"
280+
mkdir ./obj
281+
sudo mount "$dev" ./obj -o $mntopts
282+
283+
exit 0
284+
fi
285+
done
286+
}
287+
288+
289+
checkAlternative
290+
250291
# Display initial disk space stats
251292

252293
AVAILABLE_INITIAL=$(getAvailableSpace)

0 commit comments

Comments
 (0)