[Devel] [PATCH VZ9 2/3] memcg: fix oom_guarantee overdraft calculation in cgroup-v2

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Fri Mar 22 08:21:35 MSK 2024


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.

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 8ca27af8d902..fcc4b24ba330 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;
 }
 
-- 
2.43.0



More information about the Devel mailing list