Skip to content

Instantly share code, notes, and snippets.

@rahimnathwani
Created June 26, 2021 16:21
Show Gist options
  • Save rahimnathwani/c27a2e925d3f64dc8766aba9ca01ce3e to your computer and use it in GitHub Desktop.
Save rahimnathwani/c27a2e925d3f64dc8766aba9ca01ce3e to your computer and use it in GitHub Desktop.
# From https://xiaoxing.us/2018/09/04/creating_swap_on_lightsail/
# fallocate is instant; no point wasting time writing zeroes
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
# Activate swap on boot
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Make system use swap only when it needs it
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment