Skip to content

Commit f0c867d

Browse files
yuzhoujiantorvalds
authored andcommitted
mm, oom: add oom victim's memcg to the oom context information
The current oom report doesn't display victim's memcg context during the global OOM situation. While this information is not strictly needed, it can be really helpful for containerized environments to locate which container has lost a process. Now that we have a single line for the oom context, we can trivially add both the oom memcg (this can be either global_oom or a specific memcg which hits its hard limits) and task_memcg which is the victim's memcg. Below is the single line output in the oom report after this patch. - global oom context information: oom-kill:constraint=<constraint>,nodemask=<nodemask>,cpuset=<cpuset>,mems_allowed=<mems_allowed>,global_oom,task_memcg=<memcg>,task=<comm>,pid=<pid>,uid=<uid> - memcg oom context information: oom-kill:constraint=<constraint>,nodemask=<nodemask>,cpuset=<cpuset>,mems_allowed=<mems_allowed>,oom_memcg=<memcg>,task_memcg=<memcg>,task=<comm>,pid=<pid>,uid=<uid> [[email protected]: use pr_cont() in mem_cgroup_print_oom_context()] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: yuzhoujian <[email protected]> Signed-off-by: Tetsuo Handa <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: David Rientjes <[email protected]> Cc: "Kirill A . Shutemov" <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Yang Shi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ef8444e commit f0c867d

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

include/linux/memcontrol.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,11 @@ void mem_cgroup_handle_over_high(void);
526526

527527
unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg);
528528

529-
void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
529+
void mem_cgroup_print_oom_context(struct mem_cgroup *memcg,
530530
struct task_struct *p);
531531

532+
void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg);
533+
532534
static inline void mem_cgroup_enter_user_fault(void)
533535
{
534536
WARN_ON(current->in_user_fault);
@@ -970,7 +972,12 @@ static inline unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
970972
}
971973

972974
static inline void
973-
mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
975+
mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p)
976+
{
977+
}
978+
979+
static inline void
980+
mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg)
974981
{
975982
}
976983

mm/memcontrol.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,32 +1293,39 @@ static const char *const memcg1_stat_names[] = {
12931293

12941294
#define K(x) ((x) << (PAGE_SHIFT-10))
12951295
/**
1296-
* mem_cgroup_print_oom_info: Print OOM information relevant to memory controller.
1296+
* mem_cgroup_print_oom_context: Print OOM information relevant to
1297+
* memory controller.
12971298
* @memcg: The memory cgroup that went over limit
12981299
* @p: Task that is going to be killed
12991300
*
13001301
* NOTE: @memcg and @p's mem_cgroup can be different when hierarchy is
13011302
* enabled
13021303
*/
1303-
void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
1304+
void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p)
13041305
{
1305-
struct mem_cgroup *iter;
1306-
unsigned int i;
1307-
13081306
rcu_read_lock();
13091307

1308+
if (memcg) {
1309+
pr_cont(",oom_memcg=");
1310+
pr_cont_cgroup_path(memcg->css.cgroup);
1311+
} else
1312+
pr_cont(",global_oom");
13101313
if (p) {
1311-
pr_info("Task in ");
1314+
pr_cont(",task_memcg=");
13121315
pr_cont_cgroup_path(task_cgroup(p, memory_cgrp_id));
1313-
pr_cont(" killed as a result of limit of ");
1314-
} else {
1315-
pr_info("Memory limit reached of cgroup ");
13161316
}
1317-
1318-
pr_cont_cgroup_path(memcg->css.cgroup);
1319-
pr_cont("\n");
1320-
13211317
rcu_read_unlock();
1318+
}
1319+
1320+
/**
1321+
* mem_cgroup_print_oom_meminfo: Print OOM memory information relevant to
1322+
* memory controller.
1323+
* @memcg: The memory cgroup that went over limit
1324+
*/
1325+
void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg)
1326+
{
1327+
struct mem_cgroup *iter;
1328+
unsigned int i;
13221329

13231330
pr_info("memory: usage %llukB, limit %llukB, failcnt %lu\n",
13241331
K((u64)page_counter_read(&memcg->memory)),

mm/oom_kill.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ static void dump_oom_summary(struct oom_control *oc, struct task_struct *victim)
435435
oom_constraint_text[oc->constraint],
436436
nodemask_pr_args(oc->nodemask));
437437
cpuset_print_current_mems_allowed();
438+
mem_cgroup_print_oom_context(oc->memcg, victim);
438439
pr_cont(",task=%s,pid=%d,uid=%d\n", victim->comm, victim->pid,
439440
from_kuid(&init_user_ns, task_uid(victim)));
440441
}
@@ -449,7 +450,7 @@ static void dump_header(struct oom_control *oc, struct task_struct *p)
449450

450451
dump_stack();
451452
if (is_memcg_oom(oc))
452-
mem_cgroup_print_oom_info(oc->memcg, p);
453+
mem_cgroup_print_oom_meminfo(oc->memcg);
453454
else {
454455
show_mem(SHOW_MEM_FILTER_NODES, oc->nodemask);
455456
if (is_dump_unreclaim_slabs())

0 commit comments

Comments
 (0)