Add more swap with loop dev

In upstream, devstack-gate will ensure there is at least 8GB swap.
We can't actually set 8GB swap as there is no enough disk space.
And actually we have enough memory for CI jobs at the moment. So
let's make a thin file and use loop dev to make the swap. Even
it will use swap really, it should happend after we remove the
cached directory - /opt/git. So it won't be a problem at all.

Change-Id: If16152b9d2abfa71da7726202682641888a54637
This commit is contained in:
jianghua wang 2017-03-03 15:10:31 +08:00
parent a9d61c4edc
commit 41909348ea

View File

@ -25,10 +25,28 @@ function trapexit {
# Do not use 'exit' - bash will preserve the status
}
function ensure_swap {
# Add more swap by using loop device as upstream devstack-gate will ensure
# there are at leat 8GB swap. But actually we should have enough memory
# for CI jobs at the moment.
SWAPSIZE=8192
swapcurrent=$(( $(grep SwapTotal /proc/meminfo | awk '{ print $2; }') / 1024 ))
if [[ $swapcurrent -lt $SWAPSIZE ]]; then
swapdiff=$(( $SWAPSIZE - $swapcurrent ))
SWAP_FILE=/root/.swapfile
sudo truncate -s ${swapdiff}M ${SWAP_FILE}
SWAP_DEV=$(sudo losetup -f --show ${SWAP_FILE})
sudo mkswap ${SWAP_DEV}
sudo swapon ${SWAP_DEV}
fi
}
trap trapexit EXIT
set -ex
ensure_swap
#REPLACE_ENV
export PROJECTS="openstack/os-xenapi $PROJECTS"