Skip to content

Instantly share code, notes, and snippets.

@viniciusdaniel
Forked from vpnwall-services/SWAP-101.md
Created September 26, 2023 14:33
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 viniciusdaniel/12492a5320521d6aeaeaab37bf02044d to your computer and use it in GitHub Desktop.
Save viniciusdaniel/12492a5320521d6aeaeaab37bf02044d to your computer and use it in GitHub Desktop.
[SWAP 101] Swap 101 #linux #swap #101

SWAP 101

  • Allocate swap sudo fallocate -l 1G /swapfile

  • Alternate allocation sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576

  • Perms sudo chmod 600 /swapfile

  • Setup swap sudo mkswap /swapfile

  • Enable swap sudo swapon /swapfile

  • /etc/fstab entry /swapfile swap swap defaults 0 0

  • Show swap sudo swapon --show

  • Adjust swapiness #60 good for all, put lower value for production servers cat /proc/sys/vm/swappiness

  • Setup swapiness sudo sysctl vm.swappiness=10

  • /etc/sysctl.conf vm.swappiness=10

  • Remove swap sudo swapoff -v /swapfile

  • Delete swap file sudo rm /swapfile

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