How to check if Linux is swapping memory in and out?

My Linux server has lots of free RAM but it is still using swap. Should I be worried? Not really. What you should be more worried about is when your server is constantly swapping in and out.

How do I check that?

[root@rtfmp ~]# vmstat 5 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 1589660 182012 996316    0    0     5     5   56   71  0  0 99  0  0
 0  0      0 1589628 182012 996316    0    0     0     4   46   54  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     0   48   58  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     0   45   55  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     1   51   58  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     0   50   55  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     0   49   58  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     0   48   53  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     0   49   58  0  0 100  0  0
 0  0      0 1589628 182012 996316    0    0     0     0   48   54  0  0 100  0  0

I ran vmstat every 5 seconds, 10 times. Looking at the si and so fields, there is no swapping activity.

Even with a large RAM, you still need swap.

The casual reader1 may think that with a sufficient amount of memory, swap is unnecessary but this brings us to the second reason. A significant
number of the pages referenced by a process early in its life may only be used for initialisation and then never used again. It is better to swap out those pages and create more disk buffers than leave them resident and unused.
via Swap Management [kernel.org]

Another good read on swap from Linux.com: All about Linux swap space

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s