I just ran into a swap problem, so I tried to find which process was using swap, with the script(getswap.sh) shown in this. It was php-fpm, about 200 subprocess, either toke 1M swap space. So I killed php-fpm. Then I ran the script again, and total swap used decreased a lot. Howerver, result in free -m only decreased for about 3M. What is the problem?
before killing php-fpm:
[root@eng /tmp]# bash getswap.sh | sort -n -k5>out
[root@eng /tmp]# cat out|awk '{a+=$5;}END{print a;}'
202076
[root@eng /tmp]# free -m
total used free shared buffers cached
Mem: 64259 60566 3692 0 192 17098
-/+ buffers/cache: 43275 20983
Swap: 4095 155 3940
after killing php-fpm:
[root@eng /tmp]# bash getswap.sh | sort -n -k5>out
[root@eng /tmp]# cat out|awk '{a+=$5;}END{print a;}'
108456
[root@eng /tmp]# free -m
total used free shared buffers cached
Mem: 64259 60402 3857 0 192 17043
-/+ buffers/cache: 43166 21092
Swap: 4095 152 3943
and the script:
#!/bin/bash
function getswap {
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"
}
getswap
thx in advance