Skip to content

Instantly share code, notes, and snippets.

@Panthro
Last active March 14, 2019 15:39
Show Gist options
  • Save Panthro/44bb6e67aad2a3eec4cc to your computer and use it in GitHub Desktop.
Save Panthro/44bb6e67aad2a3eec4cc to your computer and use it in GitHub Desktop.
enable swap (4GB) and tweak it for a server
#Allocate the file
fallocate -l 4G /swapfile
#Give right permissions
chmod 600 /swapfile
#make it a swap file
mkswap /swapfile
#turn swap on
swapon /swapfile
#mount it at every boot
echo "/swapfile none swap sw 0 0" >> /etc/fstab
#tweak cache clean pressure
sysctl vm.vfs_cache_pressure=50
echo "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf
#change swappiness to 10% (When it's send to swap)
sysctl vm.swappiness=10
echo "vm.swappiness=10" >> /etc/sysctl.conf
@Panthro
Copy link
Author

Panthro commented Jul 30, 2015

To download it and execute in on line

wget -q -O - https://gist.githubusercontent.com/Panthro/44bb6e67aad2a3eec4cc/raw/2d9bc5e1a420eb79636f01b8d981230aab0454ac/enable-swap.sh | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment