如何查看 Linux 的 RAM 视图以确定碎片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4863707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to see Linux' view of the RAM in order to determinate the fragmentation
提问by Flavius
The only program relevant I know of is pmap
, but this only prints the memory of one process.
我知道的唯一相关程序是pmap
,但这只会打印一个进程的内存。
I would like to see how the physical memoryis occupied and by which processes/library, including the kernel, of the entire physical RAM (as opposed to that from the process' POV with pmap
).
我想看看物理内存是如何被占用的,以及整个物理 RAM 的哪些进程/库,包括内核(而不是来自进程的 POV 和pmap
)。
Ideally also with a graphical interface.
理想情况下还带有图形界面。
Do you know if there's any such tool?
不知道有没有这样的工具?
I know about the ambiguity introduced by libraries. If it's the case, it could display a 1-pixel wide line and an arrow to the real location of that library.
我知道图书馆引入的歧义。如果是这种情况,它可以显示一条 1 像素宽的线和一个指向该库实际位置的箭头。
What do I need this for? To view the RAM fragmentation.
我需要这个做什么?查看内存碎片。
采纳答案by Flavius
Memory Fragmentation
内存碎片
When a Linux system has been running for a while memory fragmentation can increase which depends heavily on the nature of the applications that are running on it. The more processes allocate and free memory, the quicker memory becomes fragmented. And the kernel may not always be able to defragment enough memory for a requested size on time. If that happens, applications may not be able to allocate larger contiguous chunks of memory even though there is enough free memory available. Starting with the 2.6 kernel, i.e. RHEL4 and SLES9, memory management has improved tremendously and memory fragmentation has become less of an issue.
当 Linux 系统运行一段时间后,内存碎片会增加,这在很大程度上取决于在其上运行的应用程序的性质。分配和释放内存的进程越多,内存碎片化的速度就越快。并且内核可能并不总是能够按时为请求的大小对足够的内存进行碎片整理。如果发生这种情况,即使有足够的可用内存,应用程序也可能无法分配更大的连续内存块。从 2.6 内核(即 RHEL4 和 SLES9)开始,内存管理有了极大的改进,内存碎片也不再是一个问题。
To see memory fragmentation you can use the magic SysRq key. Simply execute the following command:
要查看内存碎片,您可以使用神奇的 SysRq 键。只需执行以下命令:
# echo m > /proc/sysrq-trigger
This command will dump current memory information to /var/log/messages. Here is an example of a RHEL3 32-bit system:
此命令会将当前内存信息转储到 /var/log/messages。以下是 RHEL3 32 位系统的示例:
Jul 23 20:19:30 localhost kernel: 0*4kB 0*8kB 0*16kB 1*32kB 0*64kB 1*128kB 1*256kB 1*512kB 1*1024kB 0*2048kB 0*4096kB = 1952kB)
Jul 23 20:19:30 localhost kernel: 1395*4kB 355*8kB 209*16kB 15*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 12244kB)
Jul 23 20:19:31 localhost kernel: 1479*4kB 673*8kB 205*16kB 73*32kB 21*64kB 847*128kB 473*256kB 92*512kB 164*1024kB 64*2048kB 28*4096kB = 708564kB)
The first line shows DMA memory fragmentation. The second line shows Low Memory fragmentation and the third line shows High Memory fragmentation. The output shows memory fragmentation in the Low Memory area. But there are many large memory chunks available in the High Memory area, e.g. 28 4MB.
第一行显示 DMA 内存碎片。第二行显示低内存碎片,第三行显示高内存碎片。输出显示低内存区域中的内存碎片。但是在 High Memory 区域中有许多大内存块可用,例如 28 4MB。
If memory information was not dumped to /var/log/messages, then SysRq was not enabled. You can enable SysRq by setting sysrq to 1:
如果内存信息未转储到 /var/log/messages,则未启用 SysRq。您可以通过将 sysrq 设置为 1 来启用 SysRq:
# echo 1 > /proc/sys/kernel/sysrq
Starting with the 2.6 kernel, i.e. RHEL4 and SLES9, you don't need SysRq to dump memory information. You can simply check /proc/buddyinfo for memory fragmentation.
从 2.6 内核开始,即 RHEL4 和 SLES9,您不需要 SysRq 来转储内存信息。您可以简单地检查 /proc/buddyinfo 是否存在内存碎片。
Here is the output of a 64-bit server running the 2.6 kernel:
这是运行 2.6 内核的 64 位服务器的输出:
# cat /proc/buddyinfo
Node 0, zone DMA 5 4 3 4 3 2 1 0 1 1 2
Node 0, zone Normal 1046 527 128 36 17 5 26 40 13 16 94
# echo m > /proc/sysrq-trigger
# grep Normal /var/log/messages | tail -1
Jul 23 21:42:26 localhost kernel: Normal: 1046*4kB 529*8kB 129*16kB 36*32kB 17*64kB 5*128kB 26*256kB 40*512kB 13*1024kB 16*2048kB 94*4096kB = 471600kB
#
In this example I used SysRq again to show what each number in /proc/buddyinfo is referring to.
在这个例子中,我再次使用 SysRq 来显示 /proc/buddyinfo 中的每个数字所指的内容。
Source: http://www.puschitz.com/pblog/