Skip to content

Swap for digitalocean droplets

Amitai Burstein edited this page Feb 7, 2016 · 2 revisions

Digital ocean ubuntu droplets are coming without a swap by default. This might cause them to crash when they run out of memory.

Fix it by adding a swap file:

# Add a 1G swap to swapless ubuntu server. (Verify with: free -m)
# Adapted from https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

sysctl vm.swappiness=10
echo vm.swappiness=10 >> /etc/sysctl.conf

sysctl vm.vfs_cache_pressure=50
echo vm.vfs_cache_pressure=50 >> /etc/sysctl.conf

free -m