smem 是 linux 系統上一款能夠生成多種內存耗用報告的命令行工具。與現有工具不同的是 smem 能夠報告實際使用的物理內存(PSS),這是一種更有意義的指標。能夠用來衡量內存系統的庫金和應用程序所佔用的內存數量。php
因爲大部分的物理內存一般在多個應用程序之間共享,名爲實際使用物理內存(RSS)的這個標準的內存耗用衡量指標會大大高估內存耗用狀況。PSS 這個參數而是衡量了每一個應用程序在每一個共享內存區中的 」公平分配「,給出一個切合實際的衡量指標。mysql
關於 RSS、PSS 的介紹可查看文章:Linux 內存中VSS、RSS、PSS、USS 介紹linux
sudo apt-get install smem
# 參數 -u 顯示每一個用戶所耗用的內存總量 User Count Swap USS PSS RSS memcached 1 0 0 812 0 qiming 1 0 0 2207 0 mysql 1 0 0 11313 0 www 23 0 0 43324 0 root 10 0 0 67839 0
# 參數 -p 查看內存佔用百分比 PID User Command Swap USS PSS RSS 23796 root /init 0.00% 0.00% 0.00% 0.00% 72 www php-fpm: pool www 0.00% 0.00% 0.00% 0.00% 74 www php-fpm: pool www 0.00% 0.00% 0.00% 0.00% 75 www php-fpm: pool www 0.00% 0.00% 0.00% 0.00% 15099 www nginx: worker process 0.00% 0.00% 0.04% 0.00% 15100 www nginx: worker process 0.00% 0.00% 0.04% 0.00% 15101 www nginx: worker process 0.00% 0.00% 0.04% 0.00%
# 參數 -w 查看系統內存使用狀況 # 能夠 -p -w 結合 Area Used Cache Noncache firmware/hardware 0 0 0 kernel image 0 0 0 kernel dynamic memory 5627160 157948 5469212 userspace memory 174228 71404 102824 free memory 2403520 2403520 0
# 以百分比展現 Area Used Cache Noncache firmware/hardware 0.00% 0.00% 0.00% kernel image 0.00% 0.00% 0.00% kernel dynamic memory 67.75% 1.93% 65.83% userspace memory 2.12% 0.87% 1.25% free memory 30.12% 30.12% 0.00%
# 參數-R REALMEM,REALMEM這個值是指物理內存數量。此參數能夠讓smem在整個系統(-w)的輸出中發現固件/硬件所耗用的內存數量(對比上下便可發現,注意firmware/hardware) Area Used Cache Noncache firmware/hardware 16960916 0 16960916 kernel image 0 0 0 kernel dynamic memory 5636972 157948 5479024 userspace memory 174228 71404 102824 free memory 2393708 2393708 0
#參數-c 用來顯示須要展現的列 Name User PSS init root 140 mysqld_safe root 232 php-fpm www 380 php-fpm www 382 nginx www 632 memcached memcached 824
#參數-s 根據某一列(例如 rss)來排序 PID User Command Swap USS PSS RSS 1 root /init 0 0 440 0 70 root php-fpm: master process (/w 0 0 1447 0 72 www php-fpm: pool www 0 0 380 0 15099 www nginx: worker process 0 0 3239 0
#參數-r 通常與參數-s結合使用,表示反轉排序(從升序改成降序) PID User Command Swap USS PSS RSS 80 www php-fpm: pool www 0 0 382 0 81 www php-fpm: pool www 0 0 382 0 112 root /www/server/panel/pyenv/bin 0 0 16958 0 130 root /www/server/panel/pyenv/bin 0 0 33785 0 271 root nginx: master process /www/ 0 0 3699 0 3005 root /bin/sh /www/server/mysql/b 0 0 232 0 3622 mysql /www/server/mysql/bin/mysql 0 0 11313 0
#參數-M 過濾相關進程 PID User Command Swap USS PSS RSS 15108 www nginx: worker process 0 0 65 0 15109 www nginx: worker process 0 0 65 0 15110 www nginx: worker process 0 0 65 0 15111 www nginx: cache manager proces 0 0 89 0 271 root nginx: master process /www/ 0 0 1307 0
#顯示內存單位 smem -u -k User Count Swap USS PSS RSS memcached 1 0 0 824.0K 0 mysql 1 0 0 11.0M 0 www 23 0 0 42.3M 0 root 10 0 0 66.3M 0