Skip to content

Commit 93b43fa

Browse files
Luis Claudio R. Goncalvestorvalds
authored andcommitted
oom: give the dying task a higher priority
In a system under heavy load it was observed that even after the oom-killer selects a task to die, the task may take a long time to die. Right after sending a SIGKILL to the task selected by the oom-killer this task has its priority increased so that it can exit() soon, freeing memory. That is accomplished by: /* * We give our sacrificial lamb high priority and access to * all the memory it needs. That way it should be able to * exit() and clear out its resources quickly... */ p->rt.time_slice = HZ; set_tsk_thread_flag(p, TIF_MEMDIE); It sounds plausible giving the dying task an even higher priority to be sure it will be scheduled sooner and free the desired memory. It was suggested on LKML using SCHED_FIFO:1, the lowest RT priority so that this task won't interfere with any running RT task. If the dying task is already an RT task, leave it untouched. Another good suggestion, implemented here, was to avoid boosting the dying task priority in case of mem_cgroup OOM. Signed-off-by: Luis Claudio R. Goncalves <[email protected]> Signed-off-by: KOSAKI Motohiro <[email protected]> Reviewed-by: Minchan Kim <[email protected]> Cc: David Rientjes <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Cc: Oleg Nesterov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 19b4586 commit 93b43fa

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

mm/oom_kill.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
8181
}
8282
#endif /* CONFIG_NUMA */
8383

84+
/*
85+
* If this is a system OOM (not a memcg OOM) and the task selected to be
86+
* killed is not already running at high (RT) priorities, speed up the
87+
* recovery by boosting the dying task to the lowest FIFO priority.
88+
* That helps with the recovery and avoids interfering with RT tasks.
89+
*/
90+
static void boost_dying_task_prio(struct task_struct *p,
91+
struct mem_cgroup *mem)
92+
{
93+
struct sched_param param = { .sched_priority = 1 };
94+
95+
if (mem)
96+
return;
97+
98+
if (!rt_task(p))
99+
sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
100+
}
101+
84102
/*
85103
* The process p may have detached its own ->mm while exiting or through
86104
* use_mm(), but one or more of its subthreads may still have a valid
@@ -421,7 +439,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
421439
}
422440

423441
#define K(x) ((x) << (PAGE_SHIFT-10))
424-
static int oom_kill_task(struct task_struct *p)
442+
static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
425443
{
426444
p = find_lock_task_mm(p);
427445
if (!p) {
@@ -434,9 +452,17 @@ static int oom_kill_task(struct task_struct *p)
434452
K(get_mm_counter(p->mm, MM_FILEPAGES)));
435453
task_unlock(p);
436454

437-
p->rt.time_slice = HZ;
455+
438456
set_tsk_thread_flag(p, TIF_MEMDIE);
439457
force_sig(SIGKILL, p);
458+
459+
/*
460+
* We give our sacrificial lamb high priority and access to
461+
* all the memory it needs. That way it should be able to
462+
* exit() and clear out its resources quickly...
463+
*/
464+
boost_dying_task_prio(p, mem);
465+
440466
return 0;
441467
}
442468
#undef K
@@ -460,6 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
460486
*/
461487
if (p->flags & PF_EXITING) {
462488
set_tsk_thread_flag(p, TIF_MEMDIE);
489+
boost_dying_task_prio(p, mem);
463490
return 0;
464491
}
465492

@@ -489,7 +516,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
489516
}
490517
} while_each_thread(p, t);
491518

492-
return oom_kill_task(victim);
519+
return oom_kill_task(victim, mem);
493520
}
494521

495522
/*
@@ -670,6 +697,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
670697
*/
671698
if (fatal_signal_pending(current)) {
672699
set_thread_flag(TIF_MEMDIE);
700+
boost_dying_task_prio(current, NULL);
673701
return;
674702
}
675703

0 commit comments

Comments
 (0)