Do I have enough ram

From PrgmrWiki

Swap used isn't a problem (until you are out of ram.) but putting data into swap or taking data out of swap is a problem. Data that sits in swap and isn't accessed is not a problem, it just means that some program on the system claimed more ram than it really needed.


(if that program suddenly needs a lot of the swapped out data, then you have a slowdown. But that slowdown will be manifested as a high iowait) You can tell how much data the linux system is moving in and out of swap using \ vmstat:

$ vmstat 2
 procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
  r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
  0  0    160 10716088 416652 635048    0    0    11     7    0     1  0  0 99 0
  0  0    160 10715960 416656 635044    0    0     0    42 1020    28  0  0 100 0

Look at the swap .si. and .so. values. If si and so (swap in and swap out) are zero, and if you aren't running out of memory, then swap isn't a problem. The swapin and swapout values indicate a problem if they are large (and / or if your iowait is high. Note, if si and so are consistently zero and top reports high iowait, the problem is something other than swap.)

How high is high? Uh, I like to see mostly zeros, but really the alarm here is the iowait. If iowait is low, the swapping isn't causing problems. Don't worry about it. If iowait is a significant portion of cpu time and you have non-zero si and so vaues in vmstat, you can say that swapping is hurting performance.

to see iowait, run top

 top - 14:34:05 up 147 days,  3:18, 11 users,  load average: 0.00, 0.01, 0.00
 Tasks: 143 total,   1 running, 142 sleeping,   0 stopped,   0 zombie
 Cpu(s):  0.1% us,  0.1% sy,  0.0% ni, 99.8% id,  0.1% wa,  0.0% hi,  0.0% si
 Mem:  12196892k total,  1480964k used, 10715928k free,   416092k buffers
 Swap:  1052248k total,      160k used,  1052088k free,   635088k cached

The line we are interested in is Cpu(s): us stands for user, sy stands for system, ni stands for nice, id stants for idle, wa stands for iowait, hi stands for hardware interrupts, si stands for software interrupts.

The value I really want to direct your attention to is wa, or iowait. That is how much of your CPU time is wasted while waiting for IO. If swap is causing a problem, it is manifested in a high iowait (note, other things can cause high iowait as well, which is why I also use that vmstat command)

The 'sysstat' package can collect useful resource statistics over time and can be used to match iowaits with swap paging. The following script will output four columns of time %iowait swapin swapout.

# join <(sar -u) <(sar -W) |sed 's,[A|P]M ,,g;s,/s,,g' \
  |tr " " "\t" |awk '{print $1"\t"$6"\t"$9"\t"$10}'