完成文档的翻译

完成文档的翻译
This commit is contained in:
东风唯笑 2016-06-26 00:00:04 +08:00 committed by GitHub
parent 0b8be3b493
commit edb0dd9eb3

View File

@ -1,75 +1,75 @@
Smem Reports Memory Consumption Per-Process and Per-User Basis in Linux Smem Linux 下基于进程和用户的内存占用报告程序
=========================================================================== ===========================================================================
Memory management in terms of monitoring memory usage is one important thing to do on your Linux system, there are many tools available for monitoring your memory usage that you can find on different Linux distributions. But they work in different ways, in this how to guide, we shall take a look at how to install and use one such tool called smem. Linux 系统的内存管理工作中,内存使用情况的监控是十分重要的,不同的 Linux 发行版可能会提供不同的工具。但是它们的工作方式多种多样,这里,我们将会介绍如何安装和使用这样的一个名为 SMEM 的工具软件。
Smem is a command-line memory reporting tool thats gives a user diverse reports on memory usage on a Linux system. There is one unique thing about smem, unlike other traditional memory reporting tools, it reports PSS (Proportional Set Size), a more meaningful representation of memory usage by applications and libraries in a virtual memory setup. Smem 是一款命令行下的内存使用情况报告工具。和其它传统的内存报告工具不同个,它仅做这一件事情——报告 PPS实际使用的物理内存[比例分配共享库占用的内存]),这种内存使用量表示方法对于那些在虚拟内存中的应用和库更有意义。
![](http://www.tecmint.com/wp-content/uploads/2016/06/Smem-Linux-Memory-Reporting-Tool.png) ![](http://www.tecmint.com/wp-content/uploads/2016/06/Smem-Linux-Memory-Reporting-Tool.png)
>Smem Linux Memory Reporting Tool >Smem Linux 内存报告工具
Existing traditional tools focus mainly on reading RSS (Resident Set Size) which is a standard measure to monitor memory usage in a physical memory scheme, but tends to overestimate memory usage by applications. 已有的传统工具会将目光主要集中于读取 RSS实际使用物理内存[包含共享库占用的内存]),这种方法对于恒量那些使用物理内存方案的使用情况来说是标准方法,但是应用程序往往会高估内存的使用情况。
PSS on the other hand, gives a reasonable measure by determining the “fair-share” of memory used by applications and libraries in a virtual memory scheme. PSS 从另一个侧面,为那些使用虚拟内存方案的应用和库提供了给出了确定内存“公评分担”的合理措施。
You can read this [guide (about memory RSS and PSS)][1] to understand memory consumption in a Linux system, but let us proceed to looking at some of the features of smem. 你可以 [阅读此指南了解 (关于内存的 RSS 和 PSS)][1] Linux 系统中的内存占用。
### Features of Smem Tool ### Smem 这一工具的特点
- System overview listing - 系统概览列表
- Listings and also filtering by process, mappings or user - 以进程,映射和用户来显示或者是过滤
- Using data from /proc filesystem - 从 /proc 文件系统中得到数据
- Configurable listing columns from several data sources - 从多个数据源配置显示条目
- Configurable output units and percentages - 可配置输出单元和百分比
- Easy to configure headers and totals in listings - 易于配置列表标题和汇总
- Using data snapshots from directory mirrors or compressed tar files - 从镜像文件夹或者是压缩的 tar 文件中获得数据快照
- Built-in chart generation mechanism - 内置的图表生成机制
- Lightweight capture tool used in embedded systems - 在嵌入式系统中使用轻量级的捕获工具
### How to Install Smem Memory Reporting Tool in Linux ### 如何安装 Smem - Linux 下的内存使用情况报告工具
Before you proceed with installation of smem, your system must meet the following requirements: 安装之前,需要确保满足以下的条件:
- modern kernel (> 2.6.27 or so) - 现代内存 (版本号高于 2.6.27)
- a recent version of Python (2.4 or so) - 较新的 Python 版本 (2.4 及以后版本)
- optional [matplotlib][2] library for generation of charts - 可选的 [matplotlib][2] 库用于生成图表
Most of the todays Linux distributions comes with latest Kernel version with Python 2 or 3 support, so the only requirement is to install matplotlib library which is used to generate nice charts. 对于当今的大多数的 Linux 发行版而言,内核版本和 Python 的版本都能够 满足需要,所以仅需要为生成良好的图表安装 matplotlib 库。
#### On RHEL, CentOS and Fedora #### RHEL, CentOS 和 Fedora
First enable [EPEL (Extra Packages for Enterprise Linux)][3] repository and then install as follows: 首先启用 [EPEL (Extra Packages for Enterprise Linux)][3] 软件源然后按照下列步骤操作:
``` ```
# yum install smem python-matplotlib python-tk # yum install smem python-matplotlib python-tk
``` ```
#### On Debian and Ubuntu #### Debian 和 Ubuntu
``` ```
$ sudo apt-get install smem $ sudo apt-get install smem
``` ```
#### On Linux Mint #### Linux Mint
``` ```
$ sudo apt-get install smem python-matplotlib python-tk $ sudo apt-get install smem python-matplotlib python-tk
``` ```
#### on Arch Linux #### Arch Linux
Use this [AUR repository][4]. 使用此 [AUR repository][4]。
### How to Use Smem Memory Reporting Tool in Linux ### 如何使用 Smem Linux 下的内存使用情况报告工具
To view a report of memory usage across the whole system, by all system users, run the following command: 为了查看整个系统所有用户的内存使用情况,运行以下的命令:
``` ```
$ sudo smem $ sudo smem
``` ```
Monitor Memory Usage of Linux System 监视 Linux 系统中的内存使用情况
``` ```
PID User Command Swap USS PSS RSS PID User Command Swap USS PSS RSS
@ -108,15 +108,15 @@ Monitor Memory Usage of Linux System
.... ....
``` ```
When a normal user runs smem, it displays memory usage by process that the user has started, the processes are arranged in order of increasing PSS. 当常规用户运行 smem将会显示由用户启用的进程的占用情况其中进程按照 PSS 的值升序排列。
Take a look at the output below on my system for memory usage by processes started by user aaronkilik: 下面的输出为用户 “aaronkilik” 启用的进程的使用情况:
``` ```
$ smem $ smem
``` ```
Monitor User Memory Usage in Linux 监视 Linux 系统中的内存使用情况
``` ```
PID User Command Swap USS PSS RSS PID User Command Swap USS PSS RSS
@ -156,13 +156,12 @@ Monitor User Memory Usage in Linux
... ...
``` ```
There are many options to invoke while using smem, for example, to view system wide memory consumption, run the following command: 使用 smem 是还有一些参数可以选用,例如当参看整个系统的内存占用情况,运行以下的命令:
``` ```
$ sudo smem -w $ sudo smem -w
``` ```
监视 Linux 系统中的内存使用情况
Monitor System Wide Memory User Consumption
``` ```
Area Used Cache Noncache Area Used Cache Noncache
@ -173,13 +172,13 @@ userspace memory 2215368 451608 1763760
free memory 4424936 4424936 0 free memory 4424936 4424936 0
``` ```
To view memory usage on a per-user basis, run the command below: 如果想要查看每一个用户的内存使用情况,运行以下的命令:
``` ```
$ sudo smem -u $ sudo smem -u
``` ```
Monitor Memory Consumption Per-User Basis in Linux Linux 下以用户为单位监控内存占用情况
``` ```
User Count Swap USS PSS RSS User Count Swap USS PSS RSS
@ -196,13 +195,13 @@ root 39 0 323876 353418 496520
tecmint 64 0 1652888 1815699 2763112 tecmint 64 0 1652888 1815699 2763112
``` ```
You can also report memory usage by mappings as follows: 你也可以按照映射显示内存使用情况:
``` ```
$ sudo smem -m $ sudo smem -m
``` ```
Monitor Memory Usage by Mappings in Linux Linux 下以映射为单位监控内存占用情况
``` ```
Map PIDs AVGPSS PSS Map PIDs AVGPSS PSS
@ -232,15 +231,15 @@ Map PIDs AVGPSS PSS
.... ....
``` ```
There are also options for filtering smem output and we shall look at two examples here. 还有其它的选项用于 smem 的输出,下面将会举两个例子。
To filter output by username, invoke the -u or --userfilter="regex" option as below: 要按照用户名筛选输出的信息,调用 -u 或者是 --userfilter="regex" 选项,就像下面的命令这样:
``` ```
$ sudo smem -u $ sudo smem -u
``` ```
Report Memory Usage by User 按照用户报告内存使用情况
``` ```
User Count Swap USS PSS RSS User Count Swap USS PSS RSS
@ -257,13 +256,13 @@ root 39 0 323804 353374 496552
tecmint 64 0 1708900 1871766 2819212 tecmint 64 0 1708900 1871766 2819212
``` ```
To filter output by process name, invoke the -P or --processfilter="regex" option as follows: 要按照进程名称筛选输出信息,调用 -P 或者是 --processfilter="regex" 选项,就像下面的命令这样:
``` ```
$ sudo smem --processfilter="firefox" $ sudo smem --processfilter="firefox"
``` ```
Report Memory Usage by Process Name 按照进程名称报告内存使用情况
``` ```
PID User Command Swap USS PSS RSS PID User Command Swap USS PSS RSS
@ -272,15 +271,15 @@ PID User Command Swap USS PSS RSS
4424 tecmint /usr/lib/firefox/firefox 0 931732 937590 961504 4424 tecmint /usr/lib/firefox/firefox 0 931732 937590 961504
``` ```
Output formatting can be very important, and there are options to help you format memory reports and we shall take a look at few examples below. 输出的格式有时候也很重要smem 提供了一些参数帮助您格式化内存使用报告,我们将举出几个例子。
To show desired columns in the report, use -c or --columns option as follows: 设置哪些列在报告中,使用 -c 或者是 --columns选项就像下面的命令这样
``` ```
$ sudo smem -c "name user pss rss" $ sudo smem -c "name user pss rss"
``` ```
Report Memory Usage by Columns 按列报告内存使用情况
``` ```
Name User PSS RSS Name User PSS RSS
@ -312,13 +311,13 @@ ssh-agent tecmint 485 992
... ...
``` ```
You can invoke the -p option to report memory usage in percentages, as in the command below: 也可以调用 -p 选项以百分比的形式报告内存使用情况,就像下面的命令这样:
``` ```
$ sudo smem -p $ sudo smem -p
``` ```
Report Memory Usage by Percentages 按百分比报告内存使用情况
``` ```
PID User Command Swap USS PSS RSS PID User Command Swap USS PSS RSS
@ -346,13 +345,13 @@ Report Memory Usage by Percentages
.... ....
``` ```
The command below will show totals at the end of each column of the output: 下面的额命令将会在输出的最后输出一行汇总信息:
``` ```
$ sudo smem -t $ sudo smem -t
``` ```
Report Total Memory Usage Count 报告内存占用合计
``` ```
PID User Command Swap USS PSS RSS PID User Command Swap USS PSS RSS
@ -386,11 +385,11 @@ PID User Command Swap USS PSS RSS
134 11 0 2171428 2376266 3587972 134 11 0 2171428 2376266 3587972
``` ```
Further more, there are options for graphical reports that you can also use and we shall dive into them in this sub section. 另外smem 也提供了选项以图形的形式报告内存的使用情况,我们将会在下一小节深入介绍。
You can produce a bar graph of processes and their PSS and RSS values, in the example below, we produce a bar graph of processes owned by the root user. 比如,你可以生成一张进程的 PSS 和 RSS 值的条状图。在下面的例子中,我们会生成属于 root 用户的进程的内存占用图。
The vertical plane shows the PSS and RSS measure of processes and the horizontal plane represents each root user process: 纵坐标为每一个进程的 PSS 和 RSS 值,横坐标为 root 用户的所有进程:
``` ```
$ sudo smem --userfilter="root" --bar pid -c"pss rss" $ sudo smem --userfilter="root" --bar pid -c"pss rss"
@ -399,9 +398,9 @@ $ sudo smem --userfilter="root" --bar pid -c"pss rss"
![](http://www.tecmint.com/wp-content/uploads/2016/06/Linux-Memory-Usage-in-PSS-and-RSS-Values.png) ![](http://www.tecmint.com/wp-content/uploads/2016/06/Linux-Memory-Usage-in-PSS-and-RSS-Values.png)
>Linux Memory Usage in PSS and RSS Values >Linux Memory Usage in PSS and RSS Values
You can also produce a pie chart showing processes and their memory consumption based on PSS or RSS values. The command below outputs a pie chart for processes owned by root user measuring values. 也可以生成进程及其 PSS 和 RSS 占用量的饼状图。以下的命令将会输出一张 root 用户的所有进程的饼状。
The `--pie` name means label by name and `-s` option helps to sort by PSS value. `--pie` name 意思为以各个进程名字为标签,`-s` 选项帮助以 PSS 的值排序。
``` ```
$ sudo smem --userfilter="root" --pie name -s pss $ sudo smem --userfilter="root" --pie name -s pss
@ -410,13 +409,13 @@ $ sudo smem --userfilter="root" --pie name -s pss
![](http://www.tecmint.com/wp-content/uploads/2016/06/Linux-Memory-Consumption-by-Processes.png) ![](http://www.tecmint.com/wp-content/uploads/2016/06/Linux-Memory-Consumption-by-Processes.png)
>Linux Memory Consumption by Processes >Linux Memory Consumption by Processes
There are many other known fields apart from PSS and RSS used for labeling charts: 它们还提供了一些其它与 PSS 和 RSS 相关的字段用于图表的标签:
To get help, simply type, `smem -h` or visit the manual entry page. 假如需要获得帮助,非常简单,仅需要输入 `smem -h` 或者是浏览帮助页面。
We shall stop here with smem, but to understand it better, use it with many other options that you can find in the man page. As usual you can use the comment section below to express any thoughts or concerns. 关于 smem 的介绍到底为止,不过想要更好的了解它,可以通过 man 手册获得更多的选项,然后一一实践。有什么想法或者疑惑,都可以跟帖评价。
Reference Links: <https://www.selenic.com/smem/> 参考链接: <https://www.selenic.com/smem/>
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -424,7 +423,7 @@ Reference Links: <https://www.selenic.com/smem/>
via: http://www.tecmint.com/smem-linux-memory-usage-per-process-per-user/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+tecmint+%28Tecmint%3A+Linux+Howto%27s+Guide%29 via: http://www.tecmint.com/smem-linux-memory-usage-per-process-per-user/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+tecmint+%28Tecmint%3A+Linux+Howto%27s+Guide%29
作者:[Aaron Kili][a] 作者:[Aaron Kili][a]
译者:[译者ID](https://github.com/译者ID) 译者:[dongfengweixiao](https://github.com/dongfengweixiao)
校对:[校对者ID](https://github.com/校对者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
@ -434,7 +433,3 @@ via: http://www.tecmint.com/smem-linux-memory-usage-per-process-per-user/?utm_so
[2]: http://matplotlib.org/index.html [2]: http://matplotlib.org/index.html
[3]: http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/ [3]: http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/
[4]: https://www.archlinux.org/packages/community/i686/smem/ [4]: https://www.archlinux.org/packages/community/i686/smem/