Skip to content

Instantly share code, notes, and snippets.

@montgomerykern
Created March 2, 2016 00:19
Show Gist options
  • Save montgomerykern/c0051602283b10f39154 to your computer and use it in GitHub Desktop.
Save montgomerykern/c0051602283b10f39154 to your computer and use it in GitHub Desktop.
Set up a 1 GB swap file
Adding a swap file gives Discourse some extra breathing room during memory-intensive operations. 1GB swap should suffice, though if you are attempting the minimum memory configuration you should set up a 2GB swap.
In the shell you have opened to your droplet, do the following:
Create an empty swapfile
sudo install -o root -g root -m 0600 /dev/null /swapfile
write out a 1 GB file named 'swapfile'
dd if=/dev/zero of=/swapfile bs=1k count=1024k
if you want it to be 2 GB
dd if=/dev/zero of=/swapfile bs=1k count=2048k
tell linux this is the swap file:
mkswap /swapfile
Activate it
swapon /swapfile
Add it to the file system table so its there after reboot:
echo "/swapfile swap swap auto 0 0" | sudo tee -a /etc/fstab
Set the swappiness to 10 so its only uses as an emergency buffer
sudo sysctl -w vm.swappiness=10
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
The whole thing as a single copy and pastable script that creates a 2GB swapfile:
//////////////////////////////////////////////////////////
sudo install -o root -g root -m 0600 /dev/null /swapfile
dd if=/dev/zero of=/swapfile bs=1k count=2048k
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap auto 0 0" | sudo tee -a /etc/fstab
sudo sysctl -w vm.swappiness=10
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment