From 8a12fee9d3e765d1812cb7aa8c914069965badf9 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Thu, 9 Apr 2015 11:13:43 +0100 Subject: [PATCH] Adjust AIO swap size to 4G/8G, depending on RAM amount The AIO setup used for the commit checks in the gate is highly resource constrained. Currently the swap space available is 1GB and the RAM available is 8GB. The swap size would be better set to 4G if the RAM amount is 8GB or less, or 8G if the RAM amount is more than 8GB. The patch switches from using dd to using fallocate for the thick loopback file creation in order to prevent memory exhaustion when trying to create files that are larger than the available memory. Change-Id: I9cdb145780fb867b933890111f642a48ed7add70 Closes-Bug: #1442028 --- scripts/bootstrap-aio.sh | 8 +++++++- scripts/scripts-library.sh | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/bootstrap-aio.sh b/scripts/bootstrap-aio.sh index 173496c71e..fff548b25a 100755 --- a/scripts/bootstrap-aio.sh +++ b/scripts/bootstrap-aio.sh @@ -167,7 +167,13 @@ mount -a || true # Build the loopback drive for swap to use if [ ! "$(swapon -s | grep -v Filename)" ]; then - loopback_create "/opt/swap.img" 1024M thick swap + memory_kb=$(awk '/MemTotal/ {print $2}' /proc/meminfo) + if [ "${memory_kb}" -lt "8388608" ]; then + swap_size="4G" + else + swap_size="8G" + fi + loopback_create "/opt/swap.img" ${swap_size} thick swap # Ensure swap will be used on the host if [ ! $(sysctl vm.swappiness | awk '{print $3}') == "10" ];then sysctl -w vm.swappiness=10 | tee -a /etc/sysctl.conf diff --git a/scripts/scripts-library.sh b/scripts/scripts-library.sh index 9bfb7e2827..2b1c142d9b 100755 --- a/scripts/scripts-library.sh +++ b/scripts/scripts-library.sh @@ -142,7 +142,7 @@ function loopback_create() { if [ "${LOOP_FILE_TYPE}" = "thin" ]; then truncate -s ${LOOP_FILESIZE} ${LOOP_FILENAME} elif [ "${LOOP_FILE_TYPE}" = "thick" ]; then - dd if=/dev/zero of=${LOOP_FILENAME} bs=${LOOP_FILESIZE} count=1 + fallocate -l ${LOOP_FILESIZE} ${LOOP_FILENAME} else exit_fail 'No valid option ${LOOP_FILE_TYPE} found.' fi