Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memcg: print cgroup information when system panics due to panic_on_oom

If kernel panics due to oom, caused by a cgroup reaching its limit, when
'compulsory panic_on_oom' is enabled, then we will only see that the OOM
happened because of "compulsory panic_on_oom is enabled" but this doesn't
tell the difference between mempolicy and memcg. And dumping system wide
information is plain wrong and more confusing. This patch provides the
information of the cgroup whose limit triggerred panic

Signed-off-by: Balasubramani Vivekanandan <balasubramani_vivekanandan@mentor.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Balasubramani Vivekanandan and committed by
Linus Torvalds
2415b9f5 2a8e7002

+15 -11
+2 -1
include/linux/oom.h
··· 66 66 extern void oom_zonelist_unlock(struct zonelist *zonelist, gfp_t gfp_flags); 67 67 68 68 extern void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask, 69 - int order, const nodemask_t *nodemask); 69 + int order, const nodemask_t *nodemask, 70 + struct mem_cgroup *memcg); 70 71 71 72 extern enum oom_scan_t oom_scan_process_thread(struct task_struct *task, 72 73 unsigned long totalpages, const nodemask_t *nodemask,
+9 -7
mm/memcontrol.c
··· 1442 1442 struct mem_cgroup *iter; 1443 1443 unsigned int i; 1444 1444 1445 - if (!p) 1446 - return; 1447 - 1448 1445 mutex_lock(&oom_info_lock); 1449 1446 rcu_read_lock(); 1450 1447 1451 - pr_info("Task in "); 1452 - pr_cont_cgroup_path(task_cgroup(p, memory_cgrp_id)); 1453 - pr_cont(" killed as a result of limit of "); 1448 + if (p) { 1449 + pr_info("Task in "); 1450 + pr_cont_cgroup_path(task_cgroup(p, memory_cgrp_id)); 1451 + pr_cont(" killed as a result of limit of "); 1452 + } else { 1453 + pr_info("Memory limit reached of cgroup "); 1454 + } 1455 + 1454 1456 pr_cont_cgroup_path(memcg->css.cgroup); 1455 1457 pr_cont("\n"); 1456 1458 ··· 1539 1537 return; 1540 1538 } 1541 1539 1542 - check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, order, NULL); 1540 + check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, order, NULL, memcg); 1543 1541 totalpages = mem_cgroup_get_limit(memcg) ? : 1; 1544 1542 for_each_mem_cgroup_tree(iter, memcg) { 1545 1543 struct css_task_iter it;
+4 -3
mm/oom_kill.c
··· 612 612 * Determines whether the kernel must panic because of the panic_on_oom sysctl. 613 613 */ 614 614 void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask, 615 - int order, const nodemask_t *nodemask) 615 + int order, const nodemask_t *nodemask, 616 + struct mem_cgroup *memcg) 616 617 { 617 618 if (likely(!sysctl_panic_on_oom)) 618 619 return; ··· 626 625 if (constraint != CONSTRAINT_NONE) 627 626 return; 628 627 } 629 - dump_header(NULL, gfp_mask, order, NULL, nodemask); 628 + dump_header(NULL, gfp_mask, order, memcg, nodemask); 630 629 panic("Out of memory: %s panic_on_oom is enabled\n", 631 630 sysctl_panic_on_oom == 2 ? "compulsory" : "system-wide"); 632 631 } ··· 741 740 constraint = constrained_alloc(zonelist, gfp_mask, nodemask, 742 741 &totalpages); 743 742 mpol_mask = (constraint == CONSTRAINT_MEMORY_POLICY) ? nodemask : NULL; 744 - check_panic_on_oom(constraint, gfp_mask, order, mpol_mask); 743 + check_panic_on_oom(constraint, gfp_mask, order, mpol_mask, NULL); 745 744 746 745 if (sysctl_oom_kill_allocating_task && current->mm && 747 746 !oom_unkillable_task(current, NULL, nodemask) &&