1

This answer provides a good script that display how much swap each process uses: How to find out which processes are swapping in linux?

However:

petr@eliska:~$ free
             total       used       free     shared    buffers     cached
Mem:       3114288    2930040     184248          0         76    1809800
-/+ buffers/cache:    1120164    1994124
Swap:      6287356     977712    5309644

Note: 977MB of swap area is used, when I run the script I linked on top of this question, I see

PID=1 swapped 76 KB (init)
PID=369 swapped 404 KB (udevd)
PID=463 swapped 356 KB (udevd)
PID=464 swapped 348 KB (udevd)
PID=1804 swapped 1556 KB (dhclient)
PID=1859 swapped 168 KB (rpcbind)
PID=1890 swapped 408 KB (rpc.statd)
PID=1904 swapped 184 KB (rpc.idmapd)
PID=2240 swapped 348 KB (rsyslogd)
PID=2304 swapped 108 KB (acpid)
PID=2452 swapped 112 KB (atd)
PID=2529 swapped 136 KB (dbus-daemon)
PID=2544 swapped 312 KB (ntpd)
PID=2779 swapped 364 KB (memcached)
PID=2786 swapped 332 KB (sshd)
PID=2859 swapped 128 KB (cron)
PID=2878 swapped 300 KB (exim4)
PID=2904 swapped 132 KB (getty)
PID=2905 swapped 128 KB (getty)
PID=2906 swapped 124 KB (getty)
PID=2907 swapped 128 KB (getty)
PID=2908 swapped 128 KB (getty)
PID=2909 swapped 128 KB (getty)
PID=2918 swapped 744 KB (console-kit-dae)
PID=2985 swapped 156 KB (polkitd)
PID=3243 swapped 3228 KB (node)
PID=3246 swapped 1688 KB (node)
PID=3247 swapped 2580 KB (node)
PID=3249 swapped 2160 KB (node)
PID=3250 swapped 2336 KB (node)
PID=3251 swapped 1900 KB (node)
PID=3686 swapped 16 KB (oracle)
PID=16915 swapped 16 KB (oracle)
PID=29843 swapped 204 KB (java)
PID=29868 swapped 2512 KB (emagent)
PID=29925 swapped 1060 KB (oracle)
Overall swap used: 25008 KB

How do I analyze the swap area so that I can see what these (977 - 25)MB are used for? Is there any way to read how the swap is used and which parts of swap are used for what?

Community
  • 1
  • 1
Petr
  • 13,747
  • 20
  • 89
  • 144
  • 2
    Why do you ask and why do you care? What only matters is how much swap is used and by which processes.... I don't understand why you want to know which part of swap space is used by which processes? (and that might not even have a clear answer, e.g. because of [tmpfs](http://en.wikipedia.org/wiki/Tmpfs) ...) – Basile Starynkevitch Jan 24 '14 at 12:47
  • @BasileStarynkevitch I am not asking which part of swap is used by which process but what is which part of swap used for (if any process at all). As you can see in my example listing there is more than 900MB of swap space used by NO PROCESS AT ALL according to the output of script. That is why I am curious what kernel needs this swap for. – Petr Jan 27 '14 at 15:48
  • I mean, in listing you can see that all processes together use only 25MB of swap space. But free display that 977MB of swap is being used. So what is using these 952MB? – Petr Jan 27 '14 at 15:51

1 Answers1

0

Try following

cat /proc/PID/status | grep VmSwap

this script will display swap usage of all processes. (you can use grep to find any exact matches

#!/bin/bash

for file in /proc/*/status ;
do
awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file;
done
Tharanga Abeyseela
  • 3,255
  • 4
  • 33
  • 45