tags:

views:

7516

answers:

4

Under Linux, how do I find out which process is using the swap space more?

Any scripts/links appreciated..

A: 

I suppose you could get a good guess by running top and looking for active processes using a lot of memory. Doing this programatically is harder---just look at the endless debates about the Linux OOM killer heuristics.

Swapping is a function of having more memory in active use than is installed, so it is usually hard to blame it on a single process. If it is an ongoing problem, the best solution is to install more memory, or make other systemic changes.

dmckee
A: 

I don't know of any direct answer as how to find exactly what process is using the swap space, however, this link may be helpful. Another good one is over here

Also, use a good tool like htop to see which processes are using a lot of memory and how much swap overall is being used.

Jean Azzopardi
+12  A: 

Run top then press 'O' (capital letter o) followed by 'p' then 'enter'. Now processes should be sorted by their swap usage.

David Holm
From the docs, the SWAP column in top seems to just show how much swap would be necessary if the entire process was swapped out, rather than how much of the process is actually swapped at present. From what I can tell after a short search, there is no way to determine how much of each process is swapped out at the moment. The author of htop refuses to put in such a column because of this (I do see CNSWAP and NSWAP columns, but they don't seem to do anything on my machine): http://htop.sourceforge.net/index.php?page=faq
yukondude
+1  A: 

It's not entirely clear if you mean you want to find the process who has most pages swapped out or process who caused most pages to be swapped out.

For the first you may run top and order by swap (press 'Op'), for the latter you can run vmstat and look for non-zero entries for 'so'.

Ronny Vindenes