How to check the content of swap memory in Linux?
Swap usage per proccess
#!/bin/bash
set -o posix
set -u
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/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"
Problem solved:
I found out that 1372500 pages, of shared memory is swapped. Size of the page is 4096 bytes.
# ipcs -mu
------ Shared Memory Status --------
segments allocated 32
pages allocated 2752532
pages resident 1380020
pages swapped 1372500
Swap performance: 0 attempts 0 successes
# getconf PAGESIZE
4096
# echo "$((1372500*4096/1024/1024)) MB"
5361 MB
Linux moves infrequently accessed memory to swap; it doesn't always matter whether you have free memory or not at the time, see this answer on a similar question at askubuntu: https://askubuntu.com/a/159358