Aug 23 20:09:57 localhost kernel: Out of memory: Kill process 9566 (wge) score 652 or sacrifice child
Aug 23 20:09:57 localhost kernel: Killed process 9566, UID 0, (wge) total-vm:22426596kB, anon-rss:22392788kB, file-rss:420kB
事實證明,這個問題的原因是low memory耗盡。引用Tom的話“內核使用low memory來跟蹤所有的內存分配,這樣的話一個16GB內存的系統比一個4GB內存的系統,需要消耗更多的low memory,可能有4倍之多。這種額外的壓力從你剛啟動系統那一刻就開始存在了,因為內核結構必須為潛在的跟蹤四倍多的內存分配而調整大小( The kernel uses low memory to track allocations of all memory thus a system with 16GB of memory will use significantly more low memory than a system with 4GB, perhaps as much as 4 times. This extra pressure happens from the moment you turn the system on before you do anything at all because the kernel structures have to be sized for the potential of tracking allocations in four times as much memory)”。
有兩種方法查看 low memory 和 high memory 的狀態:
這是最好的解決辦法,因為所有的內存都將成為low memory。如果你在這種情況下耗盡了low memory,那就真的是out of memory了。
2、如果受限於必須使用32位系統,最好的解決辦法是使用hugemem內核。
這種內核以不同的方式分割low/high memory,而且在大多數情況下會提供足夠多的low memory到high memory的映射(This kernel splits low/high memory differently, and in most cases should provide enough low memory to map high memory)。在大多數案例中,這是一個很簡單的修復方法:安裝hugemem kernel RPM包,然後重啟即可。
如果運行hugemem內核也不可能,你可以嘗試將 /proc/sys/vm/lower_zone_protection 的值設置為250甚至更多。這將讓內核願意保護low memory,從而在分配內存時多考慮從high memory分配(This will cause the kernel to try to be more aggressive in defending the low zone from allocating memory that could potentially be allocated in the high memory zone.)。據我所知,此選項從2.6.x內核才開始可用。必要的是,您可能需要通過一些實驗來找到您系統環境中最適合的值。可以使用下面方法快速的設置和檢查改值: