[Devel] [PATCH rh7] memcg/ub: fix limit > RESOURCE_MAX case

Vladimir Davydov vdavydov at parallels.com
Fri Jun 26 04:59:21 PDT 2015


A memcg limit can be greater than RESOURCE_MAX (LLONG_MAX), because it
is rounded up to PAGE_SIZE. As a result, we will show huge numbers in
meminfo for unlimited containers instead of the host's configuration.
Fix this by making all limit-vs-RESOURCE_MAX comparisons use
greater-or-equal sign.

Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 mm/memcontrol.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index cb153ac4567b..50eefe355d2c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1648,7 +1648,7 @@ unsigned long mem_cgroup_total_pages(struct mem_cgroup *memcg, bool swap)
 
 	limit = swap ? res_counter_read_u64(&memcg->memsw, RES_LIMIT) :
 			res_counter_read_u64(&memcg->res, RES_LIMIT);
-	if (limit == RESOURCE_MAX)
+	if (limit >= RESOURCE_MAX)
 		return ULONG_MAX;
 	return min_t(unsigned long long, ULONG_MAX, limit >> PAGE_SHIFT);
 }
@@ -5388,7 +5388,7 @@ void mem_cgroup_sync_beancounter(struct mem_cgroup *memcg,
 	p->maxheld = res_counter_read_u64(&memcg->res, RES_MAX_USAGE) >> PAGE_SHIFT;
 	p->failcnt = atomic_long_read(&memcg->mem_failcnt);
 	lim = res_counter_read_u64(&memcg->res, RES_LIMIT);
-	lim = lim == RESOURCE_MAX ? UB_MAXVALUE :
+	lim = lim >= RESOURCE_MAX ? UB_MAXVALUE :
 		min_t(unsigned long long, lim >> PAGE_SHIFT, UB_MAXVALUE);
 	p->barrier = p->limit = lim;
 
@@ -5396,7 +5396,7 @@ void mem_cgroup_sync_beancounter(struct mem_cgroup *memcg,
 	k->maxheld = res_counter_read_u64(&memcg->kmem, RES_MAX_USAGE);
 	k->failcnt = res_counter_read_u64(&memcg->kmem, RES_FAILCNT);
 	lim = res_counter_read_u64(&memcg->kmem, RES_LIMIT);
-	lim = lim == RESOURCE_MAX ? UB_MAXVALUE :
+	lim = lim >= RESOURCE_MAX ? UB_MAXVALUE :
 		min_t(unsigned long long, lim, UB_MAXVALUE);
 	k->barrier = k->limit = lim;
 
@@ -5410,7 +5410,7 @@ void mem_cgroup_sync_beancounter(struct mem_cgroup *memcg,
 	maxheld = memcg->swap_max >> PAGE_SHIFT;
 	s->failcnt = atomic_long_read(&memcg->swap_failcnt);
 	lim = res_counter_read_u64(&memcg->memsw, RES_LIMIT);
-	lim = lim == RESOURCE_MAX ? UB_MAXVALUE :
+	lim = lim >= RESOURCE_MAX ? UB_MAXVALUE :
 		min_t(unsigned long long, lim >> PAGE_SHIFT, UB_MAXVALUE);
 	if (lim != UB_MAXVALUE)
 		lim -= p->limit;
@@ -5425,7 +5425,7 @@ void mem_cgroup_sync_beancounter(struct mem_cgroup *memcg,
 	o->maxheld = res_counter_read_u64(&memcg->memsw, RES_MAX_USAGE) >> PAGE_SHIFT;
 	o->failcnt = atomic_long_read(&memcg->oom_kill_cnt);
 	lim = memcg->oom_guarantee;
-	lim = lim == RESOURCE_MAX ? UB_MAXVALUE :
+	lim = lim >= RESOURCE_MAX ? UB_MAXVALUE :
 		min_t(unsigned long long, lim >> PAGE_SHIFT, UB_MAXVALUE);
 	o->barrier = o->limit = lim;
 }
@@ -5486,7 +5486,7 @@ int mem_cgroup_apply_beancounter(struct mem_cgroup *memcg,
 
 	if (mem != mem_old) {
 		/* first, reset memsw limit since it cannot be < mem limit */
-		if (memsw_old != RESOURCE_MAX) {
+		if (memsw_old < RESOURCE_MAX) {
 			memsw_old = RESOURCE_MAX;
 			ret = mem_cgroup_resize_memsw_limit(memcg, memsw_old);
 			if (ret)
-- 
2.1.4




More information about the Devel mailing list