I have an ubuntu vps running that has about 300MB of memory, of which only 20% or less is free right now ...
My question is, how can I figure out what particular program I'm running that is causing it to swap so much?
Asked
Active
Viewed 1.1k times
4
![](../../users/profiles/17676.webp)
trustfundbaby
- 205
- 2
- 3
- 9
4 Answers
10
To find out the amount of swap space used by every process, run top
(not htop
), press 'f' to select columns (f for fields) to display, press 'p' to add swap to display, press 'o' to sort the table (o for order by) and press 'p' again to order by swap usage.
-
That was exactly what i needed ... If only i could figure out how to accomplish this in htop. – trustfundbaby Apr 14 '10 at 07:48
-
Also, to sort I had to use shift+o and shift+p – trustfundbaby Apr 14 '10 at 07:54
-
1In htop, you use the "F" Keys to sort. See the line at the very bottom of the screen. – Antoine Benkemoun Apr 15 '10 at 07:09
-
1The SWAP column and thus this answer is mesleading. For an explanation see https://hisham.hm/htop/index.php?page=faq – geek-merlin Nov 19 '17 at 15:42
-
1This seems to be out of date. `p` has no effect, step-by-step instructions that worked 20 Sept 2021 shown [here](https://superuser.com/questions/1677225/check-which-processes-are-eating-swap-on-linux/1677265) – Peregrino69 Sep 20 '21 at 18:02
2
start with running
top
and pressing M [ shift+m ].
you will get process list sorted by mem consumption.
![](../../users/profiles/2413.webp)
pQd
- 29,561
- 5
- 64
- 106
1
smem is a bit harder to use than top, but offers good information. You could start with with sudo smem -s uss -r -k
which will output:
PID User Command Swap USS PSS RSS
12345 spam /usr/lib/jvm/java-6-sun/bin 0 620.9M 0 626.5M
98765 eggs /usr/bin/java -Xmx1500m -XX 0 544.2M 0 549.9M
You might also want to check out this lwn.net article, which explains the difference between RSS, PSS and USS.
![](../../users/profiles/40429.webp)
miki
- 176
- 3
0
Another option is htop
, which has better output in some cases.
![](../../users/profiles/28400.webp)
Skyhawk
- 14,149
- 3
- 52
- 95
![](../../users/profiles/37899.webp)
The Unix Janitor
- 2,388
- 14
- 13
-
I'm already using htop ... can't figure out how to see the amount of swap each process is using. – trustfundbaby Apr 14 '10 at 00:36
-
2@user37899 You should at least check that it works, if you don't say exactly how, before suggesting a solution – Prof. Moriarty Apr 14 '10 at 08:17