Linux Swappiness and SSD usage

swappiness

Swappiness is a Linux kernel parameter that determines the balance between keeping pages in physical memory (RAM) and swapping them out to swap space HDD/SSD. Swap space is a portion of the hard disk used as an extension of RAM when the system runs out of physical memory. SSD hard drives have limited write cycles and can wear out with excessive writes. Modern SSD’s has a kind of balancer build in to minimise wear and prolong the life span of the SSD.

To lower the swappiness on Linux, you need to adjust the kernel parameter that controls how aggressively the system uses swap space. Swappiness is a value between 0 and 100, where:

– 0: The kernel avoids swapping as much as possible (prefers RAM).
-100: The kernel aggressively swaps processes out of RAM.

By default, most Linux systems have a swappiness value of 60. To lower it, follow these steps:

1. Check the Current Swappiness Value

Run the following command to check the current swappiness value:

cat /proc/sys/vm/swappiness

2. Temporarily Change Swappiness (Until Reboot)

To temporarily lower the swappiness value (e.g., to 10), use the `sysctl` command:

sudo sysctl vm.swappiness=10

This change will take effect immediately but will not persist after a reboot.

3. Permanently Change Swappiness

To make the change permanent, edit the `/etc/sysctl.conf` file:

1. Open the file in a text editor:

sudo nano /etc/sysctl.conf

2. Add or modify the following line at the end of the file:

vm.swappiness=10

3. Save the file and exit the editor. Press Ctrl+X then hit Y and enter.

4. Reboot the system

Check the swappiness value again to confirm the change:

Notes:

– A lower swappiness value (e.g., 10) is recommended for systems with sufficient RAM to prioritize performance. – If you set swappiness to 0, the kernel will still use swap in extreme cases (e.g., when RAM is completely full).

Similar Posts

Leave a Reply