我有一台非常繁忙的 GNU/Linux 服务器,我认为它需要更多 RAM。我知道该free
命令不会显示已使用的 RAM 量。
所以我偶然发现了Commited_As
。/proc/meminfo
它目前显示 57972 kB,这并不多。这是进程“现在”使用的 RAM 量,还是这是估计需要多少额外 RAM 才能在这种负载下永远不会耗尽内存?
答案1
是的,Committed_AS 是需要查找的字段。正如 Robert 所说,如果该内核在特定时刻批准并分配了所有内存请求,则 99.99% 保证系统不会发生 OOM。
来自内核源代码。
Committed_AS: The amount of memory presently allocated on the system.
714 The committed memory is a sum of all of the memory which
715 has been allocated by processes, even if it has not been
716 "used" by them as of yet. A process which malloc()'s 1G
717 of memory, but only touches 300M of it will only show up
718 as using 300M of memory even if it has the address space
719 allocated for the entire 1G. This 1G is memory which has
720 been "committed" to by the VM and can be used at any time
721 by the allocating application. With strict overcommit
722 enabled on the system (mode 2 in 'vm.overcommit_memory'),
723 allocations which would exceed the CommitLimit (detailed
724 above) will not be permitted. This is useful if one needs
725 to guarantee that processes will not fail due to lack of
726 memory once that memory has been successfully allocated.
它在源中被声明为一个结构,并在函数 _vm_enough_memory() 中使用它来查看进程是否可以在内存中增长。
简而言之,这是一个用于监测内存问题的非常好的参数。
答案2
Committed_As 是对需要多少 RAM 才能 99.99% 地保证永远不会发生 OOM 的估计。
话虽如此,我不确定这个数字有多准确,或者我是否愿意为此下赌注。在我当前的服务器上,它几乎是我活动+非活动内存使用量的两倍,而在我的另一台服务器上,它显示 61mb,而服务器的活动内存约为 1gb。这让我对这个数字产生了怀疑……