From a807de1145de9fafe1139854899dfe3f5112eead Mon Sep 17 00:00:00 2001 From: Manuel Montecelo Date: Fri, 21 Sep 2018 14:03:28 +0200 Subject: [PATCH] TT#11444 Enable and calculate size of swapfile Starting with the mr6.5 release we no longer set up swap partition/LV via deployment.sh (see deployment-iso commit 6a92f155). Instead, the system will now use swapfiles, which are easier for operations like changing the size dynamically or removing them completely. This change implements the configuration for a swapfile during deployment, enabled by default and with 1/2 the size of the main memory, limited between 4 and 16GB. The file itself will be created later, during the initial NGCP configuration phase. Change-Id: I09a5a77ecfed3924184fcc7c84c6b6b21dcacc98 --- templates/scripts/includes/deployment.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/templates/scripts/includes/deployment.sh b/templates/scripts/includes/deployment.sh index 1f2dd8d..c15f401 100755 --- a/templates/scripts/includes/deployment.sh +++ b/templates/scripts/includes/deployment.sh @@ -68,6 +68,9 @@ ENABLE_VM_SERVICES=false FILESYSTEM="ext4" ROOTFS_SIZE="10G" FALLBACKFS_SIZE="${ROOTFS_SIZE}" +SWAPFILE_SIZE_MB_MIN="4096" +SWAPFILE_SIZE_MB_MAX="16384" +SWAPFILE_SIZE_MB="${SWAPFILE_SIZE_MB_MIN}" SWRAID_DEVICE="/dev/md0" SWRAID_DESTROY=false GPG_KEY_SERVER="pool.sks-keyservers.net" @@ -1354,6 +1357,16 @@ ${FALLBACK_FS} /ngcp-fallback auto ro,noatime,nofail EOF fi +# TT#11444 Calculate size of swapfile +ramsize_mb="$(( $(awk '/^MemTotal:/ {print $2}' /proc/meminfo) / 1024))" +SWAPFILE_SIZE_MB="$(( ramsize_mb / 2))" +if [[ "${swapsize_mb}" -lt "${SWAPFILE_SIZE_MB_MIN}" ]]; then + SWAPFILE_SIZE_MB="${SWAPFILE_SIZE_MB_MIN}" +elif [[ "${swapsize_mb}" -gt "${SWAPFILE_SIZE_MB_MAX}" ]]; then + SWAPFILE_SIZE_MB="${SWAPFILE_SIZE_MB_MAX}" +fi +unset ramsize_mb + # get rid of automatically installed packages chroot $TARGET apt-get --purge -y autoremove @@ -1545,6 +1558,7 @@ EXTERNAL_NETMASK="${EXTERNAL_NETMASK}" ORIGIN_INSTALL_DEV="${INSTALL_DEV}" FALLBACKFS_SIZE="${FALLBACKFS_SIZE}" ROOTFS_SIZE="${ROOTFS_SIZE}" +SWAPFILE_SIZE_MB="${SWAPFILE_SIZE_MB}" EOF if "${TRUNK_VERSION}" && checkBootParam ngcpupload ; then