Skip to content

Commit 26ebc98

Browse files
kosakitorvalds
authored andcommitted
oom: /proc/<pid>/oom_score treat kernel thread honestly
If a kernel thread is using use_mm(), badness() returns a positive value. This is not a big issue because caller take care of it correctly. But there is one exception, /proc/<pid>/oom_score calls badness() directly and doesn't care that the task is a regular process. Another example, /proc/1/oom_score return !0 value. But it's unkillable. This incorrectness makes administration a little confusing. This patch fixes it. Signed-off-by: KOSAKI Motohiro <[email protected]> Cc: 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 f88ccad commit 26ebc98

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

fs/proc/base.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ static const struct file_operations proc_lstats_operations = {
428428
#endif
429429

430430
/* The badness from the OOM killer */
431-
unsigned long badness(struct task_struct *p, unsigned long uptime);
431+
unsigned long badness(struct task_struct *p, struct mem_cgroup *mem,
432+
nodemask_t *nodemask, unsigned long uptime);
432433
static int proc_oom_score(struct task_struct *task, char *buffer)
433434
{
434435
unsigned long points = 0;
@@ -437,7 +438,7 @@ static int proc_oom_score(struct task_struct *task, char *buffer)
437438
do_posix_clock_monotonic_gettime(&uptime);
438439
read_lock(&tasklist_lock);
439440
if (pid_alive(task))
440-
points = badness(task, uptime.tv_sec);
441+
points = badness(task, NULL, NULL, uptime.tv_sec);
441442
read_unlock(&tasklist_lock);
442443
return sprintf(buffer, "%lu\n", points);
443444
}

mm/oom_kill.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static bool oom_unkillable_task(struct task_struct *p, struct mem_cgroup *mem,
139139
* algorithm has been meticulously tuned to meet the principle
140140
* of least surprise ... (be careful when you change it)
141141
*/
142-
143-
unsigned long badness(struct task_struct *p, unsigned long uptime)
142+
unsigned long badness(struct task_struct *p, struct mem_cgroup *mem,
143+
const nodemask_t *nodemask, unsigned long uptime)
144144
{
145145
unsigned long points, cpu_time, run_time;
146146
struct task_struct *child;
@@ -150,6 +150,8 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
150150
unsigned long utime;
151151
unsigned long stime;
152152

153+
if (oom_unkillable_task(p, mem, nodemask))
154+
return 0;
153155
if (oom_adj == OOM_DISABLE)
154156
return 0;
155157

@@ -351,7 +353,7 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
351353
if (p->signal->oom_adj == OOM_DISABLE)
352354
continue;
353355

354-
points = badness(p, uptime.tv_sec);
356+
points = badness(p, mem, nodemask, uptime.tv_sec);
355357
if (points > *ppoints || !chosen) {
356358
chosen = p;
357359
*ppoints = points;
@@ -482,11 +484,10 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
482484

483485
if (child->mm == p->mm)
484486
continue;
485-
if (oom_unkillable_task(p, mem, nodemask))
486-
continue;
487487

488488
/* badness() returns 0 if the thread is unkillable */
489-
child_points = badness(child, uptime.tv_sec);
489+
child_points = badness(child, mem, nodemask,
490+
uptime.tv_sec);
490491
if (child_points > victim_points) {
491492
victim = child;
492493
victim_points = child_points;

0 commit comments

Comments
 (0)