Swappiness on Linux

Posted by Gareth Vincent on 26-Jan-2016 23:56

I would like to know if anyone has played around with the "Swappiness" parameter in Linux which allows you to tweak how often pages get swapped out to disk.  I believe the default value is 60 but many of the articles that i've looked at suggest a lower value is recommended especially for Databases and JVM processing.

All Replies

Posted by Libor Laubacher on 08-Feb-2016 15:35

Gareth, are you trying to solve an existing problem with this, or is this a general curiousity? I guess that answer would depends what's on the machine and it that machine is constrained by lack of memory. For database machine it would indeed make sense to set it lower than 60 as you don't want your database 'pages' to be swapped out of physical memory, or at least with lowest possible frequency. If you have a memory constrains and loads of batch clients or generally jobs, which for example run for a bit and then sit and way, you might want to bump out the swappiness so the memory would get swapped out more aggressively and made space for something else. I haven't played with this myself, but aware of one isssue where it's been set to 0, and the OOM (out of memory) killer on Linux went on a killing spree when the machine cames under load, so probably best not to set it to 0.

Posted by Rob Fitzpatrick on 08-Feb-2016 15:45

With respect to database shared memory, you can also look at using the -pinshm broker startup parameter to prevent shared memory pages from being paged out.

Posted by gus on 08-Feb-2016 16:02

if you are not paging, then it does not matter to what value you set it so check that first.

Posted by Gareth Vincent on 11-Feb-2016 03:12

This was just something that I came across and was wondering if anyone has implemented this on a production environment.  We do have one particular client where I've noticed excessive swapping and when monitoring this through protop I noticed that the Tomcat java process was the top process that was causing swapping along with the appserver agent processes.  When issuing a  free -m there is still plenty of available memory available.  My thinking is to reduce this value to around 20 to see if this improves %iowait time on the box.  The %iowait time on the box pretty much stays between 0.00 and 5.00 but as soon as the machine starts swapping this climbs up to around 20.00 which has a noticeable impact on performance.    

Posted by Gareth Vincent on 11-Feb-2016 03:14

Thanks Rob, yes i'm aware of the -pinshm parameter but I see no swapping on the DB but rather on the java processes. Tomcat and appserver agents.

This thread is closed