How does Linux use the OOM killer mechanism?

  

The OOM killer mechanism is a mechanism for Linux to kill processes. If the process corrupts system resources to a certain extent, the OOM killer mechanism will force the process to kill. This article will introduce how Linux uses the OOM killer mechanism.

In simple terms this mechanism will monitor those who take up too much memory, especially in the moment quickly consume large amounts of memory processes, in order to prevent out of memory and the kernel will kill the process.

This function can repeatedly ensure the memory processing even if the memory cannot be released, prevent the system from stalling, and find out the process that consumes excessive memory.

The typical situation is: one machine suddenly ssh remote login, but can ping, indicating that the network is not faulty or the machine is down, it is likely that the sshd process was killed by the OOM killer.

After rebooting the machine, viewing the system log /var/log/messages will reveal an error message similar to Out of Memory: Kill process 247 (sshd).

There is another situation that can lead to ping can not ssh, that is, too many network connections to exhaust the system file descriptor resources, this situation is not considered here.

In the highly available solution using vip, this situation is also prone to brain splitting.

Preventing important system process triggering (OOM) mechanisms from being killed: You can set the parameter /proc/PID/oom_adj to -17 to temporarily turn off the OOM mechanism of the Linux kernel. The kernel will calculate a score for each process by a specific algorithm to determine which process to kill. The oom score for each process can be found in /proc/PID/oom_score.

We think that important processes have sshd, or some monitoring daemons, you can choose the process you want to protect according to your actual situation.

Protecting a process from being killed by the kernel can be done like this:

echo -17 》 /proc/$PID/oom_adj

You can write a simple script to deploy Prevent important processes from being omled on crontab

pgrep -f “/usr/sbin/sshd” |  While read PID;do echo -17 》 /proc/$PID/oom_adj;done

where “/usr/sbin/sshd” can be replaced with a process that you think is important, but be careful not to match Matching is wrong

1. Process selection method

When OOM Killer runs out of memory, it will view all processes and calculate scores for each process. Send the signal to the process with the highest score.

2. Method of calculating scores Previous page12Next page Total 2 pages

Copyright © Windows knowledge All Rights Reserved