Commit 5eee7e1c authored by Shakeel Butt's avatar Shakeel Butt Committed by Linus Torvalds

mm, oom: refactor dump_tasks for memcg OOMs

dump_tasks() traverses all the existing processes even for the memcg OOM
context which is not only unnecessary but also wasteful.  This imposes a
long RCU critical section even from a contained context which can be quite
disruptive.

Change dump_tasks() to be aligned with select_bad_process and use
mem_cgroup_scan_tasks to selectively traverse only processes of the target
memcg hierarchy during memcg OOM.

Link: http://lkml.kernel.org/r/20190617231207.160865-1-shakeelb@google.comSigned-off-by: default avatarShakeel Butt <shakeelb@google.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Acked-by: default avatarRoman Gushchin <guro@fb.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Nick Piggin <npiggin@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f168a9a5
...@@ -382,28 +382,13 @@ static void select_bad_process(struct oom_control *oc) ...@@ -382,28 +382,13 @@ static void select_bad_process(struct oom_control *oc)
oc->chosen_points = oc->chosen_points * 1000 / oc->totalpages; oc->chosen_points = oc->chosen_points * 1000 / oc->totalpages;
} }
/** static int dump_task(struct task_struct *p, void *arg)
* dump_tasks - dump current memory state of all system tasks
* @memcg: current's memory controller, if constrained
* @nodemask: nodemask passed to page allocator for mempolicy ooms
*
* Dumps the current memory state of all eligible tasks. Tasks not in the same
* memcg, not in the same cpuset, or bound to a disjoint set of mempolicy nodes
* are not shown.
* State information includes task's pid, uid, tgid, vm size, rss,
* pgtables_bytes, swapents, oom_score_adj value, and name.
*/
static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask)
{ {
struct task_struct *p; struct oom_control *oc = arg;
struct task_struct *task; struct task_struct *task;
pr_info("Tasks state (memory values in pages):\n"); if (oom_unkillable_task(p, NULL, oc->nodemask))
pr_info("[ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name\n"); return 0;
rcu_read_lock();
for_each_process(p) {
if (oom_unkillable_task(p, memcg, nodemask))
continue;
task = find_lock_task_mm(p); task = find_lock_task_mm(p);
if (!task) { if (!task) {
...@@ -412,7 +397,7 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask) ...@@ -412,7 +397,7 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask)
* detached their mm's. There's no need to report * detached their mm's. There's no need to report
* them; they can't be oom killed anyway. * them; they can't be oom killed anyway.
*/ */
continue; return 0;
} }
pr_info("[%7d] %5d %5d %8lu %8lu %8ld %8lu %5hd %s\n", pr_info("[%7d] %5d %5d %8lu %8lu %8ld %8lu %5hd %s\n",
...@@ -422,8 +407,35 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask) ...@@ -422,8 +407,35 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask)
get_mm_counter(task->mm, MM_SWAPENTS), get_mm_counter(task->mm, MM_SWAPENTS),
task->signal->oom_score_adj, task->comm); task->signal->oom_score_adj, task->comm);
task_unlock(task); task_unlock(task);
}
return 0;
}
/**
* dump_tasks - dump current memory state of all system tasks
* @oc: pointer to struct oom_control
*
* Dumps the current memory state of all eligible tasks. Tasks not in the same
* memcg, not in the same cpuset, or bound to a disjoint set of mempolicy nodes
* are not shown.
* State information includes task's pid, uid, tgid, vm size, rss,
* pgtables_bytes, swapents, oom_score_adj value, and name.
*/
static void dump_tasks(struct oom_control *oc)
{
pr_info("Tasks state (memory values in pages):\n");
pr_info("[ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name\n");
if (is_memcg_oom(oc))
mem_cgroup_scan_tasks(oc->memcg, dump_task, oc);
else {
struct task_struct *p;
rcu_read_lock();
for_each_process(p)
dump_task(p, oc);
rcu_read_unlock(); rcu_read_unlock();
}
} }
static void dump_oom_summary(struct oom_control *oc, struct task_struct *victim) static void dump_oom_summary(struct oom_control *oc, struct task_struct *victim)
...@@ -455,7 +467,7 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) ...@@ -455,7 +467,7 @@ static void dump_header(struct oom_control *oc, struct task_struct *p)
dump_unreclaimable_slab(); dump_unreclaimable_slab();
} }
if (sysctl_oom_dump_tasks) if (sysctl_oom_dump_tasks)
dump_tasks(oc->memcg, oc->nodemask); dump_tasks(oc);
if (p) if (p)
dump_oom_summary(oc, p); dump_oom_summary(oc, p);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment