[PATCH 02/10] cgroups: new resource counter inheritance API

Frederic Weisbecker fweisbec at gmail.com
Wed Feb 1 03:37:42 UTC 2012


Provide an API to inherit a counter value from a parent.  This can be
useful to implement cgroup.clone_children on a resource counter.

Still the resources of the children are limited by those of the parent, so
this is only to provide a default setting behaviour when clone_children is
set.

Signed-off-by: Frederic Weisbecker <fweisbec at gmail.com>
Cc: Paul Menage <paul at paulmenage.org>
Cc: Li Zefan <lizf at cn.fujitsu.com>
Cc: Johannes Weiner <hannes at cmpxchg.org>
Cc: Aditya Kali <adityakali at google.com>
Cc: Oleg Nesterov <oleg at redhat.com>
Cc: Tim Hockin <thockin at hockin.org>
Cc: Tejun Heo <htejun at gmail.com>
Cc: Containers <containers at lists.linux-foundation.org>
Cc: Glauber Costa <glommer at gmail.com>
Cc: Cgroups <cgroups at vger.kernel.org>
Cc: Daniel J Walsh <dwalsh at redhat.com>
Cc: "Daniel P. Berrange" <berrange at redhat.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu at jp.fujitsu.com>
Cc: Max Kellermann <mk at cm4all.com>
Cc: Mandeep Singh Baines <msb at chromium.org>
Acked-by: Kirill A. Shutemov <kirill at shutemov.name>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
---
 include/linux/res_counter.h |    2 ++
 kernel/res_counter.c        |   18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index 1b3fe05..109d118 100644
--- a/include/linux/res_counter.h
+++ b/include/linux/res_counter.h
@@ -84,6 +84,8 @@ int res_counter_write(struct res_counter *counter, int member,
 
 void res_counter_write_u64(struct res_counter *counter, int member, u64 val);
 
+void res_counter_inherit(struct res_counter *counter, int member);
+
 /*
  * the field descriptors. one for each member of res_counter
  */
diff --git a/kernel/res_counter.c b/kernel/res_counter.c
index c46465c..3a93a82 100644
--- a/kernel/res_counter.c
+++ b/kernel/res_counter.c
@@ -207,3 +207,21 @@ int res_counter_write(struct res_counter *counter, int member,
 
 	return 0;
 }
+
+/*
+ * Simple inheritance implementation to get the same value
+ * than a parent. However this doesn't enforce the child value
+ * to be always below the one of the parent. But the child is
+ * subject to its parent limitation anyway.
+ */
+void res_counter_inherit(struct res_counter *counter, int member)
+{
+	struct res_counter *parent;
+	unsigned long long val;
+
+	parent = counter->parent;
+	if (parent) {
+		val = res_counter_read_u64(parent, member);
+		res_counter_write_u64(counter, member, val);
+	}
+}
-- 
1.7.5.4



More information about the Containers mailing list