[Devel] [PATCH rh7] memcg: fix swap_max calculation for nested cgroups

Vladimir Davydov vdavydov at parallels.com
Fri Jul 31 04:51:24 PDT 2015


If there is a sub-memcg in a container, its swapout won't update
swap_max of the container's memcg, because we don't ascend the memcg
hierarchy in mem_cgroup_update_swap_max. This patch fixes this issue.

Fixes: a74376e2dde13 ("bc/memcg: show correct swap max for beancounters")
Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 mm/memcontrol.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index dd3493073a2f..6a3ec8f3f276 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -903,12 +903,14 @@ static void mem_cgroup_update_swap_max(struct mem_cgroup *memcg)
 {
 	long long swap;
 
-	swap = res_counter_read_u64(&memcg->memsw, RES_USAGE) -
-		res_counter_read_u64(&memcg->res, RES_USAGE);
+	for (; memcg; memcg = parent_mem_cgroup(memcg)) {
+		swap = res_counter_read_u64(&memcg->memsw, RES_USAGE) -
+			res_counter_read_u64(&memcg->res, RES_USAGE);
 
-	/* This is racy, but we don't have to be absolutely precise */
-	if (swap > (long long)memcg->swap_max)
-		memcg->swap_max = swap;
+		/* This is racy, but we don't have to be absolutely precise */
+		if (swap > (long long)memcg->swap_max)
+			memcg->swap_max = swap;
+	}
 }
 
 static void mem_cgroup_inc_failcnt(struct mem_cgroup *memcg,
-- 
2.1.4




More information about the Devel mailing list