Linux – How to find out processes are using swap space

linuxmemoryswap

I have a linux server top reports about 9GB of swap used:
top

But I cannot figure where's it use swap, some google results said that top – O commad follow by p will show swap usage by process. But as shown in the above image, taking a brief sum of the SWAP column shows that > 10GB of swap is used, so where does the 9GB figure for swap usage come from?

Top reports that about 96492kb of ram is used by buffers. Is there anything I can do to utilize this, instead of using swap?

Best Answer

It is possible that multiple programs will be using the same swap area, so it will be reported twice.

There is no need to try to tell Linux to use the buffered area instead of swap--it's already very smart about what it's doing. If you're using 9gb of swap and 9gb of buffer, that's a good thing... that means Linux realizes that 9gb of stuff loaded into memory isn't being used actively, so it's more efficient to swap it to disk so that your buffer can grow larger, and improve your performance.


EDIT: If you add up all of the memory used by each process, you'll get much more than your physical RAM, too. This is due to shared libraries being used by multiple programs, as well as the way Linux handles forks--it doesn't duplicate the entire program in memory, it only duplicates the portions that differ between the two instances. In some cases, video memory can be shown as part of an X process--I think the old Voodoo3 cards did this. There may be other cases where "phantom" memory can show up in top, as well.

Related Question