What is Swappiness?

Most of Linux users that have installed a distribution before, must have noticed the existence of the “swap space” during the partitioning phase (it is usually found as /sda5). This is a dedicated space in your hard drive that is usually set to at least twice the capacity of your RAM, and along with it constitutes the total virtual memory of your system. From time to time, the Linux kernel utilizes this swap space by copying chunks from your RAM to the swap, allowing active processes that require more memory than it is physically available to run.

Swappiness is the kernel parameter that defines how much (and how often) your Linux kernel will copy RAM contents to swap. This parameter's default value is “60” and it can take anything from “0” to “100”. The higher the value of the swappiness parameter, the more aggressively your kernel will swap.

Why change it?

The default value is an one-fit-all solution that can't possibly be equally efficient in all of the individual use cases, hardware specifications and user needs. Moreover, the swappiness of a system is a primary factor that determines the overall functionality and speed performance of an OS. That said, it is very important to understand how swappiness works and how the various configurations of this element could improve the operation of your system and thus your everyday usage experience.

As RAM memory is so much larger and cheaper than it used to be in the past, there are many users nowadays that have enough memory to almost never need to use the swap file. The obvious benefit that derives from this is that no system resources are ever occupied by the swapping process and that cached files are not moved back and forth from the RAM to the swap and vise versa for no reason.

How to change it?

The swappiness parameter value is stored in a simple configuration text file located in /proc/sys/vm and is named “swappiness”. If you navigate there through the file manager, you will be able to locate the file and open it to check your system's swappiness. You can also check it or change it through the terminal (which is faster) by typing the following command: “sudo sysctl vm.swappiness=10” or whatever else between “0” and “100” instead of the value “10” that I used. To ensure that the swappiness value was correctly changed to the desired one, you simply type: “cat /proc/sys/vm/swappiness” on the terminal again and the active value will be outputted.

This change has an immediate effect in your system's operation and thus no rebooting is required. In fact, rebooting will revert the swappiness back to its default value (60). If you have thoroughly tested your desired swapping value and you found that it works reliably, you can make the change permanent by navigating to /etc/sysctl.conf which is yet another text configuration file. You may open this as root (administrator) and add the following line on the bottom to determine the swappiness: vm.swappiness=”your desire value here”. Then, save the text file and you're done!

Factors for consideration

There are some maths involved in the swappiness that should be considered when changing your settings. The parameter value set to “60” means that your kernel will swap when RAM reaches 40% capacity. Setting it to “100” means that your kernel will try to swap everything. Setting it to 10 (like I did on this tutorial) means that swap will be used when RAM is 90% full, so if you have enough RAM memory, this could be a safe option that would easily improve the performance of your system.

Some users though want the full cake and that means that they set swapping to “1” or even “0”. “1” is the minimum possible “active swapping” setting while “0” means disable swapping completely and only revert to when RAM is completely filled. While these settings can still theoretically work, testing it in low-spec systems of 2GB RAM or less may cause freezes and make the OS completely unresponsive. Generally, finding out what the golden means between overall system performance and response latency requires quite some experimentation (as always).

Share this page:

Suggested articles

14 Comment(s)

Add comment


From: JustNiz

it seems to me you'd always want to use RAM as much as possible first, So why would you ever want to set swappiness so you leave more free ram?

From: Albin

Swappiness is an important topic for server implementations of Linux, but not for normal desktop use.  There are a lot of "urban myth" recommendations for desktop, but all the serious discussions relate to servers.  The only desktop machines that will normally swap at all are very old low power units, e.g. under 1mb of RAM, where the combination of the OS and an ordinary browser is topping out the RAM.  Apart from that, any system monitor will show you that any desktop machine with normal specs isn't swapping, period.

From: some dude

Well, I certainly have more than 1MB or RAM, 2 GB, which I deem to be a somewhat "normal" spec, however in the low end, and my OS certainly swaps, sometimes approaching the partition limit. Not so much "by itself", but yes, when lots of stuff are using memory, including but not limited to web browsers.

I don't really monitor it that cautiously, but I've basically noted it always happening to some degree at least. I've also tried somewhat haphazardly several swappiness configurations. Lately I have been using "2", which still swaps. 


I think low swappiness may have the downside of every now and then frozing the system in a more dramatic manner than with more swapping, which would perhaps spread the swapping into smaller slices over time, with shorter responsivity declines.

From: JFM

Files are not wriitten to swap.  If the block is clean it is silently discarded if it is dirty it is written to the emplecament it it should occuppy in the file not to swap.



Try just try to edit a one hour 24 bit, 192000 Khz one hour audio file with audacity on a 4GB box without swap.  Even with it, it can be painful.



Because it is better to put off a fire when it is still small.  Swapping pages who are little used or perhaps will no longer be reused at all (like fo intialisation routines) when machine is under no pressure is better than swapping them when OS neeeds to free hundreds of megs of RAM


Also if swappiness is too low (or you have no swap) Linux will discard library (read/only pages) possibly having to reload them two miliseconds later.


From: JFM

@JustNiz again

Another reason for swapping is providing more space more for file caching.  It is better to swap pages that are very unfrequently unused than read and reread and reread the same block belonging to a file.

From: JustNiz

JFM Thanks for taking time to expalain. I get it now.

From: mickeypop

a simple script to capture memory usage over time and maybe plot it later can help alot to find out just how much you use and where swapping is actually needed.  Then setting the swappiness would generally have the best results. 

a simple script to show ram and swap use may help

#!/bin/bash /usr/bin/free -b | /bin/awk ' \ NR==2 { ramUsed = $3 } \ NR==4 { swapUsed = $3 } \ END { print swapUsed "\n" ramUsed "\n0\n0" } '

hope this can hepl someone



From: Dan Saint-Andre

In these days of 16+ GB of system RAM, does "twice RAM" or similar really make sense as the size of swap partitions?

As I understand things, the swap partition is important for suspend-to-RAM(SLEEP) and suspend-to-disk(HIBERNATE) operations.

From: Albin


Actually the "urban myths" I mentioned have mostly to do with reducing swappiness to 10 or whatever, to reduce something that usually isn't happening anyway.  I don't know Audacity, but most a/v media software has pretty sophisticated cache settings that can make a real difference to performance on large files, allocating various caches to a big fast hard drive, especially a separate hard drive, from the software itself doesn't require monkeying with the operating sytem settings.   

From: g joe


On my ubuntu 14.04 LTS in the /etc/sysctl.conf the vm.swappiness string is not present. Where I could set this value?


From: Tom Shailer

Great post! You can also monitor swap usage using free or top commands.

From: Anonymous

This tutorial is wrong.  It says to edit this file /etc/sysctl.conf

Not for nothing but the actual path is /etc/sysctl.d/99-sysctl.conf

You should correct that, now

From: DerekVS


/etc/sysctl.d/99-sysctl.conf is just a symlink to ../sysctl.conf, so the author is still correct.

From: Mario Tello

in which you base that theory to say that it is a percentage.


"The parameter value set to “60” means that your kernel will swap when RAM reaches 40% capacity. Setting it to “100” means that your kernel will try to swap everything. Setting it to 10 (like I did on this tutorial) means that swap will be used when RAM is 90% full, so if you have enough RAM memory, this could be a safe option that would easily improve the performance of your system."


This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase agressiveness, lower values decrease the amount of swap. A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone.


Source https://www.kernel.org/doc/Documentation/sysctl/vm.txt

Other factors influence the decision to move memory pages to swap