M.2 Detecting and Recovering From OOM 700
M.2.1 Function: out_of_memory() 700
M.2.2 Function: oom_kill() 701
M.2.3 Function: select_bad_process() 702
M.2.4 Function: badness() 703
M.2.5 Function: oom_kill_task() 704
M.2.1 Function: out_of_memory() (mm/oomkill.c) 202 void out_of_memory(void)
204 static unsigned long first, last, count, lastkill;
205 unsigned long now, since;
213 now = jiffies;
223 goto reset;
245 since = now - lastkill;
252 lastkill = now;
210-211 If there are available swap slots, the system has no OOM.
213-215 Records what time it is now in jiffies and determines how long it has been since this function was last called.
222-223 If it has been more than 5 seconds since this function was last called, this resets the timer and exits the function.
229-231 If it has been longer than a second since this function was last called, this exits the function. It is possible that I/O is in progress, which will complete soon.
237-238 If the function has not been called 10 times within the last short interval, the system is not yet OOM.
245-247 If a process has been killed within the last 5 seconds, this exits the function because the dying process is likely to free memory.
253 Ok, the system really is OOM, so it calls oom_kill() (See Section M.2.2) to select a process to kill.
This function first calls select_bad_process() to find a suitable process to kill.
Once found, the task list is traversed, and the oom_kill_task() is called for the selected process and all its threads.
172 static void oom_kill(void)
174 struct task_struct *p, *q;
179 /* Found nothing?!?! Either we hang forever, or we panic. */
181 panic("Out of memory and no killable processes...\n");
183 /* kill all processes that share the ->mm (i.e. all threads) */
191 * Make kswapd go out of the way, so "p" has a good chance of
192 * killing itself before someone else gets the chance to ask
193 * for more memory.
Was this article helpful?