Alexa metrics
Live Chat

Welcome to UKFast, do you have a question? Our hosting experts have the answers.

Chat Now
Sarah UKFast | Account Manager

Q&A: What does the swappiness parameter actually do?

27 February 2012 by Pingu

The first in a series of technical ‘question and answer’ guest posts written by one of the UKFast Linux aficionados
technical answers from Linux expert
I’ve seen a lot of people posting subjective explanations of what this does. Here is hopefully a more full answer.

In the split LRU on post 2.6.28 Linux, swappiness is a multiplier used to arbitrarily modify the fraction that is calculated determining the pressure built up in both LRUs.

So, for example on a system with no free memory left,  the value of the existing memory you have is measured based on of the rate of how much memory is listed as ‘Active’ and the rate of how often pages are promoted to active after falling into the inactive list.

An LRU with many promotions/demotions of pages between active and inactive is in a lot of use.

Typically file-backed storage is cheaper and safer to evict when your running out of memory and automatically is given a modifier of 200 (this makes file-backed memory 200 times more worthless than swap-backed memory (which has a value of 0) when it multiplies this fraction.

What swappiness does is modify this value by deducting the swappiness number you gave (default 60) to file memory and adding the swappiness value you gave as a multiplier to anon memory. Thus, the default swappiness leaves you with anonymous memory being 80 times more valuable than file memory (200-60 for file, 0+60 for anon).

Therfore on a typical Linux system that has used up all its memory, page cache would have to be 80 TIMES more active than anonymous memory for anonymous memory to be swapped out in favour of page cache.

If you set swappiness to 100 this gives anon a modifier of 100 and file memory a modifier of 100 (200 – 100) leaving both LRUs equally weighted. Thus on a file-heavy system that wants page cache providing the anon memory is not as active as page cache then anon memory will be swapped to disk to make space for extra page cache.