The memsw counter in cgroup-v2 is reused by swap counter and does not
include memory usage, we need to replace it with memory + swap.

Fixes: 0cfabaf0eedad ("proc,memcg: use memcg limits for showing oom_score
inside CT")

https://virtuozzo.atlassian.net/browse/VSTOR-104929

Signed-off-by: Konstantin Khorenko <khore...@virtuozzo.com>

Feature: mm/oom: per-CT oom_score virtualization
---
v2: emulate precise "memsw" calculation for cgroup v2 case, do not
    include additional calculation logic

 include/linux/memcontrol.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index f51d7f4df3059..9b766ef9f0585 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1008,11 +1008,17 @@ unsigned long mem_cgroup_get_zone_lru_size(struct 
lruvec *lruvec,
 
 static inline unsigned long mem_cgroup_total_pages(struct mem_cgroup *memcg)
 {
-       unsigned long ram, ram_swap;
+       unsigned long ram, memsw, ram_swap;
        extern long total_swap_pages;
 
        ram = min_t(unsigned long, totalram_pages(), memcg->memory.max);
-       ram_swap = min_t(unsigned long, memcg->memsw.max, ram + 
total_swap_pages);
+
+       if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
+               memsw = memcg->memory.max + memcg->swap.max;
+       else
+               memsw = memcg->memsw.max;
+
+       ram_swap = min_t(unsigned long, memsw, ram + total_swap_pages);
 
        return ram_swap;
 }
-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to