Linux Tips & Tricks

Reduce the swappiness of your system

After installing Linux with the standard partitioning option, you will notice that there is a partition created used for swap. This "swap space" is created on your hard drive and is set with at least twice the amount of your physical system memory (RAM). Swap can be referred to as virtual memory existing besides your physical memory. This swap will be used when the amount of RAM memory is filled up. If this occurs, your system will then transfer parts, also called pages, of RAM into swap. However, using swap will be slower than using RAM since swap is located on your hard drive and discs are by default slower than RAM.
 
Reducing swappiness can help speeding up your system. swappiness is a parameter of the Linux kernel which defines how much and how often Linux is copying memory pages from RAM to swap. The default parameter for swappiness is set to 60, which is fine if you are running a server. But for normal users this value can be too high. The higher the value, the more aggressively the Linux kernel will swap.
 
Here's how to reduce the swappiness permanent. First is it good to know the default parameter set by the kernel. This can be checked by using a terminal command. Open your (default) terminal and type the following terminal command: cat /proc/sys/vm/swappiness
The output of this command shows you the current (default) swap tendency. The value should be 60
 
Now open your (default) file manager and navigate to : /etc/sysctl.conf. This file is a textual configuration file and can be edited only as root. To edit the file, right click the file and select open as root. At the bottom of this file add the following line: vm.swappiness=10
With the value set to 10 swap will be used much lesser in favour of the I/O cache which can be evicted much sooner in favour of (system) processes.
 
NOTE:
For systems with a SSD drive, the value of swappiness can be set to 1 (one) independently of the amount of available system memory (RAM). This will extend the lifespan of your SSD drive if you have a swap partition or swap file on your SSD drive.
 
Setting swappiness value to 0 (zero) means that the Linux kernel will try to avoid swap as much as possible and will use mainly all available RAM. It is not recommended to set the swap value to 0 (zero), especially on systems with low memory (RAM) since RAM will used until your system is low on memory.
Maak simpel je website Eigen site maken