Who’s eating my swap?

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s