[Devel] [PATCH rh7 3/3] memcg: sync UB_OOMGUARPAGES

Vladimir Davydov vdavydov at parallels.com
Thu May 21 02:50:26 PDT 2015


UB_OOMGUARPAGES.held = memory.memsw.usage_in_bytes
UB_OOMGUARPAGES.maxheld = memory.memsw.max_usage_in_bytes
UB_OOMGUARPAGES.barrier = limit = memory.oom_guarantee
UB_OOMGUARPAGES.failcnt = mem_cgroup->oom_kill_cnt

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

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 70dd91ab37df..6ef83fbd1a58 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5267,11 +5267,12 @@ void mem_cgroup_sync_beancounter(struct cgroup *cg, struct user_beancounter *ub)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_cont(cg);
 	unsigned long long lim, held, maxheld;
-	volatile struct ubparm *k, *p, *s;
+	volatile struct ubparm *k, *p, *s, *o;
 
 	k = &ub->ub_parms[UB_KMEMSIZE];
 	p = &ub->ub_parms[UB_PHYSPAGES];
 	s = &ub->ub_parms[UB_SWAPPAGES];
+	o = &ub->ub_parms[UB_OOMGUARPAGES];
 
 	p->held	= res_counter_read_u64(&memcg->res, RES_USAGE) >> PAGE_SHIFT;
 	p->maxheld = res_counter_read_u64(&memcg->res, RES_MAX_USAGE) >> PAGE_SHIFT;
@@ -5304,12 +5305,20 @@ void mem_cgroup_sync_beancounter(struct cgroup *cg, struct user_beancounter *ub)
 	 * (memory.memsw.limit - memory.limit). */
 	s->held = min(held, lim);
 	s->maxheld = min(maxheld, lim);
+
+	o->held = res_counter_read_u64(&memcg->memsw, RES_USAGE) >> PAGE_SHIFT;
+	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 :
+		min_t(unsigned long long, lim >> PAGE_SHIFT, UB_MAXVALUE);
+	o->barrier = o->limit = lim;
 }
 
 int mem_cgroup_apply_beancounter(struct cgroup *cg, struct user_beancounter *ub)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_cont(cg);
-	unsigned long long mem, memsw, mem_old, memsw_old;
+	unsigned long long mem, memsw, mem_old, memsw_old, oomguar;
 	int ret = 0;
 
 	mem = ub->ub_parms[UB_PHYSPAGES].limit;
@@ -5328,6 +5337,12 @@ int mem_cgroup_apply_beancounter(struct cgroup *cg, struct user_beancounter *ub)
 	else
 		memsw = RESOURCE_MAX;
 
+	oomguar = ub->ub_parms[UB_OOMGUARPAGES].barrier;
+	if (oomguar < RESOURCE_MAX >> PAGE_SHIFT)
+		oomguar <<= PAGE_SHIFT;
+	else
+		oomguar = RESOURCE_MAX;
+
 	if (ub->ub_parms[UB_KMEMSIZE].limit != UB_MAXVALUE)
 		pr_warn_once("ub: kmemsize limit is deprecated\n");
 
@@ -5367,6 +5382,8 @@ int mem_cgroup_apply_beancounter(struct cgroup *cg, struct user_beancounter *ub)
 		if (ret)
 			goto out;
 	}
+
+	memcg->oom_guarantee = oomguar;
 out:
 	return ret;
 }
-- 
1.7.10.4




More information about the Devel mailing list