Ubuntu solves the problem that oom-killer will kill some processes when the cache becomes larger. ubuntu-killer
Recently I encountered a problem where the out of memory of the operating system caused the oom-killer system to directly kill the program after the program was running for a long time:
The error message is:
Out of memory: Kill process 20011 (main) score 58 or sacriice ice child
Killed process 20011 (main) total-vm: 21688384kB, anon-rss: 715844kB, file-rss: 816256kB
These errors can be found in the/var/log/syslog file of linux.
This involves the problem of oom-killer, For details, see: http://blog.csdn.net/gugemichael/article/details/24017515
Solution 1:
Modify the/proc/sys/vm/lowmem_reserve_ratio file, that is, echo 512>/proc/sys/vm/lowmem_reserve_ratio1. malloc allocates virtual address space. Without memset or bzero, physical allocate will not be triggered and physical addresses will not be mapped, therefore, bzero is used here. 2. The block size applied each time is relatively exquisite. the Linux kernel is divided into LowMemroy and HighMemroy. LowMemory is a memory-intensive resource, and LowMemroy has a threshold value through free-lm and
/Proc/sys/vm/lowmem_reserve_ratio to check the current low size and threshold low size. Oom killer is triggered only when it is lower than the threshold value. Therefore, the default 256 M is used for block allocation. Otherwise, if you apply for 512 M (greater than 128 M) each time ), malloc may be blocked by the underlying brk syscall, and the kernel triggers page cache write-back or slab reclaim.
Solution 2: (from http://orax.blog.sohu.com/144138537.html)
Adjust three virtual memory parameters:
L VMS. min_free_kbytes = 409600
L vm. vfs_cache_pressure = 200
L vm. swappiness = 40
The purpose of adjusting MIN_FREE_KBYTES is to keep the physical memory free enough to prevent sudden page breaks. Swapiness is 60 by default. Reducing swapiness will allow the system to release more physical memory as soon as possible through the process resources not used by swapout. The default value of Vfs_cache_pressure is 100. This parameter is used to increase the tendency of the virtual memory to reclaim directory and I-node buffering. The larger the value, the more serious the tendency of recovery. The purpose of adjusting these three parameters is to allow the operating system to reclaim the buffer as soon as possible and release the physical memory, so as to avoid sudden large-scale page feed.
The sysctl command adjusted three parameters:
# Sysctl-w vm. min_free_kbytes = 409600 // here, the unit of 3000000 is k bytes (because my memory is 8 GB), that is, the cache page must be at least 3 GB, let the system kernel release the physical memory
# Sysctl-w vm. vfs_cache_pressure = 200
# Sysctl-w vm. swappiness = 40
After modifying the parameters, go to the/proc/sys/vm directory and check whether the three parameters are correctly modified:
# Cd/proc/sys/vm
# Cat min_free_kbytes
# Cat vfs_cache_pressure
# Cat swappiness
After the parameter is modified, after several minutes, the idle physical memory on node 1 obviously recovers. It indicates that the parameter actually works. The above operation has completed the current system adjustment. For permanent settings, You need to modify the/etc/sysctl. conf parameter file.
Cd/etc
# Cp sysctl. conf sysctl. conf. save20080304
# Vi sysctl. conf
Add the following content:
# Modify vm parameter
VMS. min_free_kbytes = 409600
Vm. vfs_cache_pressure = 200
Vm. swappiness = 40
Solution 3:
Directly modify the/proc/PID/oom_adj file and set it to-17. When oom-killer selects the kill program, the score value of the process to be protected is 0, and the score value is higher, oom-killer selects the program and kills it.
Echo-17/proc/8163/oom_adj
Solution 4: (from http://blog.csdn.net/tenfyguo/article/details/9409743)
Disable oom-killer directly
How to disable and activate OOM Killer:
# Echo "0">/proc/sys/vm/oom-kill
# Echo "1">/proc/sys/vm/oom-kill