Check which processes are eating swap on Linux

linuxmemorymemory managementshellswap

To see some memory info I can watch it in top of through cat /proc/meminfo.
In /proc/meminfo I can see the swap usage of the whole system like this:

SwapCached:            4 kB
SwapTotal:      33460220 kB
SwapFree:       33460216 kB

But there can be I situation when almost all the swap is used (i.e. there is a too small piece of SwapFree). How can I figure out, which process(es) are eating this swap?

UPD: there is a too small piece of SwapFree basically means that there is some process(processes) which ate a lot of memory and didn't use it for a long time. I need to find such processes.

Best Answer

  1. Run top
  2. Press f to select displayed fields
  3. Navigate down to SWAP using arrow keys
  4. Hit Space - SWAP will become preceded by asterisk *
  5. Press right arrow key - this will allow you to move SWAP to a convenient place in the listing, for example between %MEM and TIME+
  6. Press q to return to top view

Step 5 isn't necessary, just convenience - without it SWAP will be showing up as the last entry of the list, after COMMAND.

Related Question