日期:2014-05-16  浏览次数:20606 次

Linux内存高,触发oom-killer问题解决

最近遇到两起Linux的内存问题,其一是触发了oom-killer导致系统挂

1. 首先确认该系统的版本是32位

?
#uname -a
Linux alarm 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386

2. 我们了解一下32位Linux的内存管理结构

?
# DMA: 0x00000000 -? 0x00999999 (0 - 16 MB)
# LowMem: 0x01000000 - 0x037999999 (16 - 896 MB) - size: 880MB
# HighMem: 0x038000000 - <硬件特定>

??? 内核使用low memory来跟踪所有的内存分配,这样的话一个16GB内存的系统比一个4GB内存的系统,需要消耗更多的low memory,当low memory耗尽,即便系统仍然有剩余内存,仍然会触发oom-killer。在2.6内核的表现是,杀掉占用内存最高的进程,所以会导致sshd等进程被杀掉,造成系统无法登录。

3. 如何查看lowMem

?
-bash-3.00# free -lm
             total       used       free     shared    buffers     cached
Mem:          2026       1973         52          0         36       1303
Low:           874        823         51
High:         1151       1150          1
-/+ buffers/cache:        633       1392
Swap:         3067        142       2924
?

4. 所以我们需要保护LowMem,在2.6内核引入了lower_zone_protection,这将让内核愿意保护low memory,从而在分配内存时优先考虑从high memory分配。

?
-bash-3.00# cat /proc/sys/vm/lower_zone_protection
0
-bash-3.00#echo 400 > /proc/sys/vm/lower_zone_protection

?

?

另一起问题是24G内存的系统,空闲内存已经不到50M

1. 确认该系统的版本是64位

?
# uname -a
Linux gxgd-nms-app 2.6.18-194.el5xen #1 SMP Tue Mar 16 22:01:26 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux