smem 介绍
smem 是 linux 零碎上一款能够生成多种内存耗用报告的命令行工具。与现有工具不一样的是 smem 能够报告理论应用的物理内存(PSS),这是一种更有意义的指标。能够用来掂量内存零碎的库金和应用程序所占用的内存数量。
因为大部分的物理内存通常在多个应用程序之间共享,名为理论应用物理内存(RSS)的这个规范的内存耗用掂量指标会大大高估内存耗用状况。PSS 这个参数而是掂量了每个应用程序在每个共享内存区中的 ”偏心调配“,给出一个切合实际的掂量指标。
对于 RSS、PSS 的介绍可查看文章:Linux 内存中VSS、RSS、PSS、USS 介绍
装置
<code class="shell">sudo apt-get install smem
常用命令
smem -u
<code class="shell"># 参数 -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
smem -p
<code class="shell"># 参数 -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%
smem -w
<code class="shell"># 参数 -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
smem -w -p
<code class="shell"># 以百分比展现 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%
smem -R 24G -w
<code class="shell"># 参数-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
smem -c “name user pss”
<code class="shell">#参数-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
smem -s rss
<code class="shell">#参数-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
smem -s rss -r
<code class="shell">#参数-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
smem -M php
<code class="shell">#参数-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 -k
<code class="shell">#显示内存单位 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