Remove kernel tweaks while allocating swap and only allocate swap if we have more than 5GB of diskspace available
This commit is contained in:
parent
a71679c66d
commit
41c6c9c72e
|
@ -11,16 +11,19 @@ source setup/functions.sh # load our functions
|
||||||
# prevent for instance spam filtering from crashing
|
# prevent for instance spam filtering from crashing
|
||||||
|
|
||||||
# We will create a 1G file, this should be a good balance between disk usage
|
# We will create a 1G file, this should be a good balance between disk usage
|
||||||
# and buffers for the system
|
# and buffers for the system. We will only allocate this file if there is more
|
||||||
|
# than 5GB of disk space available
|
||||||
|
|
||||||
# See https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
|
# See https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
|
||||||
# for reference
|
# for reference
|
||||||
|
|
||||||
SWAP_MOUNTED=$(grep "swap" /proc/mounts)
|
SWAP_MOUNTED=$(grep "swap" /proc/mounts)
|
||||||
TOTAL_PHYSICAL_MEM=$(head -n 1 /proc/meminfo | awk '{print $2}')
|
TOTAL_PHYSICAL_MEM=$(head -n 1 /proc/meminfo | awk '{print $2}')
|
||||||
|
AVAILABLE_DISK_SPACE=$(df / --output=avail | tail -n 1)
|
||||||
if [ $TOTAL_PHYSICAL_MEM -lt 1900000 ]; then
|
if [ $TOTAL_PHYSICAL_MEM -lt 1900000 ]; then
|
||||||
if [ -z "$SWAP_MOUNTED" ]; then
|
if [ -z "$SWAP_MOUNTED" ]; then
|
||||||
if [ ! -e /swapfile ]; then
|
if [ ! -e /swapfile ]; then
|
||||||
|
if [ $AVAILABLE_DISK_SPACE -gt 5242880 ]; then
|
||||||
echo "Adding swap to the system..."
|
echo "Adding swap to the system..."
|
||||||
|
|
||||||
# Allocate and activate the swap file
|
# Allocate and activate the swap file
|
||||||
|
@ -31,15 +34,7 @@ if [ ! -e /swapfile ]; then
|
||||||
|
|
||||||
# Make sure swap is activated on boot
|
# Make sure swap is activated on boot
|
||||||
echo "/swapfile none swap sw 0 0" >> /etc/fstab
|
echo "/swapfile none swap sw 0 0" >> /etc/fstab
|
||||||
|
fi
|
||||||
# Make sure the system only swaps as a last resort
|
|
||||||
hide_output sysctl vm.swappiness=10
|
|
||||||
tools/editconf.py /etc/sysctl.conf vm.swappiness=10
|
|
||||||
|
|
||||||
# Make sure the systeem keeps the file system inodes in
|
|
||||||
# memory as long as possible
|
|
||||||
hide_output sysctl vm.vfs_cache_pressure=50
|
|
||||||
tools/editconf.py /etc/sysctl.conf vm.vfs_cache_pressure=50
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue