Recently encountered two Linux memory problems, one is triggered oom-killer caused the system to hang
1. First confirm that the version of the system is 32-bit
?
#uname -a Linux alarm 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386 |
2. Let's look at the memory management architecture of 32-bit Linux
?
# DMA: 0x00000000 - 0x00999999 (0 - 16 MB) # LowMem: 0x01000000 - 0x037999999 (16 - 896 MB) - size: 880MB # HighMem: 0x038000000 - <硬件特定> |
The kernel uses low memory to keep track of all memory allocations, so that a system with a 16GB memory is more expensive than a 4GB memory system, and when low memory is exhausted, oom-killer is triggered even if the system still has the remaining RAM. The performance of the 2.6 kernel is to kill the process that consumes the most memory, so processes such as sshd can be killed, causing the system to log off.
3. How to view Lowmem
-bash-3.00# free-lm Total used free shared buffers cached Mem: 2026 1973 the 0 2924
4. So we need to protect the LOWMEM, introducing lower_zone_protection in the 2.6 kernel, which will allow the kernel to be willing to protect low memory, thus prioritizing the allocation of memory from high.
?
-bash-3.00# cat /proc/sys/vm/lower_zone_protection 0 -bash-3.00#echo 400 > /proc/sys/vm/lower_zone_protection |
Another problem is the 24G memory system, which has less than 50M of free memory
1. Confirm that the version of the system is 64-bit
?
# 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 |
2. Use PS to see the memory of each process, about 4G, most of the memory is occupied by the page cache. The strategy of the Linux kernel is to maximize the use of memory Cache file system data, improve the IO speed, although the mechanism is that the process requires more memory, the page Cache will be automatically freed, but does not rule out the release of memory due to fragmentation does not meet the memory requirements of the process.
So we need a way to limit the pagecache limit.
Linux provides such a parameter, min_free_kbytes, to determine the threshold at which the system starts to reclaim memory and to control the system's free memory. The higher the value, the sooner the kernel starts to reclaim memory, and the higher the free memory.
?
[[email protected] root]# cat /proc/sys/vm/min_free_kbytes 163840 echo 963840 > /proc/sys/vm/min_free_kbytes |
Other optional temporary workarounds:
Close Oom-killer
Cat/proc/sys/vm/oom-kill echo "0" >/proc/sys/vm/oom-kill vi/etc/sysctl.conf vm.oom-kill = 0
2. Clear the cache (optional) echo 1 >/proc/sys/vm/drop_caches
High Linux memory, triggering Oom-killer problem resolution