Does setting an oom_score_adj of -1000 actually make a task immune to the kernel's oom_killer?
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- Red Hat OpenShift 4
Issue
- If a task's
oom_score_adjvalue is set to-1000, does this make the task the least likely to be killed, or make it completely immune to theoom_killercompletely when it is invoked?
Resolution
- Setting the processes
oom_score_adjto-1000does actually make a process unkillable by theoom_killerwhen it is invoked. - Be very careful with setting processes to being immune to the
oom_killer,
Root Cause
- When the
oom_killeris invoked, theoom_evaluate_taskfunction is invoked and theoom_badnessfunction is checked to get a score for a process's ability to be killed:
static int oom_evaluate_task(struct task_struct *task, void *arg)
[...]
points = oom_badness(task, oc->totalpages);
if (points == LONG_MIN || points < oc->chosen_points)
goto next;
- When the process is evaluated in
oom_badness, there are three conditions that exclude a process from being evaluated; it either has aoom_score_adjofOOM_SCORE_ADJ_MINwhich correlates to-1000, it is in the middle of a forking operation, or it is flagged as being unkillable (such as is the case with kernel threads):
long oom_badness(struct task_struct *p, unsigned long totalpages)
[...]
adj = (long)p->signal->oom_score_adj;
if (adj == OOM_SCORE_ADJ_MIN ||
test_bit(MMF_OOM_SKIP, &p->mm->flags) ||
in_vfork(p)) {
task_unlock(p);
return LONG_MIN;
}
- Since
-1000causes this to returnLONG_MIN, which is a-1, theoom_evaluate_taskfunction will skip this task from being considered in the list of tasks that can be killed.
SBR
Product(s)
Components
Category
Tags
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.