Previous Article Next Article Linux 上常發生的問題 Out Of Memory, oom-killer
Posted in Linux

Linux 上常發生的問題 Out Of Memory, oom-killer

Linux 上常發生的問題 Out Of Memory, oom-killer Posted on 2008 年 12 月 03 日Leave a comment

會發生 Out of Memory 就我的理解是主機的記憶體不夠,但真的不夠嗎,是程式一直狂吃記憶體讓記憶體不夠用,又當你沒有設置Swap時,這情況會使主機整台 Crashed,


OOM是Out of Memory的簡寫,也就是內存不足。出現該問題的原因有很多,如程序內存泄漏等。內存泄漏問題可以通過定時地終止和重啟有問題的程序來發現和解決。在比較新的Linux內核版本(比如2.6)中,有一種名為OOM(Out Of Memory )殺手的算法,它可以在必要時執行Kill而殺掉一些程序。

swapoff /dev/sda3


dd if=/dev/zero of=/swap bs=1024 count=$[1024 * 1024 * 4]
mkswap /swap
swapon /swap

在redhat as 5.1中,可以通過

echo 1 > /proc/sys/vm/panic_on_oom


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.


你的電子郵件位址並不會被公開。 必要欄位標記為 *