Does setting an oom_score_adj of -1000 actually make a task immune to the kernel's oom_killer?

Solution Unverified - Updated

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_adj value is set to -1000, does this make the task the least likely to be killed, or make it completely immune to the oom_killer completely when it is invoked?

Resolution

  • Setting the processes oom_score_adj to -1000 does actually make a process unkillable by the oom_killer when it is invoked.
  • Be very careful with setting processes to being immune to the oom_killer,

Root Cause

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;
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 -1000 causes this to return LONG_MIN, which is a -1, the oom_evaluate_task function will skip this task from being considered in the list of tasks that can be killed.
SBR
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.