[Devel] [PATCH rh7 04/11] ub: do not apply memcg limits on attaching via sys_setluid

Vladimir Davydov vdavydov at parallels.com
Wed May 20 08:49:27 PDT 2015


I recalled why I had added this patch - we have to activate kmem in the
underlying memcg before attaching a task to a beancounter.  However, it
is obviously better to do that when a beancounter is created via the
legacy API. The patch below does the trick. The only difference between
the previous patch and this one is that the latter also adds
ub_update_memcg to get_beancounter_by_name.

Having said that, Konstantin, please apply the patch below instead of
the original one.

Thanks,
Vladimir
---
From: Vladimir Davydov <vdavydov at parallels.com>
Subject: [PATCH] ub: apply memcg limits on create not on attach via
 sys_setluid

We apply ub limits to the underlying memcg on every attach in order to
active kmem accounting. Actually, it's saner to do that once on create
instead of on eacy sys_setluid call. This patch therefore moves
ub_update_mem_cgroup_limits call from ub_mem_cgroup_attach_task to
get_beancounter_by_name.

Also, rename ub_update_mem_cgroup_limits to ub_update_memcg ot match
ub_sync_memcg.

Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>

diff --git a/include/bc/beancounter.h b/include/bc/beancounter.h
index e0ef5ec195fa..a70684390171 100644
--- a/include/bc/beancounter.h
+++ b/include/bc/beancounter.h
@@ -317,8 +317,7 @@ extern void __uncharge_beancounter_locked(struct user_beancounter *ub,
 extern void uncharge_warn(struct user_beancounter *ub, const char *resource,
 		unsigned long val, unsigned long held);
 
-extern int ub_update_mem_cgroup_limits(struct user_beancounter *ub);
-
+extern int ub_update_memcg(struct user_beancounter *ub);
 extern void ub_sync_memcg(struct user_beancounter *ub);
 extern void ub_page_stat(struct user_beancounter *ub,
 			 const nodemask_t *nodemask,
diff --git a/kernel/bc/beancounter.c b/kernel/bc/beancounter.c
index d94fb32cd22c..fb0530b4d3a3 100644
--- a/kernel/bc/beancounter.c
+++ b/kernel/bc/beancounter.c
@@ -109,9 +109,6 @@ static void ub_cgroup_close(struct cgroup *root, struct cgroup *cg)
 		cgroup_kernel_close(cg);
 }
 
-extern int mem_cgroup_apply_beancounter(struct cgroup *cg,
-					struct user_beancounter *ub);
-
 static int ub_mem_cgroup_attach_task(struct user_beancounter *ub,
 				     struct task_struct *tsk)
 {
@@ -121,12 +118,7 @@ static int ub_mem_cgroup_attach_task(struct user_beancounter *ub,
 	cg = ub_cgroup_open(mem_cgroup_root, ub);
 	if (IS_ERR(cg))
 		return PTR_ERR(cg);
-	if (ub != get_ub0())
-		ret = mem_cgroup_apply_beancounter(cg, ub);
-	else
-		ret = 0;
-	if (!ret)
-		ret = cgroup_kernel_attach(cg, tsk);
+	ret = cgroup_kernel_attach(cg, tsk);
 	ub_cgroup_close(mem_cgroup_root, cg);
 	return ret;
 }
@@ -186,7 +178,12 @@ fail_blkio:
 	goto out;
 }
 
-int ub_update_mem_cgroup_limits(struct user_beancounter *ub)
+extern void mem_cgroup_sync_beancounter(struct cgroup *cg,
+					struct user_beancounter *ub);
+extern int mem_cgroup_apply_beancounter(struct cgroup *cg,
+					struct user_beancounter *ub);
+
+int ub_update_memcg(struct user_beancounter *ub)
 {
 	struct cgroup *cg;
 	int ret;
@@ -202,9 +199,6 @@ int ub_update_mem_cgroup_limits(struct user_beancounter *ub)
 	return ret;
 }
 
-extern void mem_cgroup_sync_beancounter(struct cgroup *cg,
-					struct user_beancounter *ub);
-
 void ub_sync_memcg(struct user_beancounter *ub)
 {
 	struct cgroup *cg;
@@ -383,6 +377,8 @@ struct user_beancounter *get_beancounter_by_name(const char *name, int create)
 				return NULL;
 			pr_warn_once("Allocating UB with syslimits is deprecated!\n");
 			init_beancounter_syslimits(cgroup_ub(cg));
+			if (ub_update_memcg(cgroup_ub(cg)) != 0)
+				pr_warn("Failed to init UB %s limits\n", name);
 		}
 	} else {
 		cg = cgroup_kernel_open(ub_cgroup_root, 0, name);
diff --git a/kernel/bc/sys.c b/kernel/bc/sys.c
index 875f05ecad08..096aa978b04e 100644
--- a/kernel/bc/sys.c
+++ b/kernel/bc/sys.c
@@ -99,7 +99,7 @@ long do_setublimit(uid_t uid, unsigned long resource,
 	init_beancounter_precharge(ub, resource);
 	spin_unlock_irqrestore(&ub->ub_lock, flags);
 
-	error = ub_update_mem_cgroup_limits(ub);
+	error = ub_update_memcg(ub);
 
 	put_beancounter(ub);
 out:



More information about the Devel mailing list