[RHEL7,COMMIT] mm, memcg: add oom counter to memory.stat memcgroup file #PSBM-107731

Submitted by Vasily Averin on Sept. 23, 2020, 12:56 p.m.

Details

Message ID 202009231256.08NCu83c014898@vz7build.vvs.sw.ru
State New
Series "mm, memcg: add oom counter to memory.stat memcgroup file #PSBM-107731"
Headers show

Commit Message

Vasily Averin Sept. 23, 2020, 12:56 p.m.
The commit is pushed to "branch-rh7-3.10.0-1127.18.2.vz7.163.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.18.2.vz7.163.28
------>
commit 545507995ca12b24a7d1fd886a6c82b28bb47e2c
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date:   Wed Sep 23 15:56:08 2020 +0300

    mm, memcg: add oom counter to memory.stat memcgroup file #PSBM-107731
    
    Add oom counter to memory.stat file. oom shows amount of oom kills
    triggered due to cgroup's memory limit. total_oom shows total sum of
    oom kills triggered due to cgroup's and it's sub-groups memory limits.
    
    memory.stat in the root cgroup counts global oom kills.
    
    E.g:
     # mkdir /sys/fs/cgroup/memory/test/
     # echo 100M > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
     # echo 100M > /sys/fs/cgroup/memory/test/memory.memsw.limit_in_bytes
     # echo $$ > /sys/fs/cgroup/memory/test/tasks
     # ./vm-scalability/usemem -O 200M
     # grep oom /sys/fs/cgroup/memory/test/memory.stat
       oom 1
       total_oom 1
     # echo -1 > /sys/fs/cgroup/memory/test/memory.memsw.limit_in_bytes
     # echo -1 > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
     # ./vm-scalability/usemem -O 1000G
     # grep oom /sys/fs/cgroup/memory/memory.stat
        oom 1
        total_oom 2
    
    https://jira.sw.ru/browse/PSBM-107731
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/memcontrol.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 6587cc2..fe06c7d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -400,6 +400,7 @@  struct mem_cgroup {
 	struct mem_cgroup_stat_cpu __percpu *stat;
 	struct mem_cgroup_stat2_cpu stat2;
 	spinlock_t pcp_counter_lock;
+	atomic_long_t	oom;
 
 	atomic_t	dead_count;
 #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_INET)
@@ -2005,6 +2006,7 @@  void mem_cgroup_note_oom_kill(struct mem_cgroup *root_memcg,
 		if (memcg == root_memcg)
 			break;
 	}
+	atomic_long_inc(&root_memcg->oom);
 
 	if (memcg_to_put)
 		css_put(&memcg_to_put->css);
@@ -5691,6 +5693,7 @@  static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,
 	for (i = 0; i < MEM_CGROUP_EVENTS_NSTATS; i++)
 		seq_printf(m, "%s %lu\n", mem_cgroup_events_names[i],
 			   mem_cgroup_read_events(memcg, i));
+	seq_printf(m, "oom %lu\n", atomic_long_read(&memcg->oom));
 
 	for (i = 0; i < NR_LRU_LISTS; i++)
 		seq_printf(m, "%s %lu\n", mem_cgroup_lru_names[i],
@@ -5733,6 +5736,12 @@  static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,
 		seq_printf(m, "total_%s %llu\n",
 			   mem_cgroup_events_names[i], val);
 	}
+	{
+		unsigned long val = 0;
+		for_each_mem_cgroup_tree(mi, memcg)
+			val += atomic_long_read(&mi->oom);
+		seq_printf(m, "total_oom %lu\n", val);
+	}
 
 	for (i = 0; i < NR_LRU_LISTS; i++) {
 		unsigned long long val = 0;