Table of Contents

SWAP / Swappiness

Swappiness defines how fast processes, more accurate their consumed RAM, is sourced out to a disk. This is only required and recommended when there's not enough RAM available. Since hard drives are thousands of times slower than RAM, it is recommended for servers to keep the swap value as low as possible due to a higher performance. In general the physical storage location should be at least a SSD, better a NVMe.

To view the current swappiness:

cat /proc/sys/vm/swappiness

To change the swappiness permanently, edit /etc/sysctl.conf:

vm.swappiness=<value>

The variable vm.swappiness can have a value between 0 and 100, higher values mean a faster “outswapping” to the disk.

Sourced from linuxize.com

Disable SWAP permanently

To disable the SWAP on Debian and some other Linux Distributions just comment out the following line in /etc/fstab:

/swapfile                                 none            swap    sw              0       0

Increase SWAP-Storage (e.g. for Raspberry Pi)

Raspberry Pis are powerful, but sometimes the amount of RAM is too low, besides RAM-compression swapping can be a helpful solution.

Change/Increade SWAP Space on Raspberry Pi OS (Debian):

Firstly turn off swap (moves everything from swap to the RAM):

sudo dphys-swapfile swapoff

Then edit the SWAP size in (size in MBytes):

sudo nano /etc/dphys-swapfile

Set size to new size of swap-ram and initialize new swap file:

sudo dphys-swapfile setup

Should produce something like this: want /var/swap=4096MByte, checking existing: deleting wrong size file (2147483648), generating swapfile … of 4096MBytes Finally turn the swap back on, there's no reboot required:

sudo dphys-swapfile swapon

If getting want /var/swap=4096MByte, restricting to config limit: 2048MBytes, checking existing: keeping it as error when running setup, check CONFMAX of /sbin/dphys-swapfile. And re-run this command.

Initially sourced from pimylifeup.com