smem 介绍
smem 是 linux 零碎上一款能够生成多种内存耗用报告的命令行工具。与现有工具不一样的是 smem 能够报告理论应用的物理内存(PSS),这是一种更有意义的指标。能够用来掂量内存零碎的库金和应用程序所占用的内存数量。
因为大部分的物理内存通常在多个应用程序之间共享,名为理论应用物理内存(RSS)的这个规范的内存耗用掂量指标会大大高估内存耗用状况。PSS 这个参数而是掂量了每个应用程序在每个共享内存区中的 ”偏心调配“,给出一个切合实际的掂量指标。
对于 RSS、PSS 的介绍可查看文章:Linux 内存中VSS、RSS、PSS、USS 介绍
装置
sudo apt-get install smem
常用命令
smem -u
# 参数 -u 显示每个用户所耗用的内存总量User Count Swap USS PSS RSSmemcached 1 0 0 812 0qiming 1 0 0 2207 0mysql 1 0 0 11313 0www 23 0 0 43324 0root 10 0 0 67839 0
smem -p
# 参数 -p 查看内存占用百分比 PID User Command Swap USS PSS RSS23796 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%
smem -w
# 参数 -w 查看零碎内存应用状况# 能够 -p -w 联合Area Used Cache Noncachefirmware/hardware 0 0 0kernel image 0 0 0kernel dynamic memory 5627160 157948 5469212userspace memory 174228 71404 102824free memory 2403520 2403520 0
smem -w -p
# 以百分比展现Area Used Cache Noncachefirmware/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%
smem -R 24G -w
# 参数-R REALMEM,REALMEM这个值是指物理内存数量。此参数能够让smem在整个零碎(-w)的输入中发现固件/硬件所耗用的内存数量(比照高低即可发现,留神firmware/hardware)Area Used Cache Noncachefirmware/hardware 16960916 0 16960916kernel image 0 0 0kernel dynamic memory 5636972 157948 5479024userspace memory 174228 71404 102824free memory 2393708 2393708 0
smem -c "name user pss"
#参数-c 用来显示须要展现的列Name User PSSinit root 140mysqld_safe root 232php-fpm www 380php-fpm www 382nginx www 632memcached memcached 824
smem -s rss
#参数-s 依据某一列(例如 rss)来排序PID User Command Swap USS PSS RSS1 root /init 0 0 440 070 root php-fpm: master process (/w 0 0 1447 072 www php-fpm: pool www 0 0 380 015099 www nginx: worker process 0 0 3239 0
smem -s rss -r
#参数-r 个别与参数-s联合应用,示意反转排序(从升序改为降序)PID User Command Swap USS PSS RSS80 www php-fpm: pool www 0 0 382 081 www php-fpm: pool www 0 0 382 0112 root /www/server/panel/pyenv/bin 0 0 16958 0130 root /www/server/panel/pyenv/bin 0 0 33785 0271 root nginx: master process /www/ 0 0 3699 03005 root /bin/sh /www/server/mysql/b 0 0 232 03622 mysql /www/server/mysql/bin/mysql 0 0 11313 0
smem -M php
#参数-M 过滤相干过程 PID User Command Swap USS PSS RSS15108 www nginx: worker process 0 0 65 015109 www nginx: worker process 0 0 65 015110 www nginx: worker process 0 0 65 015111 www nginx: cache manager proces 0 0 89 0 271 root nginx: master process /www/ 0 0 1307 0
smem -k
#显示内存单位smem -u -kUser Count Swap USS PSS RSSmemcached 1 0 0 824.0K 0mysql 1 0 0 11.0M 0www 23 0 0 42.3M 0root 10 0 0 66.3M 0