What is using my Linux swap space?

13 November,2018 by Jack Vamvas

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.  

 

SUM=0
OVERALL=0
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 }'`
        do
                let SUM=$SUM+$SWAP
        done
        echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
        let OVERALL=$OVERALL+$SUM
        SUM=0

done
echo "Overall swap used: $OVERALL"




 Thank you to Erik Ljungstrom for the script

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

Share:

Verify your Comment

Previewing your Comment

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

Working...
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.

Working...

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