Swap memory issue

Hi,

In our production box i can see the Swap space using the below command

 free
             total       used       free     shared    buffers     cached
Mem:      65963232   41041084   24922148          0     877160   35936292
-/+ buffers/cache:    4227632   61735600
Swap:      4192880    1915204    2277676

I heard in forums SWAP space should be double the size of RAM or atleast half of it.

Also with TOP command and sorted on Swap i got the below output

13554 db2inst1  18   0 5648m 473m 463m S  0.0  0.7  13:38.10 5.1g db2sysc
 1979 root      21   0 2880m 1.5g  30m S  0.0  2.4  28:39.52 1.3g java

The first two entries itself will add up above 6GB
How come one command shows the SWAP as less than 4GB and the top command show as used more than 6GB.

We had few performance issue in the prod box. trying to analyse some good practice on memory setup

uname -a
Linux XXXXXXXXXX 2.6.18-308.4.1.el5 #1 SMP Wed Mar 28 01:54:56 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

NOTE: swappiness is 60

Show the parameters of the top command you used as well as the column headings for it.

FYI: I looks like you have approx 65 GB of ram and 4GB of paging space. Most swap specifications I have ever seen depend upon the total amount of memory in the system...so it's never "always half" or "always double".

These are just thumb rules to start with. The real rule is simple, the swap should be large enough to avoid being out of swap and might be much larger with no negative effect. This is essentially unrelated to the RAM size but definitely related to the sum of the memory required by all running applications.

Top swap column shows the amount of non resident address space. It doesn't need to reside on the swap area but might simply be on memory mapped plain files.

1 Like

During the peak of our batch we will have lot of processes trying to access the resources. during this time Swap space reach 100% and even after all the process completed the swap space will not come down below 40%.
we will process nearly 100GB of data during this time, not sure how much will go through memory or not.

---------- Post updated at 09:54 AM ---------- Previous update was at 09:51 AM ----------

This is the top command result with the header and first two lines which use the most of the swap space.

top - 09:52:55 up 5 days,  3:54,  8 users,  load average: 0.07, 0.08, 0.25
Tasks: 466 total,   1 running, 465 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  65963232k total, 51535512k used, 14427720k free,   807228k buffers
Swap:  4192880k total,  2397768k used,  1795112k free, 46612976k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU SWAP %MEM    TIME+  COMMAND
13554 db2inst1  18   0 5650m 510m 497m S  0.0 5.0g  0.8  20:23.87 db2sysc
 1979 root      21   0 2880m 1.6g  29m S  0.0 1.2g  2.5  33:43.26 java

The virtual addresses add up to about 6 GB. The resident memory is about 2 GB.

If a program allocates a 5 GB array its virtual address space utilization instantly increases by 5 GB because addresses must be assigned to all 5 GB. But the OS is not stupid enough to instantly dedicate 5GB of physical memory to that array. As the program actually uses the array the OS will allocate memory page by page.

And think about a program like vim. It's a huge program with many features but most of us don't use them all. As we use features in vim, if the code is already in core, fine. Otherwise a page fault is generated and a page is read in. vim page-faults just enough stuff into core to do what we want. The rest stays on disk.

1 Like

The problem was , when our batch was running on its peak, as i told all the resources cpu, memory and swap space were reaching 100%, and finally system become unresponsive.
later we increased the swap space , and for last few days we were observing the swap space was never even reaching 1GB and RAM is steady.
Could you please explain when Swap memory will be used. Will Swap memory be used only when Ram is full..
Want to really understand whether the increase in swap space would have reduced the issues with our process

If the CPU is fully utilized, the performance slow down linearily with the extra load.
If the RAM is fully utilized, SWAP will start to be used. The performance might slow down much more intensively with the extra load, but this will really depend on the active set. There are situations where the performance won't be significantly hurt.
If the SWAP if fully utilized, applications will randomly crash.

There is a common misconception that having a large SWAP area has an adverse effect on performance. This is incorrect, having too little RAM is a serious cause of performance issues. Having too large a swap is a safe configuration.

1 Like