Linux , Swap Memory usage

Published by

Posted on June 10, 2016

running free -m , you notice the system is using swap and you are curious to know which process is usingĀ all the memory.

free -m
total used free shared buff/cache available
Mem: 2000 419 783 2 797 1380
Swap: 2047 0 2047

run the below command to see if your system actively using swap
vmstat -S M 1
Reference
use-vmstat-to-monitor-system-performance
Found this nice script courtesy of http://blog.theunixguide.com/?p=277

/usr/bin/time -v ls /etc/resolv.conf

grep Swap /proc/[1-9]*/smaps | grep -v ‘\W0 kB’


ps ax | sed "s/^ *//" > /tmp/ps_ax.output
for x in $(grep Swap /proc/[1-9]*/smaps | grep -v '\W0 kB' | tr -s ' ' | cut -d' ' -f-2 | sort -t' ' -k2 -n | tr -d ' ' | tail -10); do
swapusage=$(echo $x | cut -d: -f3)
pid=$(echo $x | cut -d/ -f3)
procname=$(cat /tmp/ps_ax.output | grep ^$pid)
echo "============================"
echo "Process : $procname"
echo "Swap usage: $swapusage kB"; done