Skip to contentSkip to conversation

mm/oom_kill: count global and memory cgroup oom kills

PATCH Applied Konstantin Khlebnikov 6 participants 9 messages May 25, 2017 – Sep 13, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm/oom_kill: count global and memory cgroup oom kills

Show count of oom killer invocations in /proc/vmstat and count of processes killed in memory cgroup in knob "memory.events" (in memory.oom_control for v1 cgroup).

Also describe difference between "oom" and "oom_kill" in memory cgroup documentation. Currently oom in memory cgroup kills tasks iff shortage has happened inside page fault.

These counters helps in monitoring oom kills - for now the only way is grepping for magic words in kernel log.

---

v1: https://lkml.kernel.org/r/149520375057.74196.2843113275800730971.stgit@buzz

v2:
* count all oom kills in /proc/vmstat
* update counter for cgroup which tasks belongs to

---
 Documentation/cgroup-v2.txt   |   20 ++++++++++++++++----
 include/linux/memcontrol.h    |    5 ++++-
 include/linux/vm_event_item.h |    1 +
 mm/memcontrol.c               |    2 ++
 mm/oom_kill.c                 |    5 +++++
 mm/vmstat.c                   |    1 +
 6 files changed, 29 insertions(+), 5 deletions(-)
Documentation/cgroup-v2.txt +16 -4
index dc5e2dcdbef4..738b1c7023ad 100644
@@ -826,13 +826,25 @@ PAGE_SIZE multiple when read back.
 
 		The number of times the cgroup's memory usage was
 		about to go over the max boundary.  If direct reclaim
-		fails to bring it down, the OOM killer is invoked.
+		fails to bring it down, the cgroup goes to OOM state.
 
 	  oom
 
-		The number of times the OOM killer has been invoked in
-		the cgroup.  This may not exactly match the number of
-		processes killed but should generally be close.
+		The number of time the cgroup's memory usage was
+		reached the limit and allocation was about to fail.
+
+		Depending on context result could be invocation of OOM
+		killer and retrying allocation or failing alloction.
+
+		Failed allocation in its turn could be returned into
+		userspace as -ENOMEM or siletly ignored in cases like
+		disk readahead.	 For now OOM in memory cgroup kills
+		tasks iff shortage has happened inside page fault.
+
+	  oom_kill
+
+		The number of processes belonging to this cgroup
+		killed by any kind of OOM killer.
 
   memory.stat
 
include/linux/memcontrol.h +4 -1
index 899949bbb2f9..42296f7001da 100644
@@ -556,8 +556,11 @@ static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,
 
 	rcu_read_lock();
 	memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
-	if (likely(memcg))
+	if (likely(memcg)) {
 		this_cpu_inc(memcg->stat->events[idx]);
+		if (idx == OOM_KILL)
+			cgroup_file_notify(&memcg->events_file);
+	}
 	rcu_read_unlock();
 }
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
include/linux/vm_event_item.h +1 -0
index d84ae90ccd5c..1707e0a7d943 100644
@@ -41,6 +41,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 		KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY,
 		PAGEOUTRUN, PGROTATED,
 		DROP_PAGECACHE, DROP_SLAB,
+		OOM_KILL,
 #ifdef CONFIG_NUMA_BALANCING
 		NUMA_PTE_UPDATES,
 		NUMA_HUGE_PTE_UPDATES,
mm/memcontrol.c +2 -0
index 94172089f52f..7011ebf2b90e 100644
@@ -3574,6 +3574,7 @@ static int mem_cgroup_oom_control_read(struct seq_file *sf, void *v)
 
 	seq_printf(sf, "oom_kill_disable %d\n", memcg->oom_kill_disable);
 	seq_printf(sf, "under_oom %d\n", (bool)memcg->under_oom);
+	seq_printf(sf, "oom_kill %lu\n", memcg_sum_events(memcg, OOM_KILL));
 	return 0;
 }
 
@@ -5165,6 +5166,7 @@ static int memory_events_show(struct seq_file *m, void *v)
 	seq_printf(m, "high %lu\n", memcg_sum_events(memcg, MEMCG_HIGH));
 	seq_printf(m, "max %lu\n", memcg_sum_events(memcg, MEMCG_MAX));
 	seq_printf(m, "oom %lu\n", memcg_sum_events(memcg, MEMCG_OOM));
+	seq_printf(m, "oom_kill %lu\n", memcg_sum_events(memcg, OOM_KILL));
 
 	return 0;
 }
mm/oom_kill.c +5 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
 	/* Get a reference to safely compare mm after task_unlock(victim) */
 	mm = victim->mm;
 	mmgrab(mm);
+
+	/* Raise event before sending signal: reaper must see this */
+	count_vm_event(OOM_KILL);
+	mem_cgroup_count_vm_event(mm, OOM_KILL);
+
 	/*
 	 * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
 	 * the OOM victim from depleting the memory reserves from the user
mm/vmstat.c +1 -0
index 76f73670200a..fe80b81a86e0 100644
@@ -1018,6 +1018,7 @@ const char * const vmstat_text[] = {
 
 	"drop_pagecache",
 	"drop_slab",
+	"oom_kill",
 
 #ifdef CONFIG_NUMA_BALANCING
 	"numa_pte_updates",

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 880

Quoted 10 lines · Konstantin Khlebnikov
mm/oom_kill.c +2 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
 	/* Get a reference to safely compare mm after task_unlock(victim) */
 	mm = victim->mm;
 	mmgrab(mm);
+
+	/* Raise event before sending signal: reaper must see this */

How is the oom reaper involved here?

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 886

Quoted 6 lines
mm/oom_kill.c +3 -0
+	count_vm_event(OOM_KILL);
+	mem_cgroup_count_vm_event(mm, OOM_KILL);
+
 	/*
 	 * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
 	 * the OOM victim from depleting the memory reserves from the user

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 14 lines · David Rientjes

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 880

Quoted 10 lines · Konstantin Khlebnikov
mm/oom_kill.c +2 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
      /* Get a reference to safely compare mm after task_unlock(victim) */
      mm = victim->mm;
      mmgrab(mm);
+
+     /* Raise event before sending signal: reaper must see this */

How is the oom reaper involved here?

Task reaper - OOM event should happens before SIGCHLD.

Quoted 8 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 886

Quoted 7 lines
mm/oom_kill.c +3 -0
+     count_vm_event(OOM_KILL);
+     mem_cgroup_count_vm_event(mm, OOM_KILL);
+
      /*
       * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
       * the OOM victim from depleting the memory reserves from the user
Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer Acked-by on v2 1/1
#3 lore raw
In reply to Konstantin Khlebnikov
Quoted 10 lines · Konstantin Khlebnikov

Show count of oom killer invocations in /proc/vmstat and count of processes killed in memory cgroup in knob "memory.events" (in memory.oom_control for v1 cgroup).

Also describe difference between "oom" and "oom_kill" in memory cgroup documentation. Currently oom in memory cgroup kills tasks iff shortage has happened inside page fault.

These counters helps in monitoring oom kills - for now the only way is grepping for magic words in kernel log.

Yes this is less than optimal and the counter sounds like a good step forward. I have 2 comments to the patch though.

[...]

Quoted 5 lines
include/linux/memcontrol.h +0 -0
index 899949bbb2f9..42296f7001da 100644

include/linux/memcontrol.h static inline void mem_cgroup_count_vm_event(struct mm_struct *mm, · line 564

Quoted 10 lines
include/linux/memcontrol.h +4 -1
@@ -556,8 +556,11 @@ static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,
 
 	rcu_read_lock();
 	memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
-	if (likely(memcg))
+	if (likely(memcg)) {
 		this_cpu_inc(memcg->stat->events[idx]);
+		if (idx == OOM_KILL)
+			cgroup_file_notify(&memcg->events_file);
+	}
 	rcu_read_unlock();

Well, this is ugly. I see how you want to share the global counter and the memcg event which needs the notification. But I cannot say this would be really easy to follow. Can we have at least a comment in memcg_event_item enum definition?

Quoted 6 lines
mm/oom_kill.c +0 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
 	/* Get a reference to safely compare mm after task_unlock(victim) */

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 886

Quoted 10 lines
mm/oom_kill.c +5 -0
 	mm = victim->mm;
 	mmgrab(mm);
+
+	/* Raise event before sending signal: reaper must see this */
+	count_vm_event(OOM_KILL);
+	mem_cgroup_count_vm_event(mm, OOM_KILL);
+
 	/*
 	 * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
 	 * the OOM victim from depleting the memory reserves from the user

Why don't you count tasks which share mm with the oom victim?

mm/oom_kill.c +2 -0
index 0e2c925e7826..9a95947a60ba 100644
@@ -924,6 +924,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
 		 */
 		if (unlikely(p->flags & PF_KTHREAD))
 			continue;
+		count_vm_event(OOM_KILL);
+		count_memcg_event_mm(mm, OOM_KILL);
 		do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
 	}
 	rcu_read_unlock();

Other than that looks good to me.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw
Quoted 23 lines · Michal Hocko
Quoted 10 lines · Konstantin Khlebnikov

Show count of oom killer invocations in /proc/vmstat and count of processes killed in memory cgroup in knob "memory.events" (in memory.oom_control for v1 cgroup).

Also describe difference between "oom" and "oom_kill" in memory cgroup documentation. Currently oom in memory cgroup kills tasks iff shortage has happened inside page fault.

These counters helps in monitoring oom kills - for now the only way is grepping for magic words in kernel log.

Yes this is less than optimal and the counter sounds like a good step forward. I have 2 comments to the patch though.

[...]

Quoted 6 lines
include/linux/memcontrol.h +0 -0
index 899949bbb2f9..42296f7001da 100644
@@ -556,8 +556,11 @@ static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,
 
Quoted 14 lines

include/linux/memcontrol.h static inline void mem_cgroup_count_vm_event(struct mm_struct *mm, · line 564

Quoted 9 lines
include/linux/memcontrol.h +4 -1
  	rcu_read_lock();
  	memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
-	if (likely(memcg))
+	if (likely(memcg)) {
  		this_cpu_inc(memcg->stat->events[idx]);
+		if (idx == OOM_KILL)
+			cgroup_file_notify(&memcg->events_file);
+	}
  	rcu_read_unlock();

Well, this is ugly. I see how you want to share the global counter and the memcg event which needs the notification. But I cannot say this would be really easy to follow. Can we have at least a comment in memcg_event_item enum definition?

Yep, this is a little bit ugly.
But this funciton is static-inline and idx always constant so resulting code is fine.

Quoted 11 lines
Quoted 11 lines
mm/oom_kill.c +2 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
  	/* Get a reference to safely compare mm after task_unlock(victim) */
  	mm = victim->mm;
  	mmgrab(mm);
+
+	/* Raise event before sending signal: reaper must see this */
Quoted 8 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 886

Quoted 6 lines
mm/oom_kill.c +3 -0
+	count_vm_event(OOM_KILL);
+	mem_cgroup_count_vm_event(mm, OOM_KILL);
+
  	/*
  	 * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
  	 * the OOM victim from depleting the memory reserves from the user

Why don't you count tasks which share mm with the oom victim?

Yes, this makes sense. But these kills are not logged thus counter will differs from logged events. Also these tasks might live in different cgroups, so counting to mm owner isn't correct.

Quoted 14 lines
mm/oom_kill.c +2 -0
index 0e2c925e7826..9a95947a60ba 100644
@@ -924,6 +924,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
  		 */
  		if (unlikely(p->flags & PF_KTHREAD))
  			continue;
+		count_vm_event(OOM_KILL);
+		count_memcg_event_mm(mm, OOM_KILL);
  		do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
  	}
  	rcu_read_unlock();
Quoted 3 lines

Other than that looks good to me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#5 lore raw
Quoted 4 lines · Konstantin Khlebnikov
Quoted 1 line · Michal Hocko

On Thu 25-05-17 13:28:30, Konstantin Khlebnikov wrote:

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

index 04c9143a8625..dd30a045ef5b 100644

mm/oom_kill.c +2 -0
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
 	/* Get a reference to safely compare mm after task_unlock(victim) */
 	mm = victim->mm;
 	mmgrab(mm);
+
+	/* Raise event before sending signal: reaper must see this */
Quoted 8 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 886

Quoted 6 lines
mm/oom_kill.c +3 -0
+	count_vm_event(OOM_KILL);
+	mem_cgroup_count_vm_event(mm, OOM_KILL);
+
 	/*
 	 * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
 	 * the OOM victim from depleting the memory reserves from the user

Why don't you count tasks which share mm with the oom victim?

Quoted 2 lines

Yes, this makes sense. But these kills are not logged thus counter will differs from logged events.

Yes they are not but does that matter? Do we want _all_ or only some oom kills being counted.

Quoted 2 lines

Also these tasks might live in different cgroups, so counting to mm owner isn't correct.

Well, the situation with mm shared between different memcgs is always hairy. We try to charge mm->owner but I suspect we are not consistent in that. I would have to double check because it's been a long ago since I've investigated that. My point is that once you count OOM kills you should count all the tasks IMHO.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
In reply to Konstantin Khlebnikov

Hi,

I have submitted a similar patch 2 years ago (Oct/2015). But at that time the patch was rejected.
Here is the history:
https://lkml.org/lkml/2015/10/1/372

Now I see the similar patch got accepted. At least the initial idea and the objective were same. Even I were not included here.
On one side I feel happy that my initial idea got accepted now.But on the other side it really hurts :(

Thanks,Pintu

On Monday 5 June 2017, 7:57:57 PM IST, Konstantin Khlebnikov <[email protected]> wrote:

Quoted 29 lines · Michal Hocko
Quoted 10 lines · Konstantin Khlebnikov

Show count of oom killer invocations in /proc/vmstat and count of processes killed in memory cgroup in knob "memory.events" (in memory.oom_control for v1 cgroup).

Also describe difference between "oom" and "oom_kill" in memory cgroup documentation. Currently oom in memory cgroup kills tasks iff shortage has happened inside page fault.

These counters helps in monitoring oom kills - for now the only way is grepping for magic words in kernel log.

Yes this is less than optimal and the counter sounds like a good step forward. I have 2 comments to the patch though.

[...]

Quoted 12 lines
include/linux/memcontrol.h +0 -0
index 899949bbb2f9..42296f7001da 100644
@@ -556,8 +556,11 @@ static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,


      rcu_read_lock();
      memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); -    if (likely(memcg))
+    if (likely(memcg)) { this_cpu_inc(memcg->stat->events[idx]);
+        if (idx == OOM_KILL)

Quoted 8 lines
Quoted 3 lines

+            cgroup_file_notify(&memcg->events_file); +    }
      rcu_read_unlock();

Well, this is ugly. I see how you want to share the global counter and the memcg event which needs the notification. But I cannot say this would be really easy to follow. Can we have at least a comment in memcg_event_item enum definition?

Yep, this is a little bit ugly.
But this funciton is static-inline and idx always constant so resulting code is fine.

Quoted 11 lines
Quoted 11 lines
mm/oom_kill.c +2 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
       /* Get a reference to safely compare mm after task_unlock(victim) */
       mm = victim->mm;
       mmgrab(mm);
+
+    /* Raise event before sending signal: reaper must see this */
Quoted 8 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 886

Quoted 6 lines
mm/oom_kill.c +3 -0
+    count_vm_event(OOM_KILL);
+    mem_cgroup_count_vm_event(mm, OOM_KILL);
+
       /*
       * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
       * the OOM victim from depleting the memory reserves from the user

Why don't you count tasks which share mm with the oom victim?

Yes, this makes sense. But these kills are not logged thus counter will differs from logged events. Also these tasks might live in different cgroups, so counting to mm owner isn't correct.

Quoted 14 lines
mm/oom_kill.c +2 -0
index 0e2c925e7826..9a95947a60ba 100644
@@ -924,6 +924,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
           */
           if (unlikely(p->flags & PF_KTHREAD))
               continue;
+        count_vm_event(OOM_KILL);
+        count_memcg_event_mm(mm, OOM_KILL);
           do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
       }
       rcu_read_unlock();
Quoted 3 lines

Other than that looks good to me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 9 lines · PINTU KUMAR

Hi,

I have submitted a similar patch 2 years ago (Oct/2015). But at that time the patch was rejected.
Here is the history:
https://lkml.org/lkml/2015/10/1/372

Quoted 5 lines

Now I see the similar patch got accepted. At least the initial idea and the objective were same. Even I were not included here.
On one side I feel happy that my initial idea got accepted now.
But on the other side it really hurts :(

If this makes you feel better: mine version also fixes uncertainty in memory cgroup statistics.

Quoted 88 lines

Thanks,
Pintu

On Monday 5 June 2017, 7:57:57 PM IST, Konstantin Khlebnikov <[email protected]> wrote:

Quoted 23 lines · Michal Hocko
Quoted 10 lines · Konstantin Khlebnikov

Show count of oom killer invocations in /proc/vmstat and count of processes killed in memory cgroup in knob "memory.events" (in memory.oom_control for v1 cgroup).

Also describe difference between "oom" and "oom_kill" in memory cgroup documentation. Currently oom in memory cgroup kills tasks iff shortage has happened inside page fault.

These counters helps in monitoring oom kills - for now the only way is grepping for magic words in kernel log.

Yes this is less than optimal and the counter sounds like a good step forward. I have 2 comments to the patch though.

[...]

Quoted 6 lines
include/linux/memcontrol.h +0 -0
index 899949bbb2f9..42296f7001da 100644
@@ -556,8 +556,11 @@ static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,
 
Quoted 14 lines

include/linux/memcontrol.h static inline void mem_cgroup_count_vm_event(struct mm_struct *mm, · line 564

Quoted 9 lines
include/linux/memcontrol.h +4 -1
     rcu_read_lock();
     memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
-    if (likely(memcg))
+    if (likely(memcg)) {
         this_cpu_inc(memcg->stat->events[idx]);
+        if (idx == OOM_KILL)
+            cgroup_file_notify(&memcg->events_file);
+    }
     rcu_read_unlock();

Well, this is ugly. I see how you want to share the global counter and the memcg event which needs the notification. But I cannot say this would be really easy to follow. Can we have at least a comment in memcg_event_item enum definition?

Yep, this is a little bit ugly.
But this funciton is static-inline and idx always constant so resulting code is fine.

Quoted 11 lines
Quoted 11 lines
mm/oom_kill.c +2 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
     /* Get a reference to safely compare mm after task_unlock(victim) */
     mm = victim->mm;
     mmgrab(mm);
+
+    /* Raise event before sending signal: reaper must see this */
Quoted 8 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 886

Quoted 6 lines
mm/oom_kill.c +3 -0
+    count_vm_event(OOM_KILL);
+    mem_cgroup_count_vm_event(mm, OOM_KILL);
+
     /*
     * We should send SIGKILL before setting TIF_MEMDIE in order to prevent
     * the OOM victim from depleting the memory reserves from the user

Why don't you count tasks which share mm with the oom victim?

Yes, this makes sense. But these kills are not logged thus counter will differs from logged events. Also these tasks might live in different cgroups, so counting to mm owner isn't correct.

Quoted 14 lines
mm/oom_kill.c +2 -0
index 0e2c925e7826..9a95947a60ba 100644
@@ -924,6 +924,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
         */
         if (unlikely(p->flags & PF_KTHREAD))
             continue;
+        count_vm_event(OOM_KILL);
+        count_memcg_event_mm(mm, OOM_KILL);
         do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
     }
     rcu_read_unlock();
Quoted 10 lines
Quoted 3 lines

Other than that looks good to me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 18 lines · Konstantin Khlebnikov
Quoted 10 lines · PINTU KUMAR

Hi,

I have submitted a similar patch 2 years ago (Oct/2015). But at that time the patch was rejected.
Here is the history:
https://lkml.org/lkml/2015/10/1/372

Quoted 6 lines

Now I see the similar patch got accepted. At least the initial idea and the objective were same.
Even I were not included here.
On one side I feel happy that my initial idea got accepted now. But on the other side it really hurts :(

Quoted 3 lines

If this makes you feel better: mine version also fixes uncertainty in memory cgroup statistics.

Yes, my initial version was also just about global oom counter. And planning to add more later. But initial version itself was rejected. Sometimes its really painful to know how same ideas are treated differently :(

Anyways, thanks for this version. I think it is really helpful as per my experience.
Specially in production system where logs are disabled and no root access. But still we can access the /proc/vmstat fields. This was my point.

Quoted 108 lines
Quoted 101 lines

Thanks,
Pintu

On Monday 5 June 2017, 7:57:57 PM IST, Konstantin Khlebnikov <[email protected]> wrote:

Quoted 15 lines · Michal Hocko
Quoted 10 lines · Konstantin Khlebnikov

Show count of oom killer invocations in /proc/vmstat and count of processes killed in memory cgroup in knob "memory.events" (in memory.oom_control for v1 cgroup).

Also describe difference between "oom" and "oom_kill" in memory cgroup documentation. Currently oom in memory cgroup kills tasks iff shortage has happened inside page fault.

These counters helps in monitoring oom kills - for now the only way is grepping for magic words in kernel log.

Yes this is less than optimal and the counter sounds like a good step forward. I have 2 comments to the patch though.

Quoted 7 lines

[...]

include/linux/memcontrol.h static inline void

Quoted 5 lines
include/linux/memcontrol.h +0 -0
index 899949bbb2f9..42296f7001da 100644
@@ -556,8 +556,11 @@ static inline void

mem_cgroup_count_vm_event(struct mm_struct *mm,

Quoted 11 lines

include/linux/memcontrol.h static inline void · line 563

Quoted 10 lines
include/linux/memcontrol.h +4 -1
     rcu_read_lock();
     memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
-    if (likely(memcg))
+    if (likely(memcg)) {
         this_cpu_inc(memcg->stat->events[idx]);
+        if (idx == OOM_KILL)
+            cgroup_file_notify(&memcg->events_file);
+    }
     rcu_read_unlock();
Quoted 4 lines

Well, this is ugly. I see how you want to share the global counter and the memcg event which needs the notification. But I cannot say this would be really easy to follow. Can we have at least a comment in memcg_event_item enum definition?

Yep, this is a little bit ugly.
But this funciton is static-inline and idx always constant so resulting code is fine.

Quoted 6 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control

Quoted 6 lines
mm/oom_kill.c +0 -0
index 04c9143a8625..dd30a045ef5b 100644
@@ -876,6 +876,11 @@ static void oom_kill_process(struct oom_control

*oc, const char *message)

Quoted 1 line

mm/oom_kill.c static void oom_kill_process(struct oom_control · line 876

Quoted 1 line
mm/oom_kill.c +0 -0
     /* Get a reference to safely compare mm after task_unlock(victim)

*/

Quoted 9 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control · line 885

Quoted 9 lines
mm/oom_kill.c +5 -0
     mm = victim->mm;
     mmgrab(mm);
+
+    /* Raise event before sending signal: reaper must see this */
+    count_vm_event(OOM_KILL);
+    mem_cgroup_count_vm_event(mm, OOM_KILL);
+
     /*
     * We should send SIGKILL before setting TIF_MEMDIE in order to

prevent

Quoted 3 lines

mm/oom_kill.c static void oom_kill_process(struct oom_control · line 886

Quoted 1 line
mm/oom_kill.c +0 -0
     * the OOM victim from depleting the memory reserves from the user

Why don't you count tasks which share mm with the oom victim?

Yes, this makes sense. But these kills are not logged thus counter will differs from logged events.
Also these tasks might live in different cgroups, so counting to mm owner isn't correct.

mm/oom_kill.c static void oom_kill_process(struct oom_control

Quoted 5 lines
mm/oom_kill.c +0 -0
index 0e2c925e7826..9a95947a60ba 100644
@@ -924,6 +924,8 @@ static void oom_kill_process(struct oom_control

*oc, const char *message)

Quoted 9 lines
mm/oom_kill.c +2 -0
         */
         if (unlikely(p->flags & PF_KTHREAD))
             continue;
+        count_vm_event(OOM_KILL);
+        count_memcg_event_mm(mm, OOM_KILL);
         do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
     }
     rcu_read_unlock();
Quoted 3 lines

Other than that looks good to me.

Quoted 6 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>