[CentOS] Swap Considerations

Feizhou feizhou at graffiti.net
Thu Mar 1 15:17:18 UTC 2007

>> I think monitoring swap comes down to two things: strange memory use and
>> whether there is a lot of stuff going in and out of swap and the amount
>> of data. For I/O intensive servers, you don't want to see swap being
>> used so monitoring swap usage can help to fine tune no. of processes or
>> whatever to keep the box from using swap if it does use swap.
> What your really saying, and this is a very fair answer, is to monitor
> it on systems with different loads and learn what it should look like
> when things are well, such that I can determine what is the norm, and
> thus with that defination identify aberrations.

No. You do not have to compare different systems. See below.

>> So I personally only care about swap if using it gets in the way
>> (usually servers) and if my box does not have enough RAM for the
>> applications I have to open where disk I/O is not critical (usually
>> desktops)
> Presently most of our servers have between 4 and 8 gigs of ram, and
> our distro (a one off from CentOS) blankedly creates a 2 gig swap area
> on top of lvm on top of a raid 1 md device.  But with all the
> applications we write not a one of them do we ever want to actually
> use swap, we mainly have it there just in case.  What we never did was
> the research on our own to figure out what real threshholds exist such
> that we could monitor and alarm when thresholds were crossed.  On
> Solaris we were given very specific things to look for by Sun, so we
> were taken aback when RedHat (whom we were paying too) did not give
> such specific instructions.

It comes down to whether the use of swap has a significant effect on 
your operations. You can tell the kernel to not ever use swap unless 
absolutely necessary: swappiness = 0. Normally it is set at 60 (range is 
from 0 - 100). Let me explain how I would handle swap.

Take a case of mail servers with hundreds of processes that only have 
1GB of RAM and a pair of disks. I would use vmstat to check the 'si so' 
columns to see whether the box is swapping. Positive figures in both 
columns indicates use of swap and if I see constant reports of positive 
figures for these two columns, I start reducing the number of processes 
allowed to run to increase performance. This is how I identify active 
swap usage as opposed to swap in use. Swap in use is not the same as 
active swap usage. I could get maybe tens or even hundreds of megabytes 
being reported in swap but if vmstat 'si so' columns report zeros, I 
don't worry about its effect on disk i/o because there is none. However, 
if the amount of swap in use continues to grow over time, I start 
looking for memory leaks.

More information about the CentOS mailing list