[Devel] [PATCH RH9 v2 3/5] mm/memcontrol: fix mem_cgroup_enough_memory on cgroup-v2

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Wed Sep 6 06:14:07 MSK 2023


In cgroup-v2 memsw is not used anymore, instead we have swap and memory
separated from one another. So let's replace memsw to mem+swap.

https://jira.vzint.dev/browse/PSBM-149975
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
v2: should use mem+swap instead of just mem here
---
 mm/memcontrol.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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



More information about the Devel mailing list