如何查看按实际内存使用量排序的顶级进程? [英] How to see top processes sorted by actual memory usage?
问题描述
我有一台具有12G内存的服务器. top的片段如下所示:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12979 frank 20 0 206m 21m 12m S 11 0.2 26667:24 krfb
13 root 15 -5 0 0 0 S 1 0.0 36:25.04 ksoftirqd/3
59 root 15 -5 0 0 0 S 0 0.0 4:53.00 ata/2
2155 root 20 0 662m 37m 8364 S 0 0.3 338:10.25 Xorg
4560 frank 20 0 8672 1300 852 R 0 0.0 0:00.03 top
12981 frank 20 0 987m 27m 15m S 0 0.2 45:10.82 amarok
24908 frank 20 0 16648 708 548 S 0 0.0 2:08.84 wrapper
1 root 20 0 8072 608 572 S 0 0.0 0:47.36 init
2 root 15 -5 0 0 0 S 0 0.0 0:00.00 kthreadd
free -m
显示以下内容:
total used free shared buffers cached
Mem: 12038 11676 362 0 599 9745
-/+ buffers/cache: 1331 10706
Swap: 2204 257 1946
如果我理解正确,则系统只有362 MB的可用内存.我的问题是:如何找出哪个进程正在消耗大部分内存?
仅作为背景信息,系统正在运行64bit OpenSuse 12
.
首先,重复一遍此口头禅:未使用的内存就是浪费的内存". Linux内核会保留巨大数量的文件元数据和所请求的文件,直到看起来更重要的东西将这些数据推出为止.这就是为什么您可以运行:
find /home -type f -name '*.mp3'
find /home -type f -name '*.aac'
并使第二个find
实例以惊人的速度运行.
Linux仅留出一点可用"内存来处理内存使用量的高峰,而无需付出太多努力.
第二,您想找到正在消耗所有内存的进程;在top
中,使用M
命令按内存使用进行排序.随意忽略VIRT
列,该列仅告诉您已分配了多少虚拟内存,而不是进程正在使用的内存量. RES
报告 驻留的内存或当前在ram中的内存(而不是交换到磁盘,或者尽管有人提出请求,但从来没有实际分配过).
但是,由于RES
将算为/lib/libc.so.6
几乎每个进程都使用一次内存,这并不是一个进程正在使用多少内存的好方法. SHR
列报告与其他进程共享的内存量,但是不能保证另一个进程实际上正在共享-它可以共享,只有其他人不想共享. >
smem
工具旨在帮助用户更好地衡量应真正存储多少内存归咎于每个单独的过程.它做了一些聪明的工作,以找出真正独特的内容,共享的内容,并按比例将共享内存与共享它的进程相加. smem
可以帮助您了解内存的性能要比top
更好,但是top
是出色的入门工具.
I have a server with 12G of memory. A fragment of top is shown below:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12979 frank 20 0 206m 21m 12m S 11 0.2 26667:24 krfb
13 root 15 -5 0 0 0 S 1 0.0 36:25.04 ksoftirqd/3
59 root 15 -5 0 0 0 S 0 0.0 4:53.00 ata/2
2155 root 20 0 662m 37m 8364 S 0 0.3 338:10.25 Xorg
4560 frank 20 0 8672 1300 852 R 0 0.0 0:00.03 top
12981 frank 20 0 987m 27m 15m S 0 0.2 45:10.82 amarok
24908 frank 20 0 16648 708 548 S 0 0.0 2:08.84 wrapper
1 root 20 0 8072 608 572 S 0 0.0 0:47.36 init
2 root 15 -5 0 0 0 S 0 0.0 0:00.00 kthreadd
The free -m
shows the following:
total used free shared buffers cached
Mem: 12038 11676 362 0 599 9745
-/+ buffers/cache: 1331 10706
Swap: 2204 257 1946
If I understand correctly, the system has only 362 MB of available memory. My question is: How can I find out which process is consuming most of the memory?
Just as background info, the system is running 64bit OpenSuse 12
.
First, repeat this mantra for a little while: "unused memory is wasted memory". The Linux kernel keeps around huge amounts of file metadata and files that were requested, until something that looks more important pushes that data out. It's why you can run:
find /home -type f -name '*.mp3'
find /home -type f -name '*.aac'
and have the second find
instance run at ridiculous speed.
Linux only leaves a little bit of memory 'free' to handle spikes in memory usage without too much effort.
Second, you want to find the processes that are eating all your memory; in top
use the M
command to sort by memory use. Feel free to ignore the VIRT
column, that just tells you how much virtual memory has been allocated, not how much memory the process is using. RES
reports how much memory is resident, or currently in ram (as opposed to swapped to disk or never actually allocated in the first place, despite being requested).
But, since RES
will count e.g. /lib/libc.so.6
memory once for nearly every process, it isn't exactly an awesome measure of how much memory a process is using. The SHR
column reports how much memory is shared with other processes, but there is no guarantee that another process is actually sharing -- it could be sharable, just no one else wants to share.
The smem
tool is designed to help users better gage just how much memory should really be blamed on each individual process. It does some clever work to figure out what is really unique, what is shared, and proportionally tallies the shared memory to the processes sharing it. smem
may help you understand where your memory is going better than top
will, but top
is an excellent first tool.
这篇关于如何查看按实际内存使用量排序的顶级进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!