amuck-landowner

Linux swappiness - how do you set optimal value?

ICPH

Member
Hello,

how do You set proper value of swappiness for the Linux server?

i mean how to meter the performance before/after change (its a webserver) to find optimal value..

-------

show current value:

cat /proc/sys/vm/swappiness

Set temporary new value

sysctl -w vm.swappiness=0

set permanently new value:

add it into /etc/sysctl.conf
 
Last edited by a moderator:

drmike

100% Tier-1 Gogent
I've long ran with swappiness at 0.

Unsure what the other values are intending with swapping out to disk.  Disk is slow. Even SSD based stuff.

Long considered the overly aggressive caching in Linux, especially in desktop use to be rather broken/aggressive/annoying.
 

MannDude

Just a dude
vpsBoard Founder
Moderator
If I use less than 50% of my allocated RAM on a machine, which I normally do even during peak times, I set it to zero or 10 at the highest.
 

zzrok

New Member
I much prefer this StackExchange topic over the Ubuntu topic: http://unix.stackexchange.com/questions/88693/why-is-swappiness-set-to-60-by-default.

The Ubuntu topic misrepresents how swapping works.  It doesn't work simply by amount of RAM consumed; the LRU algorithm makes it more nuanced than that.

Take note of this quote from the answer:

As with any performance parameter, adjusting vm.swappiness should be based on benchmark data comparable to real workloads, not just a gut feeling.
The correct way to tune swappiness is to leave it at the default value and setup server monitoring that tells you when pages are actually being moved in to and out of swap.  Every time pages are moved from RAM to swap (swap out) is a time you effectively get extra memory for free.  This is when unused code and data in you programs is being moved out of RAM, making more space for used code, data, and file caching.  Only worry about tweaking swappiness when you start seeing a significant amount of pages moving from swap into RAM (swap in).  At that point, tweaking may not help much unless you are just on the edge of not having enough RAM.  You need to make sure any programs that manage their own memory aren't trying to use too much (like MySQL innodb cache) or you may just plain need more memory.

TL;DR: Leave swappiness alone. Monitor swap in and swap out.  Don't worry about swap out.  Worry about swap in.

Edit: improve description of what to do about swap in and add TL;DR.
 
Last edited by a moderator:

zzrok

New Member

drmike

100% Tier-1 Gogent

tonyg

New Member
For servers my general rule is the less RAM the greater the need for swap, but I never disable it.

I typically follow the below:

256MB RAM or less  =  60 (Default Value)

512MB to 1GB  RAM =  40

Above 1GB RAM       =  30
 

splitice

Just a little bit crazy...
Verified Provider
Your hard drive type is a very important factor, you don't want to be killing SSD's with swapping if you dont have to be.

I usually use a value of 1 on SSD servers, or when there is a normally excessive amount of ram. Its based on limited testing and experiences with the default values.

Values between 10 and 30 are probably sane in most other cases (dedicated servers).
 
Top
amuck-landowner