leah blogs

July 2013

05jul2013 · Summer of Scripts: swaptop

A good start to debug various slowdowns in programs is to analyze virtual memory usage, especially on machines with low amounts of RAM.

I wrote swaptop to calculate which processes use swap, and how much swapped:

% swaptop
  293240  hotot 29421
  140880  firefox 26337
   90760  evince 1856
   84472  skype 1674
...

It shows kbytes of swap used by the process and its pid.

Since some kernel version the swap usage is presented directly in /proc/$$/status, which makes the script pretty trivial. But before that, you had to calculate swap usage by adding up swapped pages from /proc/$$/smaps, which makes the script a bit slow on such old kernels.

NP: Die Schnitter—Aderlass

Copyright © 2004–2022