[Devel] [PATCH RH9 2/4] mm/memcontrol: fix mem_cgroup_enough_memory on cgroup-v2

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Mon Aug 28 12:22:40 MSK 2023


In cgroup-v2 memsw is not used anymore, instead we have swap and memory
separated from one another. So memory limit should be read from
memory.max not from memsw.max.

https://jira.vzint.dev/browse/PSBM-149975
Fixes: 9417436f33d1 ("ve/mm: add heuristic check for memory overcommit")
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 mm/memcontrol.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9287eed944d5..cd11065cbe0d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4283,7 +4283,10 @@ static int mem_cgroup_enough_memory(struct mem_cgroup *memcg, long pages)
 	long free;
 
 	/* unused memory */
-	free = memcg->memsw.max - page_counter_read(&memcg->memory);
+	if (memcg->css.cgroup->root == &cgrp_dfl_root)
+		free = memcg->memory.max - page_counter_read(&memcg->memory);
+	else
+		free = memcg->memsw.max - page_counter_read(&memcg->memory);
 
 	/* reclaimable slabs */
 	free += memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) >> PAGE_SHIFT;
-- 
2.41.0



More information about the Devel mailing list