[Devel] [PATCH RH8] mm/memcontrol: fix oom counting

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Fri Jun 18 18:34:45 MSK 2021


Fix oom_total in /sys/fs/cgroup/memory/memory.stat being always zero due to
incrementing pointer instead of value in accumulate_ooms()
Drop cond_resched() - looks like an overkill to call it after each two
atomic_long_read()

Fixes: 64e8dc809dd9 ("mm, memcg: Fix "add oom counter to memory.stat memcgroup file"")
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 mm/memcontrol.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 05058ef..329223b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4184,19 +4184,19 @@ static ssize_t memcg_numa_migrate_write(struct kernfs_open_file *of, char *buf,
 	PSWPOUT,
 };
 
-static void accumulate_ooms(struct mem_cgroup *memcg, unsigned long *total_oom,
-			unsigned long *total_oom_kill)
+static void accumulate_ooms(struct mem_cgroup *memcg, unsigned long *oom,
+			unsigned long *kill)
 {
 	struct mem_cgroup *mi;
-
-	total_oom_kill = total_oom = 0;
+	unsigned long total_oom_kill = 0, total_oom = 0;
 
 	for_each_mem_cgroup_tree(mi, memcg) {
 		total_oom += atomic_long_read(&mi->memory_events[MEMCG_OOM]);
 		total_oom_kill += atomic_long_read(&mi->memory_events[MEMCG_OOM_KILL]);
-
-		cond_resched();
 	}
+
+	*oom = total_oom;
+	*kill = total_oom_kill;
 }
 
 static int memcg_stat_show(struct seq_file *m, void *v)
-- 
1.8.3.1



More information about the Devel mailing list