Skip to content

Commit fe6bdfc

Browse files
Roman Gushchintorvalds
authored andcommitted
mm: fix oom_kill event handling
Commit e27be24 ("mm: memcg: make sure memory.events is uptodate when waking pollers") converted most of memcg event counters to per-memcg atomics, which made them less confusing for a user. The "oom_kill" counter remained untouched, so now it behaves differently than other counters (including "oom"). This adds nothing but confusion. Let's fix this by adding the MEMCG_OOM_KILL event, and follow the MEMCG_OOM approach. This also removes a hack from count_memcg_event_mm(), introduced earlier specially for the OOM_KILL counter. [akpm@linux-foundation.org: fix for droppage of memcg-replace-mm-owner-with-mm-memcg.patch] Link: http://lkml.kernel.org/r/20180508124637.29984-1-guro@fb.com Signed-off-by: Roman Gushchin <guro@fb.com> Acked-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d7dc899 commit fe6bdfc

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

‎include/linux/memcontrol.h‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum memcg_memory_event {
5353
MEMCG_HIGH,
5454
MEMCG_MAX,
5555
MEMCG_OOM,
56+
MEMCG_OOM_KILL,
5657
MEMCG_SWAP_MAX,
5758
MEMCG_SWAP_FAIL,
5859
MEMCG_NR_MEMORY_EVENTS,
@@ -720,11 +721,8 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
720721

721722
rcu_read_lock();
722723
memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
723-
if (likely(memcg)) {
724+
if (likely(memcg))
724725
count_memcg_events(memcg, idx, 1);
725-
if (idx == OOM_KILL)
726-
cgroup_file_notify(&memcg->events_file);
727-
}
728726
rcu_read_unlock();
729727
}
730728

@@ -735,6 +733,21 @@ static inline void memcg_memory_event(struct mem_cgroup *memcg,
735733
cgroup_file_notify(&memcg->events_file);
736734
}
737735

736+
static inline void memcg_memory_event_mm(struct mm_struct *mm,
737+
enum memcg_memory_event event)
738+
{
739+
struct mem_cgroup *memcg;
740+
741+
if (mem_cgroup_disabled())
742+
return;
743+
744+
rcu_read_lock();
745+
memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
746+
if (likely(memcg))
747+
memcg_memory_event(memcg, event);
748+
rcu_read_unlock();
749+
}
750+
738751
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
739752
void mem_cgroup_split_huge_fixup(struct page *head);
740753
#endif
@@ -756,6 +769,11 @@ static inline void memcg_memory_event(struct mem_cgroup *memcg,
756769
{
757770
}
758771

772+
static inline void memcg_memory_event_mm(struct mm_struct *mm,
773+
enum memcg_memory_event event)
774+
{
775+
}
776+
759777
static inline enum mem_cgroup_protection mem_cgroup_protected(
760778
struct mem_cgroup *root, struct mem_cgroup *memcg)
761779
{

‎mm/memcontrol.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,7 +3550,8 @@ static int mem_cgroup_oom_control_read(struct seq_file *sf, void *v)
35503550

35513551
seq_printf(sf, "oom_kill_disable %d\n", memcg->oom_kill_disable);
35523552
seq_printf(sf, "under_oom %d\n", (bool)memcg->under_oom);
3553-
seq_printf(sf, "oom_kill %lu\n", memcg_sum_events(memcg, OOM_KILL));
3553+
seq_printf(sf, "oom_kill %lu\n",
3554+
atomic_long_read(&memcg->memory_events[MEMCG_OOM_KILL]));
35543555
return 0;
35553556
}
35563557

@@ -5239,7 +5240,8 @@ static int memory_events_show(struct seq_file *m, void *v)
52395240
atomic_long_read(&memcg->memory_events[MEMCG_MAX]));
52405241
seq_printf(m, "oom %lu\n",
52415242
atomic_long_read(&memcg->memory_events[MEMCG_OOM]));
5242-
seq_printf(m, "oom_kill %lu\n", memcg_sum_events(memcg, OOM_KILL));
5243+
seq_printf(m, "oom_kill %lu\n",
5244+
atomic_long_read(&memcg->memory_events[MEMCG_OOM_KILL]));
52435245

52445246
return 0;
52455247
}

‎mm/oom_kill.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
913913

914914
/* Raise event before sending signal: task reaper must see this */
915915
count_vm_event(OOM_KILL);
916-
count_memcg_event_mm(mm, OOM_KILL);
916+
memcg_memory_event_mm(mm, MEMCG_OOM_KILL);
917917

918918
/*
919919
* We should send SIGKILL before granting access to memory reserves

0 commit comments

Comments
 (0)