What is using my Linux swap space?

13 November,2018 by Tom Collins

Question:  I'm familiar with how to monitor swap space usage for processes.    There is more detail about the methods I've adopted for using vmstat to check swap in and swap out on Linux swap space and DB2 . How can I check what is currently in the Linux wasp space ?


Answer: Sometimes out of curiosity I like to check what is consuming Linux swap space on a server . Various security type scans always appear to abound on servers and I like to differentiate between ad- hoc , regular processes.    The more relevant information you've got - allows better decision making.

I use this  little script - which lists out all the processes and the swap usage.  


for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
        PID=`echo $DIR | cut -d / -f 3`
        PROGNAME=`ps -p $PID -o comm --no-headers`
        for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
                let SUM=$SUM+$SWAP
        echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"

echo "Overall swap used: $OVERALL"

 Thank you to Erik Ljungstrom for the script

Author: Rambler(http://www.dba-db2.com)


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on What is using my Linux swap space?

Comments are moderated, and will not appear until the author has approved them.

dba-db2.com | DB2 Performance Tuning | DBA DB2:Everything | FAQ | Contact | Copyright