Skip to content

Instantly share code, notes, and snippets.

@motchang
Last active June 17, 2016 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motchang/8856dfbf96be1aabe49bdc435bb00553 to your computer and use it in GitHub Desktop.
Save motchang/8856dfbf96be1aabe49bdc435bb00553 to your computer and use it in GitHub Desktop.
mkswap
5 9 * * * root /sbin/swapoff -a && /root/bin/mkswap.sh
# http://dev.classmethod.jp/cloud/ec2linux-swap-bestpractice/
SWAPFILENAME=/swap.img
MEMSIZE=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`
if [ $MEMSIZE -lt 2097152 ]; then
SIZE=${((MEMSIZE * 2))}k
elif [ $MEMSIZE -lt 8388608 ]; then
SIZE=${MEMSIZE}k
elif [ $MEMSIZE -lt 67108864 ]; then
SIZE=${((MEMSIZE / 2))}k
else
SIZE=4194304k
fi
fallocate -l $SIZE $SWAPFILENAME && mkswap $SWAPFILENAME && swapon $SWAPFILENAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment