會發生 Out of Memory 就我的理解是主機的記憶體不夠,但真的不夠嗎,是程式一直狂吃記憶體讓記憶體不夠用,又當你沒有設置Swap時,這情況會使主機整台 Crashed,
引用: http://www.admin99.net/read.php/303.htm
OOM是Out of Memory的簡寫,也就是內存不足。出現該問題的原因有很多,如程序內存泄漏等。內存泄漏問題可以通過定時地終止和重啟有問題的程序來發現和解決。在比較新的Linux內核版本(比如2.6)中,有一種名為OOM(Out Of Memory )殺手的算法,它可以在必要時執行Kill而殺掉一些程序。
比較變態的是,oom-killer只考慮lowmemory而不考慮highmemory,即便這個時候物理內存還有很多free或者cached或者buffer,只要swap不足,便會執行oom-killer。簡單怀疑swap空間會不會有什麼問題?重建一些swap,權且試試看
先移除原來的swap區
swapoff /dev/sda3創建/swap做為新的swap區,新swap分區的大小是4G,為了以后同樣生效,不要忘了編輯/etc/fstab文件。
dd if=/dev/zero of=/swap bs=1024 count=$[1024 * 1024 * 4]
mkswap /swap
swapon /swap第三種解決辦法,就是關閉oom-killer或者降低其出現的几率
在redhat as 5.1中,可以通過echo 1 > /proc/sys/vm/panic_on_oom
或者(推荐這個,一些提及oracle優化的文章中也推荐這個)
echo 1 > /proc/sys/vm/overcommit_memory
或者
echo 0 > /proc/sys/vm/overcommit_ratio
註解: overcommit_memory
Controls overcommit of system memory, possibly allowing processes to allocate (but not use) more memory than is actually available.
* 0 – Heuristic overcommit handling. Obvious overcommits of address space are refused. Used for a typical system. It ensures a seriously wild allocation fails while allowing overcommit to reduce swap usage. root is allowed to allocate slighly more memory in this mode. This is the default.
* 1 – Always overcommit. Appropriate for some scientific applications.
* 2 – Don’t overcommit. The total address space commit for the system is not permitted to exceed swap plus a configurable percentage (default is 50) of physical RAM. Depending on the percentage you use, in most situations this means a process will not be killed while attempting to use already-allocated memory but will receive errors on memory allocation as appropriate.
留言