Linux

我的 Centos 伺服器會洩漏記憶體嗎?

  • August 6, 2012

我收到了一些關於虛擬化伺服器的記憶體使用的相互矛盾的資訊。最令人震驚的資訊是:

每天的伺服器記憶體使用量

請注意,伺服器僅分配了 4GB 的 RAM,儘管已送出顯示為 12GB。

另外,如果我執行,ps aux | grep httpd我會得到以下資訊:

root      1566  0.1  9.5 580392 375540 ?       Ss   Jun18  96:15 /usr/local/apache/bin/httpd -k start -DSSL
root      4212  0.0  9.4 580388 371948 ?       S    08:01   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody    7674  0.6  9.5 580392 373600 ?       S    08:26   0:02 /usr/local/apache/bin/httpd -k start -DSSL
nobody   10894  0.6  9.5 580532 373508 ?       S    08:28   0:01 /usr/local/apache/bin/httpd -k start -DSSL
nobody   11668  0.6  9.5 580392 373600 ?       S    08:29   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   11669  0.6  9.5 580392 373512 ?       S    08:29   0:01 /usr/local/apache/bin/httpd -k start -DSSL
nobody   11975  0.6  9.5 580392 373492 ?       S    08:29   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   12108  0.7  9.5 580392 373492 ?       S    08:29   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   12993  0.6  9.5 580392 373492 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   13080  0.6  9.5 580392 373492 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   13211  0.6  9.5 580392 373492 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   13496  0.6  9.5 580392 373520 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   13497  0.6  9.5 580392 373492 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   13829  0.6  9.5 580392 373492 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   13858  0.6  9.5 580392 373492 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   13963  0.6  9.5 580392 373484 ?       S    08:30   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   14070  0.7  9.5 580392 373492 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   14290  0.6  9.5 580392 373492 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   14404  0.6  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   14745  0.6  9.5 580392 373492 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   14850  0.6  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   14957  0.5  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15061  0.6  9.5 580392 373492 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15174  0.8  9.5 580392 373492 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15228  0.6  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15263  0.4  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15264  0.5  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15290  0.7  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15291  0.5  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15294  0.4  9.5 580392 373484 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15296  0.6  9.5 580392 373492 ?       S    08:31   0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody   15401  0.5  9.5 580392 373484 ?       S    08:32   0:00 /usr/local/apache/bin/httpd -k start -DSSL
root     15506  0.0  0.0 103228   840 pts/0    S+   08:32   0:00 grep httpd

這總共使用了超過 294.5% 的記憶體。

top也給出了類似的結果。

但是,如果我執行,free -m我會得到:

            total       used       free     shared    buffers     cached
Mem:          3831       3647        184          0        257       2358
-/+ buffers/cache:       1031       2799
Swap:         4031         29       4002

這對我來說似乎沒問題,沒有過度使用記憶體的跡象。

伺服器相對較快,沒有異常的停機時間/遲緩,我想保持這種狀態。異常讀數只是異常,還是更嚴重的事情?

你有足夠的記憶體。如果您使用的記憶體達到最大數量並且緩衝區和記憶體將非常低,那麼您將遇到記憶體問題,使用 SWAP 將會增加,那麼您可能會遇到可用 RAM 的問題。從你的文章來看,一切正常……

這是什麼是送出記憶體的簡單解釋:

Committed_AS: An estimate of how much RAM you would need to make a 99.99% guarantee that there never is OOM (out of memory) for this workload. Normally the kernel will overcommit memory. That means, say you do a 1GB malloc, nothing happens, really. Only when you start USING that malloc memory you will get real memory on demand, and just as much as you use. So you sort of take a mortgage and hope the bank doesn't go bust. Other cases might include when you mmap a file that's shared only when you write to it and you get a private copy of that data. While it normally is shared between processes. The Committed_AS is a guesstimate of how much RAM/swap you would need worst-case.

這裡是漏洞說明http://www.redhat.com/advice/tips/meminfo.html

所以你沒有記憶問題,一切正常,讀數正常。

引用自:https://serverfault.com/questions/414534