Oh noes! Your monitoring just alerted you that a server is running low on swap! How can you find what is using the most swap space? Well top
will tell you what is using the most memory, but not which process is using the most swap.
And with things like docker
and kubernetes
implementing cgroups
to limit the RAM usage of things, you might have plenty of free memory and still run into swap issues. (protip: disable swap if using kubernetes
). So how can you find out? Like this:
for file in /proc/*/status
do
echo -n "$file "
awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file
done | sort -k 3 -n -r | less
This will dig through all the processes on the system and sort them by VmSwap usage, making it easy to find the pid and process binary eating all your swap space.