Show real swap usage for each individual process

Update: the kernel patch is already in 2.6.34-rcN.

Currently, in top, the SWAP column only shows the difference between VIRT and RES:
    case P_SWP:
MKCOL(scale_num(PAGES_TO_KB(p->size - p->resident), w, s));
So currently the value is of no use.

As a matter of fact, a recent enough kernel has provided the information which is needed to calculate the swap usage for each process. It is in /proc/$PID/smaps. But using smaps may affect top's performance because you have to calculate the sum yourself.

But with this patch https://patchwork.kernel.org/patch/56929/, the kernel will keep track of each process's swap usage for you. This patch (maybe not exactly in the same shape) is already in mmotm tree (http://userweb.kernel.org/~akpm/mmotm/) 2.6.34-rcN.

However, checking the /proc/$PID/status file directly may not be a thing which people would like to do. So I decided to make a patch for ps and top. Now it seems to be working.

This is the vanilla ps:
$ ps -o m_swap,comm -e | grep firefox
- firefox

This is modified ps:
$ ./ps/ps -o m_swap,comm -e | grep firefox
2984 firefox

This is a picture showing a modified top:


The patch can be found here:
http://dev.gentoo.org/~r0bertz/per-process-swap-usage.patch

Comments

Toralf Förster said…
You're sure that the patch is in current git tree ?
B/c I've v2.6.34-rc4-156-g13bd8e4 and get this :

tfoerste@n22 ~ $ ps -o m_swap,comm -e | grep firefox
- firefox
r0bertz said…
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b084d4353ff99d824d3bc5a5c2c22c70b1fba722
Jeremy Olexa said…
Hi Zhang,
Nice contributions there, have the patches been submitted upstream so we can see them in future releases of procps ?
r0bertz said…
Yes, I have sent to procps-feedback mailing list on sf.net and the maintainer himself.

Popular posts from this blog

The diff between the original SEC complaint against Ripple and the amended one

Rippled thread cpu usage

Send $SGB (Songbird) to another wallet using a script