Skip to content

Commit 1d7b3f2

Browse files
the8472marcoieni
andcommitted
[review] add more comments
Co-authored-by: Marco Ieni <[email protected]>
1 parent 33c1bf4 commit 1d7b3f2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,38 @@ checkAlternative() {
257257
local space_target_kb=$((50 * 1024 * 1024))
258258
local available_space_kb=$(df -k "$gha_alt_disk" --output=avail | tail -n 1)
259259

260+
# mount options that trade durability for performance
260261
# ignore-tidy-linelength
261262
local mntopts="defaults,discard,journal_async_commit,barrier=0,noauto_da_alloc,lazytime,data=writeback"
262263

263264
# GHA has a 2nd disk mounted at /mnt that is almost empty.
265+
# Check if it's a valid mountpoint and it has enough available space.
264266
if mountpoint "$gha_alt_disk" && [ "$available_space_kb" -ge "$space_target_kb" ]; then
265267
local blkdev=$(df -k "$gha_alt_disk" --output=source | tail -n 1)
266268
echo "Sufficient space available on $blkdev mounted at $gha_alt_disk"
269+
# see cleanSwap(), swapfile may be mounted under /mnt
267270
sudo swapoff -a || true
271+
272+
# unmount from original location
268273
sudo umount "$gha_alt_disk"
274+
275+
# remount under the obj dir which is used by docker scripts to write most
276+
# of our build output. And apply optimized mount options while we're at it.
269277
mkdir ./obj
270-
# remount with O_EATMYDATA while we're at it
271278
sudo mount $blkdev ./obj -o $mntopts || (sudo dmesg | tail -n 20 ; exit 1)
279+
280+
# ensure current user can access everything.
281+
# later scripts assume they have recursive access to obj
272282
sudo chown -R "$USER":"$USER" ./obj
273283

284+
# Exit from this script to avoid wasting time removing disk space,
285+
# as we already have enough disk space in the alternative drive.
274286
exit 0
275287
fi
276288

277289
# ephemeral NVMe drives on AWS
278290
for dev in /dev/nvme*n1; do
291+
# check that it's a blockdev and not mounted.
279292
if [ -b "$dev" ] && [ "$(mount | grep "$dev" | wc -l)" -eq 0 ]; then
280293
echo "Found unused block device $dev, creating filesystem"
281294
sudo mkfs.ext4 -E lazy_itable_init=1,lazy_journal_init=1 "$dev"

0 commit comments

Comments
 (0)