Wednesday, May 4, 2011

Swappiness

Swappiness, as the name suggests, affects the swapping in the Linux systems. 

Its kind of slider value. 0 means keep pages in memory as long as possible. 100 means at maximum throttle and in-between just a frequency for swapping.

The minimum value for the swappiness is 0 and the maximum is 100. The default value is 60. On the Oracle Exadata database machine it is also set to default value of 60.

Decreasing the swappiness would keep more pages in memory instead of putting them in swap space, and so those pages would occupy the memory, and in case memory is needed than on run time those pages would be swapped out, causing the overhead, but the plus side is that if those pages are accessed again, they dont have to be swapped in again, as they would already be present in the memory.

If swappiness is increased then it would swap out more aggressively, and if pages are accessed which have been swapped out, the user's interactivity will get degradation first time.

This is all relative. 

For instance, If we are observing memory shortage for the prcoess and there is lot of swapping out (so in vmstat) then we might look at increasing swappiness to swapout more to make room for more memory.

If we are observing more and more swapping in (ver frequent si in vmstat) then we could look at decreasing swappiness.

In order to play with the swappiness, you can temporarily set it by:

echo 100 > /proc/sys/vm/swappiness
and you can permanently set it in /etc/sysctl.conf

No comments: