AIX詳細查看用戶/進程使用內存
問題描述:通過topas發現%comp內存已使用98%
問題分析:
1,從大到小排列10個內存使用率進程
ps aux | head -1 ; ps aux | sort -rn +3 | head -10
如詳細查看進程: ps -ealf | head -1 ; ps -ealf | sort -rn +9 | head -10
# ps aux | head -1 ; ps aux | sort -rn +3 | head -10
USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND
root 6553834 0.1 3.0 115064 115080 - A Feb 20 86:08 /var/opt/tivoli
root 5701730 0.0 1.0 17480 21956 - A Mar 05 1:17 /opt/BESClient/
pconsole 4456680 0.0 1.0 42456 42464 - A Feb 20 3:11 /usr/java5/bin/
root 6750376 0.0 0.0 796 824 pts/0 A 11:29:26 0:00 ps aux
root 6488234 0.0 0.0 260 268 - A Mar 13 0:02 auditbin
root 6357208 0.0 0.0 236 248 pts/0 A 11:29:26 0:00 sort -rn +3
root 5963962 0.0 0.0 1768 1804 - A Feb 20 0:00 /usr/sbin/rsct/
root 5832798 0.0 0.0 836 856 - A 11:29:12 0:00 telnetd -a
root 5570748 0.0 0.0 2128 2096 - A Feb 20 0:00 /usr/sbin/rsct/
root 5308652 0.0 0.0 7328 7436 - A Feb 20 1:01 /usr/sbin/rsct/
2,根據某個命令或進程名,查看內存使用率
# ps aux | head -1 ; ps aux | grep topas
如詳細查看:
USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND
root 2359426 0.0 0.0 1440 1272 - A Feb 20 1:08 /usr/bin/topasr
root 6160578 0.0 0.0 252 264 pts/0 A 11:36:45 0:00 grep topas
但有的時候ps aux並不能非常詳細地表現出進程的完整使用率
3,通過root用戶svmon用戶可以分析出內存使用量
# svmon -G
size inuse free pin virtual mmode
memory 1048576 1037487 11089 229668 378796 Ded
pg space 2097152 2360
work pers clnt other
pin 196952 0 0 32716
in use 378796 0 658691
PageSize PoolSize inuse pgsp pin virtual
s 4 KB - 793327 2360 49188 134636
m 64 KB - 15260 0 11280 15260
inuse:是物理內存使用量,這裡是以4K為單位,所以 1037487*4096=4249546752(424M)
virtual:是虛擬內存使用量,這裡是以4K為單位,所以 378796*4096=1551548416(155M)
4,顯示使用物理內存最多的3個進程:
# svmon -uP -t 3|grep -p Pid|grep '^.*[0-9] '
6553834 java 51279 8917 0 50938 N Y N
4456680 java 34626 8874 0 34608 N Y N
5701730 BESClient 29564 8882 0 25689 Y Y N
輸出的格式順序為 Pid Command Inuse Pin Pgsp Virtual 64-bit Mthrd
可以計算出X程序所使用的實存為51279×4096=210038784,約為210MB
5,顯示交換區使用物理內存最多的3個進程
# svmon -gP -t 3|grep -p Pid|grep '^.*[0-9] '
1966206 shlap64 26782 8880 0 26771 Y N N
0 swapper 9872 8912 0 9872 Y N N
1 init 22094 8836 0 22076 N N N
第一個程序X所使用的交換區大小約為 26782×4096 =10510336 字節,大約為10MB空間
6,每隔三秒顯示使用最多的段
# svmon -S -t 3 -i 3
Vsid Esid Type Description Inuse Pin Pgsp Virtual
4f08 - clnt 37505 0 - -
11e1 - clnt 33623 0 - -
8811 - work kernel pinned heap 12637 6547 8091 19397
可見,Vsid為4f08的段使用最多
7,svmon -pP 22674
看PID為22674的進程所使用的為那些文件
Pid Command nuse Pin Pgsp Virtual 64-bit Mthrd
22674 java 29333 1611 2756 32404 N Y
Vsid Esid Type Description Inuse Pin Pgsp Virtual
0 0 work kernel seg 2979 1593 1659 4561
a056 - work 43 16 3 46
1e03 2 work process private 77 2 17 93
1080 - pers /dev/hd2:69742 1 0 - -
f8bd f work shared library data 84 0 11 99
60ee 8 work shmat/mmap 0 0 0 0
70ec - pers /dev/hd2:69836 1 0 - -
8,通過ncheck命令,檢查Vsid都使用了哪些文件。
ncheck a056
附件1:查看物理內存總量
# cat mem1.sh
#!/usr/bin/ksh
#mem totle
totalmem=$(vmstat -v|head -n 1|awk '{print $1/256}')
echo "mem totle:"
echo $totalmem MB
echo
附件2:查看每個用戶占用物理內存的數量
# cat mem2.sh
usermem=$(for username in `cat /etc/passwd|awk -F: '{print $1}'`
do
svmon -U $username|grep $username" "
done)
usermem=`echo "$usermem"|grep -v "0 0 0 0"|awk '{print $1,$2/256,"MB"}'`
echo "singe user pmem"
echo "$usermem"
usermem=$(echo "$usermem"|awk 'BEGIN{sum1=0;}{sum1=sum1+$2;}END{print sum1;}')
usermem=$(echo $usermem|awk -F\. '{print $1}')
echo "singe user pmem :" $usermem MB
echo
AIX5.3下查看系統、用戶、文件系統占用內存數量
#!/usr/bin/ksh
#查看總的內存數量:
totalmem=$(vmstat -v|head -n 1|awk '{print $1/256}')
echo "總內存(物理內存):"
echo $totalmem MB
echo
#查看各用戶使用的內存:
usermem=$(for username in `cat /etc/passwd|awk -F: '{print $1}'`
do
svmon -U $username|grep $username" "
done)
usermem=`echo "$usermem"|grep -v "0 0 0 0"|awk '{print $1,$2/256,"MB"}'`
echo "各用戶內存(物理內存):"
echo "$usermem"
usermem=$(echo "$usermem"|awk 'BEGIN{sum1=0;}{sum1=sum1+$2;}END{print sum1;}')
usermem=$(echo $usermem|awk -F\. '{print $1}')
echo "用戶內存(物理內存)合計:" $usermem MB
echo
#查看文件系統緩存:
clientmem1=`svmon -G|grep "^pin"|awk '{print $4}'`
clientmem2=`svmon -G|grep "^in use"|awk '{print $5}'`
clientmem=`expr $clientmem1 + $clientmem2`
clientmem=`expr $clientmem / 256`
echo "文件系統緩存(物理內存):"
echo $clientmem MB
echo
#查看系統使用內存:
sysmem=$(svmon -S -s -u|cut -b 54-|grep -v "0 0 0 0"|grep [0-9]|awk '{print $1,$2}')
supremeseg=`echo "$sysmem"|grep S|awk 'BEGIN{sum1=0;}{sum1=sum1+$2;}END{sum1=sum1*16*1024*1024;print sum1;}'`
largeseg=`echo "$sysmem"|grep L|awk 'BEGIN{sum1=0;}{sum1=sum1+$2;}END{sum1=sum1*16*1024;print sum1;}'`
mediumseg=`echo "$sysmem"|grep m|awk 'BEGIN{sum1=0;}{sum1=sum1+$2;}END{sum1=sum1*64;print sum1;}'`
smallseg=`echo "$sysmem"|grep s|awk 'BEGIN{sum1=0;}{sum1=sum1+$2;}END{sum1=sum1*4;print sum1;}'`
sysmem=$(expr $supremeseg + $largeseg + $mediumseg + $smallseg)
sysmem=$(expr $sysmem / 1024)
echo "系統內存(物理內存):"
echo $sysmem MB
echo
#查看空閒內存:
freemem=$(vmstat -v|grep free|awk '{print $1/256}')
echo "空閒內存(物理內存):"
freemem=$(echo $freemem|awk -F\. '{print $1}')
echo $freemem MB
echo