Which signal does the oom killer send to kill the process?

 SOLUTION 已验证 - 已更新 2015年十二月22日22:06 - 

​English ​

环境

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

问题

  • Which signal does the ​​oom killer​​ send to kill the process?
  • Which signal (​​SIGTERM​​, ​​SIGKILL​​, other?) does the ​​oom killer​​ use to kill processes?

决议

Although the ​​oom killer​​ source code ​​mm/oom_kill.c​​ has many changes and will continue to have in future for optimise, Improvisation purposes. But the signal which is sent to the process in an event of a oom is still the ​​SIGKILL​​ signal. Please find the source code snippet from RHEL 6.6.

​Raw​

static int oom_kill_task(struct task_struct *p)
{
struct task_struct *q;
struct mm_struct *mm;

p = find_lock_task_mm(p);
if (!p)
return 1;

if (sysctl_would_have_oomkilled == 1) {
printk(KERN_ERR "Would have killed process %d (%s). But continuing instead.\n",
task_pid_nr(p), p->comm);
task_unlock(p);
return 0;
}

/* mm cannot be safely dereferenced after task_unlock(p) */
mm = p->mm;

pr_err("Killed process %d, UID %d, (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
task_pid_nr(p), task_uid(p), p->comm, K(p->mm->total_vm),
K(get_mm_counter(p->mm, anon_rss)),
K(get_mm_counter(p->mm, file_rss)));
task_unlock(p);

/*
* Kill all processes sharing p->mm in other thread groups, if any.
* They don't get access to memory reserves or a higher scheduler
* priority, though, to avoid depletion of all memory or task
* starvation. This prevents mm->mmap_sem livelock when an oom killed
* task cannot exit because it requires the semaphore and its contended
* by another thread trying to allocate memory itself. That thread will
* now get access to memory reserves since it has a pending fatal
* signal.
*/
for_each_process(q)
if (q->mm == mm && !same_thread_group(q, p)) {
task_lock(q); /* Protect ->comm from prctl() */
pr_err("Kill process %d (%s) sharing same memory\n",
task_pid_nr(q), q->comm);
task_unlock(q);
force_sig(SIGKILL, q);
}

set_tsk_thread_flag(p, TIF_MEMDIE);
force_sig(SIGKILL, p);

return 0;
}