导读 Linux 系统的内存管理工作中,内存使用情况的监控是十分重要的,在各种 Linux 发行版上你会找到许多这种工具。它们的工作方式多种多样,在这里,我们将会介绍如何安装和使用这样的一个名为 smem 的工具软件。
Smem工具的简介

Smem 是一款命令行下的内存使用情况报告工具,它能够给用户提供 Linux 系统下的内存使用的多种报告。和其它传统的内存报告工具不同的是,它有个独特的功能,可以报告 PSS【Proportional Set Size(按比例占用大小)】,这种内存使用量表示方法对于那些在虚拟内存中的应用和库更有意义。传统工具会将目光主要集中于读取 RSS,这种方法是以物理内存方案来衡量使用情况的标准方法,但是往往高估了应用程序的内存的使用情况。PSS 从另一个侧面,通过判定在虚拟内存中的应用和库所使用的“合理分享”的内存,来给出更可信的衡量结果。

Smem 这一工具的特点
  1. 系统概览列表
  2. 以进程、映射和用户来显示或者是过滤
  3. /proc 文件系统中得到数据
  4. 从多个数据源配置显示的条目
  5. 可配置输出单位和百分比
  6. 易于配置列表表头和汇总
  7. 从镜像文件夹或者是压缩的 tar 文件中获得数据快照
  8. 内置的图表生成机制
  9. 轻量级的捕获工具,可用于嵌入式系统
安装 Smem - Linux工具
安装条件:
  1. 现代内核 (版本号高于 2.6.27)
  2.  
  3. 较新的 Python 版本 (2.4 及以后版本)
  4.  
  5. 可选的 matplotlib 库用于生成图表

对于当今的大多数的 Linux 发行版而言,内核版本和 Python 的版本都能够满足需要,所以仅需要为生成良好的图表安装 matplotlib 库。

RHEL, CentOS 和 Fedora

首先启用 EPEL (Extra Packages for Enterprise Linux)软件源,然后按照下列步骤操作:

  1. # yum install smem python-matplotlib python-tk
Debian 和 Ubuntu
  1. $ sudo apt-get install smem
Linux Mint
  1. $ sudo apt-get install smem python-matplotlib python-tk
Arch Linux

使用此"https://www.archlinux.org/packages/community/i686/smem/"的AUR 仓库。

Smem–Linux的使用
内存使用情况
  1. $ sudo smem
  2.  
  3. PID User Command Swap USS PSS RSS
  4. 6367 tecmint cat 0 100 145 1784
  5. 6368 tecmint cat 0 100 147 1676
  6. 2864 tecmint /usr/bin/ck-launch-session 0 144 165 1780
  7. 7656 tecmint gnome-pty-helper 0 156 178 1832
  8. 5758 tecmint gnome-pty-helper 0 156 179 1916
  9. 1441 root /sbin/getty -8 38400 tty2 0 152 184 2052
  10. 1434 root /sbin/getty -8 38400 tty5 0 156 187 2060
  11. 1444 root /sbin/getty -8 38400 tty3 0 156 187 2060
  12. 1432 root /sbin/getty -8 38400 tty4 0 156 188 2124
  13. 1452 root /sbin/getty -8 38400 tty6 0 164 196 2064
  14. 2619 root /sbin/getty -8 38400 tty1 0 164 196 2136
  15. 3544 tecmint sh -c /usr/lib/linuxmint/mi 0 212 224 1540
  16. 1504 root acpid -c /etc/acpi/events - 0 220 236 1604
  17. 3311 tecmint syndaemon -i 0.5 -K -R 0 252 292 2556
  18. 3143 rtkit /usr/lib/rtkit/rtkit-daemon 0 300 326 2548
  19. 1588 root cron 0 292 333 2344
  20. 1589 avahi avahi-daemon: chroot helpe 0 124 334 1632
  21. 1523 root /usr/sbin/irqbalance 0 316 343 2096
  22. 585 root upstart-socket-bridge --dae 0 328 351 1820
  23. 3033 tecmint /usr/bin/dbus-launch --exit 0 328 360 2160
  24. 1346 root upstart-file-bridge --daemo 0 348 371 1776
  25. 2607 root /usr/bin/xdm 0 188 378 2368
  26. 1635 kernoops /usr/sbin/kerneloops 0 352 386 2684
  27. 344 root upstart-udev-bridge --daemo 0 400 427 2132
  28. 2960 tecmint /usr/bin/ssh-agent /usr/bin 0 480 485 992
  29. 3468 tecmint /bin/dbus-daemon --config-f 0 344 515 3284
  30. 1559 avahi avahi-daemon: running [tecm 0 284 517 3108
  31. 7289 postfix pickup -l -t unix -u -c 0 288 534 2808
  32. 2135 root /usr/lib/postfix/master 0 352 576 2872
  33. 2436 postfix qmgr -l -t unix -u 0 360 606 2884
  34. 1521 root /lib/systemd/systemd-logind 0 600 650 3276
  35. 2222 nobody /usr/sbin/dnsmasq --no-reso 0 604 669 3288
  36. ....
查看用户进程占用内存情况

普通用户运行 smem,显示由该用户的进程的占用情况,并按照 PSS 的值升序排列。

  1. $ smem
  2.  
  3. PID User Command Swap USS PSS RSS
  4. 6367 tecmint cat 0 100 145 1784
  5. 6368 tecmint cat 0 100 147 1676
  6. 2864 tecmint /usr/bin/ck-launch-session 0 144 166 1780
  7. 3544 tecmint sh -c /usr/lib/linuxmint/mi 0 212 224 1540
  8. 3311 tecmint syndaemon -i 0.5 -K -R 0 252 292 2556
  9. 3033 tecmint /usr/bin/dbus-launch --exit 0 328 360 2160
  10. 3468 tecmint /bin/dbus-daemon --config-f 0 344 515 3284
  11. 3122 tecmint /usr/lib/gvfs/gvfsd 0 656 801 5552
  12. 3471 tecmint /usr/lib/at-spi2-core/at-sp 0 708 864 5992
  13. 3396 tecmint /usr/lib/gvfs/gvfs-mtp-volu 0 804 914 6204
  14. 3208 tecmint /usr/lib/x86_64-linux-gnu/i 0 892 1012 6188
  15. 3380 tecmint /usr/lib/gvfs/gvfs-afc-volu 0 820 1024 6396
  16. 3034 tecmint //bin/dbus-daemon --fork -- 0 920 1081 3040
  17. 3365 tecmint /usr/lib/gvfs/gvfs-gphoto2- 0 972 1099 6052
  18. 3228 tecmint /usr/lib/gvfs/gvfsd-trash - 0 980 1153 6648
  19. 3107 tecmint /usr/lib/dconf/dconf-servic 0 1212 1283 5376
  20. 6399 tecmint /opt/google/chrome/chrome - 0 144 1409 10732
  21. 3478 tecmint /usr/lib/x86_64-linux-gnu/g 0 1724 1820 6320
  22. 7365 tecmint /usr/lib/gvfs/gvfsd-http -- 0 1352 1884 8704
  23. 6937 tecmint /opt/libreoffice5.0/program 0 1140 2328 5040
  24. 3194 tecmint /usr/lib/x86_64-linux-gnu/p 0 1956 2405 14228
  25. 6373 tecmint /opt/google/chrome/nacl_hel 0 2324 2541 8908
  26. 3313 tecmint /usr/lib/gvfs/gvfs-udisks2- 0 2460 2754 8736
  27. 3464 tecmint /usr/lib/at-spi2-core/at-sp 0 2684 2823 7920
  28. 5771 tecmint ssh -p 4521 tecmnt765@212.7 0 2544 2864 6540
  29. 5759 tecmint /bin/bash 0 2416 2923 5640
  30. 3541 tecmint /usr/bin/python /usr/bin/mi 0 2584 3008 7248
  31. 7657 tecmint bash 0 2516 3055 6028
  32. 3127 tecmint /usr/lib/gvfs/gvfsd-fuse /r 0 3024 3126 8032
  33. 3205 tecmint mate-screensaver 0 2520 3331 18072
  34. 3171 tecmint /usr/lib/mate-panel/notific 0 2860 3495 17140
  35. 3030 tecmint x-session-manager 0 4400 4879 17500
  36. 3197 tecmint mate-volume-control-applet 0 3860 5226 23736
  37. ...
查看系统占用内存的情况
  1. $ sudo smem -w
  2.  
  3. Area Used Cache Noncache
  4. firmware/hardware 0 0 0
  5. kernel image 0 0 0
  6. kernel dynamic memory 1425320 1291412 133908
  7. userspace memory 2215368 451608 1763760
  8. free memory 4424936 4424936 0
每一个用户的内存使用情况
  1. $ sudo smem -u
  2. User Count Swap USS PSS RSS
  3. rtkit 1 0 300 326 2548
  4. kernoops 1 0 352 385 2684
  5. avahi 2 0 408 851 4740
  6. postfix 2 0 648 1140 5692
  7. messagebus 1 0 1012 1173 3320
  8. syslog 1 0 1396 1419 3232
  9. www-data 2 0 5100 6572 13580
  10. mpd 1 0 7416 8302 12896
  11. nobody 2 0 4024 11305 24728
  12. root 39 0 323876 353418 496520
  13. tecmint 64 0 1652888 1815699 2763112
按照映射显示内存使用情况
  1. $ sudo smem -m
  2.  
  3. Map PIDs AVGPSS PSS
  4. /dev/fb0 1 0 0
  5. /home/tecmint/.cache/fontconfig/7ef2298f 18 0 0
  6. /home/tecmint/.cache/fontconfig/c57959a1 18 0 0
  7. /home/tecmint/.local/share/mime/mime.cac 15 0 0
  8. /opt/google/chrome/chrome_material_100_p 9 0 0
  9. /opt/google/chrome/chrome_material_200_p 9 0 0
  10. /usr/lib/x86_64-linux-gnu/gconv/gconv-mo 41 0 0
  11. /usr/share/icons/Mint-X-Teal/icon-theme. 15 0 0
  12. /var/cache/fontconfig/0c9eb80ebd1c36541e 20 0 0
  13. /var/cache/fontconfig/0d8c3b2ac0904cb8a5 20 0 0
  14. /var/cache/fontconfig/1ac9eb803944fde146 20 0 0
  15. /var/cache/fontconfig/3830d5c3ddfd5cd38a 20 0 0
  16. /var/cache/fontconfig/385c0604a188198f04 20 0 0
  17. /var/cache/fontconfig/4794a0821666d79190 20 0 0
  18. /var/cache/fontconfig/56cf4f4769d0f4abc8 20 0 0
  19. /var/cache/fontconfig/767a8244fc0220cfb5 20 0 0
  20. /var/cache/fontconfig/8801497958630a81b7 20 0 0
  21. /var/cache/fontconfig/99e8ed0e538f840c56 20 0 0
  22. /var/cache/fontconfig/b9d506c9ac06c20b43 20 0 0
  23. /var/cache/fontconfig/c05880de57d1f5e948 20 0 0
  24. /var/cache/fontconfig/dc05db6664285cc2f1 20 0 0
  25. /var/cache/fontconfig/e13b20fdb08344e0e6 20 0 0
  26. /var/cache/fontconfig/e7071f4a29fa870f43 20 0 0
  27. ....
筛选 smem 的输出
筛选出用户名的信息

用户名筛选输出的信息,-u 或者是 --userfilter="regex" 选项

  1. $ sudo smem -u
  2.  
  3. User Count Swap USS PSS RSS
  4. rtkit 1 0 300 326 2548
  5. kernoops 1 0 352 385 2684
  6. avahi 2 0 408 851 4740
  7. postfix 2 0 648 1140 5692
  8. messagebus 1 0 1012 1173 3320
  9. syslog 1 0 1400 1423 3236
  10. www-data 2 0 5100 6572 13580
  11. mpd 1 0 7416 8302 12896
  12. nobody 2 0 4024 11305 24728
  13. root 39 0 323804 353374 496552
  14. tecmint 64 0 1708900 1871766 2819212
筛选出进程的信息

进程名称筛选输出信息,使用-P 或者是--processfilter="regex"选项

  1. $ sudo smem --processfilter="firefox"
  2.  
  3. PID User Command Swap USS PSS RSS
  4. 9212 root sudo smem --processfilter=f 0 1172 1434 4856
  5. 9213 root /usr/bin/python /usr/bin/sm 0 7368 7793 11984
  6. 4424 tecmint /usr/lib/firefox/firefox 0 931732 937590 961504
-c 或者是 --columns 选项设置格式

使用 -c 或者是 --columns 选项,就像下面的命令这样:

  1. $ sudo smem -c "name user pss rss"
  2.  
  3. Name User PSS RSS
  4. cat tecmint 145 1784
  5. cat tecmint 147 1676
  6. ck-launch-sessi tecmint 165 1780
  7. gnome-pty-helpe tecmint 178 1832
  8. gnome-pty-helpe tecmint 179 1916
  9. getty root 184 2052
  10. getty root 187 2060
  11. getty root 187 2060
  12. getty root 188 2124
  13. getty root 196 2064
  14. getty root 196 2136
  15. sh tecmint 224 1540
  16. acpid root 236 1604
  17. syndaemon tecmint 296 2560
  18. rtkit-daemon rtkit 326 2548
  19. cron root 333 2344
  20. avahi-daemon avahi 334 1632
  21. irqbalance root 343 2096
  22. upstart-socket- root 351 1820
  23. dbus-launch tecmint 360 2160
  24. upstart-file-br root 371 1776
  25. xdm root 378 2368
  26. kerneloops kernoops 386 2684
  27. upstart-udev-br root 427 2132
  28. ssh-agent tecmint 485 992
  29. ...
以百分比的形式报告内存使用情况-p
  1. $ sudo smem -p
  2. PID User Command Swap USS PSS RSS
  3. 6367 tecmint cat 0.00% 0.00% 0.00% 0.02%
  4. 6368 tecmint cat 0.00% 0.00% 0.00% 0.02%
  5. 9307 tecmint sh -c { sudo /usr/lib/linux 0.00% 0.00% 0.00% 0.02%
  6. 2864 tecmint /usr/bin/ck-launch-session 0.00% 0.00% 0.00% 0.02%
  7. 3544 tecmint sh -c /usr/lib/linuxmint/mi 0.00% 0.00% 0.00% 0.02%
  8. 5758 tecmint gnome-pty-helper 0.00% 0.00% 0.00% 0.02%
  9. 7656 tecmint gnome-pty-helper 0.00% 0.00% 0.00% 0.02%
  10. 1441 root /sbin/getty -8 38400 tty2 0.00% 0.00% 0.00% 0.03%
  11. 1434 root /sbin/getty -8 38400 tty5 0.00% 0.00% 0.00% 0.03%
  12. 1444 root /sbin/getty -8 38400 tty3 0.00% 0.00% 0.00% 0.03%
  13. 1432 root /sbin/getty -8 38400 tty4 0.00% 0.00% 0.00% 0.03%
  14. 1452 root /sbin/getty -8 38400 tty6 0.00% 0.00% 0.00% 0.03%
  15. 2619 root /sbin/getty -8 38400 tty1 0.00% 0.00% 0.00% 0.03%
  16. 1504 root acpid -c /etc/acpi/events - 0.00% 0.00% 0.00% 0.02%
  17. 3311 tecmint syndaemon -i 0.5 -K -R 0.00% 0.00% 0.00% 0.03%
  18. 3143 rtkit /usr/lib/rtkit/rtkit-daemon 0.00% 0.00% 0.00% 0.03%
  19. 1588 root cron 0.00% 0.00% 0.00% 0.03%
  20. 1589 avahi avahi-daemon: chroot helpe 0.00% 0.00% 0.00% 0.02%
  21. 1523 root /usr/sbin/irqbalance 0.00% 0.00% 0.00% 0.03%
  22. 585 root upstart-socket-bridge --dae 0.00% 0.00% 0.00% 0.02%
  23. 3033 tecmint /usr/bin/dbus-launch --exit 0.00% 0.00% 0.00% 0.03%
  24. ....
最后一行汇总信息
  1. $ sudo smem -t
  2. PID User Command Swap USS PSS RSS
  3. 6367 tecmint cat 0 100 139 1784
  4. 6368 tecmint cat 0 100 141 1676
  5. 9307 tecmint sh -c { sudo /usr/lib/linux 0 96 158 1508
  6. 2864 tecmint /usr/bin/ck-launch-session 0 144 163 1780
  7. 3544 tecmint sh -c /usr/lib/linuxmint/mi 0 108 170 1540
  8. 5758 tecmint gnome-pty-helper 0 156 176 1916
  9. 7656 tecmint gnome-pty-helper 0 156 176 1832
  10. 1441 root /sbin/getty -8 38400 tty2 0 152 181 2052
  11. 1434 root /sbin/getty -8 38400 tty5 0 156 184 2060
  12. 1444 root /sbin/getty -8 38400 tty3 0 156 184 2060
  13. 1432 root /sbin/getty -8 38400 tty4 0 156 185 2124
  14. 1452 root /sbin/getty -8 38400 tty6 0 164 193 2064
  15. 2619 root /sbin/getty -8 38400 tty1 0 164 193 2136
  16. 1504 root acpid -c /etc/acpi/events - 0 220 232 1604
  17. 3311 tecmint syndaemon -i 0.5 -K -R 0 260 298 2564
  18. 3143 rtkit /usr/lib/rtkit/rtkit-daemon 0 300 324 2548
  19. 1588 root cron 0 292 326 2344
  20. 1589 avahi avahi-daemon: chroot helpe 0 124 332 1632
  21. 1523 root /usr/sbin/irqbalance 0 316 340 2096
  22. 585 root upstart-socket-bridge --dae 0 328 349 1820
  23. 3033 tecmint /usr/bin/dbus-launch --exit 0 328 359 2160
  24. 1346 root upstart-file-bridge --daemo 0 348 370 1776
  25. 2607 root /usr/bin/xdm 0 188 375 2368
  26. 1635 kernoops /usr/sbin/kerneloops 0 352 384 2684
  27. 344 root upstart-udev-bridge --daemo 0 400 426 2132
  28. .....
  29. -------------------------------------------------------------------------------
  30. 134 11 0 2171428 2376266 3587972

简要以图形的形式报告内存的使用情况

条形图

生成一张进程的 PSS 和 RSS 值的条状图,纵坐标为每一个进程的 PSS 和 RSS 值,横坐标为 root 用户的所有进程(的 ID):

  1. $ sudo smem --userfilter="root" --bar pid -c"pss rss"

饼形图

也可以生成进程及其 PSS 和 RSS 占用量的饼状图。以下的命令将会输出一张 root 用户的所有进程的饼状图。

--pie name 意思为以各个进程名字为标签,-s选项用来以 PSS 的值排序。

  1. $ sudo smem --userfilter="root" --pie name -s pss

关于 smem 的介绍到此为止,不过想要更好的了解它,可以通过 man 手册,-h等方式获得更多的选项,然后一一实践。有什么想法或者疑惑,都可以跟帖评价。

smem – Linux 内存监视软件的更多相关文章

  1. 常用linux系统监视软件

    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo ##epel源 yum install -y ...

  2. Linux内存运维操作及常用命令

    Linux内存运维操作及常用命令 1.问题诊断 1.1 什么是 Linux 服务器 Load Average? 1.2如何查看 Linux 服务器负载? 1.3服务器负载高怎么办? 1.4如何查看服务 ...

  3. 【实时】DevExpress内存监视

    前言 在做项目的时候,我们有时候需要检测项目的内存占用情况,有时候是检测内存泄露~,有时候是查看某段代码执行前后的内存对比,以方便找出问题并以解决. 内存泄漏也称作“存储渗漏”,用动态存储分配函数动态 ...

  4. linux内存——/proc/sys/vm/drop_caches

      原贴:http://www.linuxfly.org/post/320/ http://blog.csdn.net/chinalinuxzend/article/category/265273/2 ...

  5. Windows内存管理和linux内存管理

    windows内存管理 windows 内存管理方式主要分为:页式管理,段式管理,段页式管理. 页式管理的基本原理是将各进程的虚拟空间划分为若干个长度相等的页:页式管理把内存空间按照页的大小划分成片或 ...

  6. Linux内存寻址之分页机制

    在上一篇文章Linux内存寻址之分段机制中,我们了解逻辑地址通过分段机制转换为线性地址的过程.下面,我们就来看看更加重要和复杂的分页机制. 分页机制在段机制之后进行,以完成线性—物理地址的转换过程.段 ...

  7. 手工释放Linux内存

    转载自:http://blog.csdn.net/wyzxg/article/details/7279986/ linux的内存查看: [root@localhost 0.1.0]# free -m  ...

  8. 手工释放linux内存——/proc/sys/vm/drop_caches

    --手工释放linux内存——/proc/sys/vm/drop_caches 总有很多朋友对于Linux的内存管理有疑问,之前一篇日志似乎也没能清除大家的疑虑.而在新版核心中,似乎对这个问题提供了新 ...

  9. Windows上模拟Linux环境的软件Cygwin

    Windows上模拟Linux环境的软件Cygwin 2010-10-11 15:19      我要评论(0) 字号:T|T Cygwin是一个用于在Windows上 模拟Linux环境的软件.它可 ...

随机推荐

  1. linux安装ftp组件

    1   安装vsftpd组件 linux系统安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件. [root@bogon ~]# yum -y install v ...

  2. angularjs中$watch监听model(对象属性、对象)变化

    昨天看了一下教学视频,学到了有关$watch的用法,想到最近做的一个页面中有个select下拉选项(select中的值变化了,则后面input中的值也跟着相应的变化),不知是否可以使用$watch来代 ...

  3. WinForm------GridControl中通过判断单元格文字显示不同字体颜色或背景色

  4. SVN服务器配置说明

    1.前 言 花了72小时,终于把 Subversion 初步掌握了.从一个连“什么是版本控制”都不知道的门外汉,到配置出精确至每目录访问的入门者,中间还卡了一天时间.其中费了许多气力,摸索实验了多次, ...

  5. Python MySQLdb在Linux下的快速安装

    在家里windows环境下搞了一次 见   python MySQLdb在windows环境下的快速安装.问题解决方式 http://blog.csdn.NET/wklken/article/deta ...

  6. Java反射机制<1>

    如果要通过一个对象找到一个类的名称,此时就需要用到反射机制(反射技术是用来做框架的,一般情况下Java私有对象不能被访问,但是暴力反射可以访问私有对象). 任何一个类如果没有明确地声明继承自哪个父类的 ...

  7. Java同步synchronized与死锁

    多个线程要操作同一资源时就有可能出现资源的同步问题. 同步就是指多个操作在同一个时间段内只能有一个线程进行,其他线程要等待此线程完成之后才可以继续执行. 解决资源共享的同步操作,可以使用同步代码块和同 ...

  8. paramiko模拟ansible远程执行命令

    主模块 #!/usr/bin/env python from multiprocessing import Process import paramiko import time import sys ...

  9. javascript 小技巧

    1:Boolean()==!! console.log(Boolean(888));//true console.log(!!(888));//true console.log(Boolean(&qu ...

  10. js日历插件 中文、英文日历

    日历插件 来源网站:http://www.cnblogs.com/yank/archive/2008/08/14/1267746.html 六款英文日历 http://www.bobd.cn/desi ...