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
This commit is contained in:
Jesse Pretorius 2015-04-09 11:13:43 +01:00
parent 4c4fbe25c3
commit 8a12fee9d3
2 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -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