From 0d7c02f1327ddac3968e7e5d6a32a1ad3a5223df Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Mon, 17 May 2021 15:03:05 -0700 Subject: [PATCH] Better swap alignment We ran into this when fixing the zuul02 swap partition. Essentially parted complained that our alignments weren't optimal. After some googling the Internet said that using multiples of 8 tends to be safe. We shifted the offset from 1MB to 8MB to start the partition and the warnings went away. Add this change into make_swap.sh to automate this for future servers. Change-Id: Iad3ef40cf2c1e064482d49bd722c3de4354ec74d --- launch/make_swap.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/launch/make_swap.sh b/launch/make_swap.sh index 97b5a5dc9c..493dba6789 100644 --- a/launch/make_swap.sh +++ b/launch/make_swap.sh @@ -24,8 +24,10 @@ if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then SWAPFILE=/swapfile MEMKB=`grep MemTotal /proc/meminfo | awk '{print $2; }'` # Use the nearest power of two in MB as the swap size. + # We also shift by 8MB to start the partitions as apparently + # parted and linux prefer things aligned on multiples of 8. # This ensures that the partitions below are aligned properly. - MEM=`python3 -c "import math ; print(min(2**int(round(math.log($MEMKB/1024, 2))),8192))"` + MEM=`python3 -c "import math ; print(min(2**int(round(math.log($MEMKB/1024, 2))),8192) + 8)"` # Avoid using config drive device for swap if [ -n "$DEV" ] && ! blkid | grep $DEV | grep TYPE ; then @@ -37,7 +39,7 @@ if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then parted ${DEV} --script -- \ mklabel msdos \ - mkpart primary linux-swap 1 ${MEM} \ + mkpart primary linux-swap 8 ${MEM} \ mkpart primary ext2 ${MEM} -1 sync # We are only interested in scanning $DEV, not all block devices