Scenario Description: In practical applications, when an oom anomaly occurs, it's not what we expect. We force the process to terminate, in fact, to shut down the service, causing the service to fail, to some extent, the system crashes or restarts or freezes, there is no difference. For the actual customer, the inability to provide the service itself is an exception, whether for the need of downtime or the cooling of the machine. In fact, we should all find the root of the problem. Under a lot of factors, we have not designed the Oom protection program to protect the whole system, on the contrary, it is through this mechanism to find out where the problem lies.
If we try to monitor our service program and whether it will cause oom, we can simply close the current process by increasing the coefficient of oom and when the whole system is out of memory. Let's look at a section of Oom code:
/* * Adjust the score by Oomkilladj. */if (P->oomkilladj) {if (P->oomkilladj > 0) Points <<= p->oomkilladj;elsepoints >>=-(p-> OOMKILLADJ);} Simple description: Points is the evaluation integer that the current process needs to terminate, the higher the value, the more likely the process is terminated, and p is the descriptor struct task_struct of the current process.
Full description of how to be able to modify the Oomkilladj parameter, any process under the/proc to generate a process flag folder, record the current process of some parameters, for example, we see through the PS Process ID number is 100, you can see things under/proc/100/. One of the Oom_adj parameters can be set, detailed settings are as follows:
Excerpt from: http://www.oracle.com/technetwork/articles/servers-storage-dev/oom-killer-1911807.html
echo >/proc/100/oom_adj
Of course, we can see from the moving position that cannot infinite move, otherwise extremes meet. The value is typically between 16 and 15.
Of course, the oom mechanism can also be closed by passing the following parameters:
Sysctl Vm.overcommit_memory=2echo "vm.overcommit_memory=2" >>/etc/sysctl.conf
The basic use of oom and the actual use case