[Devel] [PATCH RHEL7 COMMIT] memcg/bc: sync UB_OOMGUARPAGES

Konstantin Khorenko khorenko at virtuozzo.com
Thu May 28 09:07:52 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.7
------>
commit 7c52d5c053e6573ab78b67a35f5d16e51c0b3d56
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Thu May 28 20:07:52 2015 +0400

    memcg/bc: sync UB_OOMGUARPAGES
    
    Patchset description:
    
    This patch set adds memory.oom_guarantee file to memory cgroup which
    allows to protect a memory cgroup from OOM killer. It works as follows:
    OOM killer first selects from processes in cgroups that are above their
    OOM guarantee, and only if there is no such it switches to scanning
    processes from all cgroups. This behavior is similar to UB_OOMGUARPAGES.
    
    It also adds OOM kills counter to each memory cgroup and synchronizes
    beancounters' UB_OOMGUARPAGES resource with oom_guarantee/oom_kill_cnt
    obtained from mem_cgroup.
    
    Related to https://jira.sw.ru/browse/PSBM-20089
    
    Vladimir Davydov (3):
      memcg: add oom_guarantee
      memcg: count oom kills
      memcg: sync UB_OOMGUARPAGES
    
    This patch description:
    
    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 4dad5bd..cfe5875 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5304,12 +5304,13 @@ 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, *d, *p, *s;
+	volatile struct ubparm *k, *d, *p, *s, *o;
 
 	k = &ub->ub_parms[UB_KMEMSIZE];
 	d = &ub->ub_parms[UB_DCACHESIZE];
 	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;
@@ -5347,12 +5348,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;
@@ -5371,6 +5380,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");
 	if (ub->ub_parms[UB_DCACHESIZE].limit != UB_MAXVALUE)
@@ -5412,6 +5427,8 @@ int mem_cgroup_apply_beancounter(struct cgroup *cg, struct user_beancounter *ub)
 		if (ret)
 			goto out;
 	}
+
+	memcg->oom_guarantee = oomguar;
 out:
 	return ret;
 }



More information about the Devel mailing list