• Edit
  • Delete

Ubuntu Swap Cheatsheet

  • swapon -s
    • show swap info
  • swapoff -a
    • turn off all swap devices
  • swapon -a
    • turn on all swap devices

Swappiness

  • cat /proc/sys/vm/swappiness

    • 60 = default, ~ use swap when half of ram is used

    • 10 = use swap when only 10% ram free

    • 0 = use swap only when absoltely necessary

  • sudo vi /etc/sysctl.conf

    • vm.swappiness = 10
  • sudo sysctl vm.swappiness=10

Create Swapfile

  • sudo fallocate -l 4G /swapfile

  • sudo chmod 600 /swapfile

  • sudo mkswap /swapfile

  • sudo swapon /swapfile

  • sudo vi /etc/fstab

    • /swapfile swap swap defaults 0 0
  • sudo swapon --show