[Devel] [PATCH RHEL9 COMMIT] memcg: fix oom_guarantee overdraft calculation in cgroup-v2

Konstantin Khorenko khorenko at virtuozzo.com
Tue Mar 26 16:48:42 MSK 2024


The commit is pushed to "branch-rh9-5.14.0-362.18.1.vz9.40.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-362.18.1.vz9.40.3
------>
commit 79882e58f54a8e4e99076db9d6792eae1eab680a
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Mon Mar 25 17:33:53 2024 +0800

    memcg: fix oom_guarantee overdraft calculation in cgroup-v2
    
    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: c31dabeaf42d ("memcg: add oom_guarantee")
    
    https://virtuozzo.atlassian.net/browse/PSBM-154224
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    Feature: mm/oom: OOM guarantee feature
---
 mm/memcontrol.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 2b6b7dd5a1c0..19abe1578093 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1503,7 +1503,10 @@ unsigned long mem_cgroup_overdraft(struct mem_cgroup *memcg)
 		return 0;
 
 	guarantee = READ_ONCE(memcg->oom_guarantee);
-	usage = page_counter_read(&memcg->memsw);
+	if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
+		usage = page_counter_read(&memcg->memory) + page_counter_read(&memcg->swap);
+	else
+		usage = page_counter_read(&memcg->memsw);
 	return usage > guarantee ? (usage - guarantee) : 0;
 }
 


More information about the Devel mailing list