Skip to main content

Swap

Clear swap file

1 - Disable Swap

 sudo swapoff -a

2 - Re-enable swap

 sudo swapon -a


View Swap usage

 sudo smem -rs swap

 

Swap config

Update swappiness config

 sudo bash -c "echo 'vm.swappiness = 1' >> /etc/sysctl.conf"

Update value immediately

 sysctl vm.swappiness=1

 

About swap

Swappiness in Linux is a kernel parameter that controls how aggressively the system moves inactive pages from RAM to the swap space on disk. The swappiness value is represented as a percentage from 0 to 100, and it affects the balance between using physical RAM and swap space. Lowering swappiness can help improve performance in certain scenarios, particularly when you have a decent amount of physical memory available.

How Swappiness Works
Low swappiness values (0–30): The kernel avoids swapping as much as possible and will only swap when RAM is close to being fully utilized. This setting is ideal when performance is prioritized and there’s enough RAM.

High swappiness values (60–100): The kernel uses swap space more aggressively, even when RAM is available. This setting can be helpful on systems with limited RAM or on systems running many applications simultaneously.

The default value for swappiness on most Linux systems is 60.