Prologue: History has become the past, but the past has been buried in the invisible sand, can not become a history
Code storage:/mm/oom_kill.c main function: void out_of_memory (int gfp_mask) The main functions are as follows: 1) call select_bad_process (void) function to return the selected deleted process Task_ struct struct 2) calls the oom_kill_process (struct task_struct *p) function to send a termination signal to the process description: select_bad_process (void) iterates through all the processes (except for process 1). The budget value of the current process is counted according to a certain algorithm, and the process descriptor with the largest budget value is returned. Where the badness function is called to count the budget values for each process. For the badness function, depending on the amount of memory consumed, the startup usage time and CPU time, whether it is the root process, especially the direct access to the hardware, so in fact, we may need to adapt to our own system. In fact, this is very unusual. Auxiliary function Description: oom_kill_process (struct task_struct *p) does not terminate the parent process, but terminates a child process in the parent process, and then exits, if the current parent process does not have child processes, attempt to terminate itself. So the process of termination may not be able to solve the problem. Of course, it is likely to be called multiple times, but it does not necessarily solve the problem.
Oom-kill Kernel Source Analysis