Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
top (per the man page) calculates SWAP to be VIRTUAL - PHYSICAL ram usage. Not entirely accurate from my experiments. – lornix Nov 9 '11 at 23:29

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.

share|improve this answer
I don't think shared libraries should be count as swap, because when system start-up, no swap use but there are many shared libraries already loaded. Anyway, I see that my system use about 9GB of swap partition, I just want to find out which process used most of swap(exclude share libraries, memory map file...) – secmask Jun 21 '11 at 10:28

Parsing the /proc subdirectory works:

As a bash script:

for PROCESS in /proc/*/; do
  swapused=$(awk 'BEGIN { total = 0 } /^Swap:[[:blank:]]*[1-9]/ { total = total + $2 } END { print total }' ${PROCESS}/smaps 2>/dev/null || echo 0)
  if [ $swapused -gt 0 ]; then
    /bin/echo -e "${swapused}k\t$(cat ${PROCESS}/cmdline)"

Output could be sorted Hi-Lo by piping to sort:

{blah}| sort -rn

Of course, rewrite this in your favorite language-of-the-week as you desire. My Awk-fu is not strong.


# show swap used by processes
(for PROCESS in /proc/*/; do
  swapused=$(awk 'BEGIN { total = 0 } /^Swap:[[:blank:]]*[1-9]/ { total = total + $2 } END { print total }' ${PROCESS}/smaps 2>/dev/null || echo 0)
  if [ $swapused -gt 0 ]; then
    /bin/echo -e "${swapused}k\t$(cat ${PROCESS}/cmdline)"
done ) | sort -nr
share|improve this answer
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .