aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2014-01-23 15:53:34 -0800
committerMoyster <oysterized@gmail.com>2019-05-02 18:38:54 +0200
commite868f231e6c523309a5f5d36d11ec1abe33f5d1c (patch)
tree15027dd7843cc06b4e1221828649c795d2ea4a76
parent53be5bd234ee07a15ab99a42c0fc11a9e3a39e91 (diff)
mm, oom: prefer thread group leaders for display purposes
When two threads have the same badness score, it's preferable to kill the thread group leader so that the actual process name is printed to the kernel log rather than the thread group name which may be shared amongst several processes. This was the behavior when select_bad_process() used to do for_each_process(), but it now iterates threads instead and leads to ambiguity. Change-Id: I71ebfbeb4b030d3b4cc342d68af70526e29fd8d4 Signed-off-by: David Rientjes <rientjes@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Greg Thelen <gthelen@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/memcontrol.c19
-rw-r--r--mm/oom_kill.c12
2 files changed, 20 insertions, 11 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index bc733288f..d6d5a7ea9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1847,13 +1847,18 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
break;
};
points = oom_badness(task, memcg, NULL, totalpages);
- if (points > chosen_points) {
- if (chosen)
- put_task_struct(chosen);
- chosen = task;
- chosen_points = points;
- get_task_struct(chosen);
- }
+ if (!points || points < chosen_points)
+ continue;
+ /* Prefer thread group leaders for display purposes */
+ if (points == chosen_points &&
+ thread_group_leader(chosen))
+ continue;
+
+ if (chosen)
+ put_task_struct(chosen);
+ chosen = task;
+ chosen_points = points;
+ get_task_struct(chosen);
}
cgroup_iter_end(cgroup, &it);
}
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 46859d19e..fee5298ef 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -337,10 +337,14 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
break;
};
points = oom_badness(p, NULL, nodemask, totalpages);
- if (points > chosen_points) {
- chosen = p;
- chosen_points = points;
- }
+ if (!points || points < chosen_points)
+ continue;
+ /* Prefer thread group leaders for display purposes */
+ if (points == chosen_points && thread_group_leader(chosen))
+ continue;
+
+ chosen = p;
+ chosen_points = points;
}
if (chosen)
get_task_struct(chosen);