mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Menage <menage@google.com>
To: lizf@cn.fujitsu.com, balbir@linux.vnet.ibm.com
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	containers@lists.linux-foundation.org,
	kamezawa.hiroyu@jp.fujitsu.com
Subject: [PATCH 9/9] [RFC] Example multi-bindable subsystem: a max-depth controller
Date: Wed, 01 Jul 2009 19:11:39 -0700	[thread overview]
Message-ID: <20090702021139.14469.3097.stgit@menage.mtv.corp.google.com> (raw)
In-Reply-To: <20090702020624.14469.47066.stgit@menage.mtv.corp.google.com>

[RFC] Example multi-bindable subsystem: a max-depth controller

This subsystem introduces a new file, "maxdepth.children", in each
cgroup in its hierarchy.  This value defaults to -1, meaning no
limit. If this maxdepth.children is >= 0, then no child cgroup may be
created below this cgroup at a depth of more than maxdepth.children.
The limit is checked at cgroup creation time for all ancestor cgroups.

Signed-off-by: Paul Menage <menage@google.com>

---

 include/linux/cgroup_subsys.h |    6 +++
 init/Kconfig                  |    8 ++++
 kernel/Makefile               |    1 +
 kernel/maxdepth_cgroup.c      |   80 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 kernel/maxdepth_cgroup.c

diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h
index 5dfea38..021bfc1 100644
--- a/include/linux/cgroup_subsys.h
+++ b/include/linux/cgroup_subsys.h
@@ -66,3 +66,9 @@ MULTI_SUBSYS(info)
 #endif
 
 /* */
+
+#ifdef CONFIG_CGROUP_MAXDEPTH
+MULTI_SUBSYS(maxdepth)
+#endif
+
+/* */
diff --git a/init/Kconfig b/init/Kconfig
index 3bd4685..69907cc 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -613,6 +613,14 @@ config CGROUP_INFO
 	  application-specific configuration data about a cgroup. Can
 	  be mounted on multiple hierarchies at once.
 
+config CGROUP_MAXDEPTH
+       bool "CGroups controller to limit the max depth of a hierarchy"
+       depends on CGROUPS
+       help
+         Provides a simple cgroups subsystem with an
+         "maxdepth.children" field that limits the maximum number of
+         child generations permitted to a cgroup.
+
 endif # CGROUPS
 
 config MM_OWNER
diff --git a/kernel/Makefile b/kernel/Makefile
index e713a67..5712cd5 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
 obj-$(CONFIG_CPUSETS) += cpuset.o
 obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o
 obj-$(CONFIG_CGROUP_INFO) += info_cgroup.o
+obj-$(CONFIG_CGROUP_MAXDEPTH) += maxdepth_cgroup.o
 obj-$(CONFIG_UTS_NS) += utsname.o
 obj-$(CONFIG_USER_NS) += user_namespace.o
 obj-$(CONFIG_PID_NS) += pid_namespace.o
diff --git a/kernel/maxdepth_cgroup.c b/kernel/maxdepth_cgroup.c
new file mode 100644
index 0000000..2ca92d8
--- /dev/null
+++ b/kernel/maxdepth_cgroup.c
@@ -0,0 +1,80 @@
+/*
+ * maxdepth_cgroup.c - simple cgroup providing a child generation
+ * limit field
+ */
+
+#include "linux/cgroup.h"
+#include "linux/err.h"
+#include "linux/seq_file.h"
+
+struct maxdepth_cgroup {
+	struct cgroup_subsys_state css;
+	int maxdepth;
+};
+
+static inline struct maxdepth_cgroup *cg_md(struct cgroup *cg)
+{
+	return container_of(cgroup_subsys_state(cg, maxdepth_subsys_id),
+			    struct maxdepth_cgroup, css);
+}
+
+static struct cgroup_subsys_state *md_create(struct cgroup_subsys *ss,
+					     struct cgroup *cg)
+{
+	struct maxdepth_cgroup *md;
+	int depth = 1, maxdepth;
+	while (1) {
+		cg = cg->parent;
+		if (!cg)
+			break;
+		maxdepth = cg_md(cg)->maxdepth;
+		if ((maxdepth >= 0) && (depth > maxdepth))
+			return ERR_PTR(-EINVAL);
+		depth++;
+	}
+
+	md = kzalloc(sizeof(*md), GFP_KERNEL);
+	if (!md)
+		return ERR_PTR(-ENOMEM);
+	md->maxdepth = -1;
+	return &md->css;
+}
+
+static void md_destroy(struct cgroup_subsys *ss, struct cgroup *cont)
+{
+	kfree(cg_md(cont));
+}
+
+static s64 md_read(struct cgroup *cont, struct cftype *cft)
+{
+	return cg_md(cont)->maxdepth;
+}
+
+static int md_write(struct cgroup *cont, struct cftype *cft, s64 val)
+{
+	if ((val < -1) || (val >= INT_MAX))
+		return -EINVAL;
+	cg_md(cont)->maxdepth = val;
+	return 0;
+}
+
+static struct cftype md_files[] =  {
+	{
+		.name = "children",
+		.read_s64 = md_read,
+		.write_s64 = md_write,
+	}
+};
+
+static int md_populate(struct cgroup_subsys *ss, struct cgroup *cont)
+{
+	return cgroup_add_files(cont, ss, md_files, ARRAY_SIZE(md_files));
+}
+
+struct cgroup_subsys maxdepth_subsys = {
+	.name = "maxdepth",
+	.create = md_create,
+	.destroy = md_destroy,
+	.populate = md_populate,
+	.subsys_id = maxdepth_subsys_id,
+};


      parent reply	other threads:[~2009-07-02  2:13 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-02  2:10 [PATCH 0/9] [RFC] CGroup Hierarchy Extensions Paul Menage
2009-07-02  2:10 ` [PATCH 1/9] [RFC] Support named cgroups hierarchies Paul Menage
2009-07-02  2:28   ` KAMEZAWA Hiroyuki
2009-07-02  2:49     ` Paul Menage
2009-07-03  1:51       ` Li Zefan
2009-07-02  8:09   ` Louis Rilling
2009-07-02  8:19     ` Paul Menage
2009-07-02  8:24       ` Louis Rilling
2009-07-03  2:32   ` Li Zefan
2009-07-13 23:39     ` Paul Menage
2009-07-02  2:11 ` [PATCH 2/9] [RFC]Move the cgroup debug subsys into cgroup.c to access internal state Paul Menage
2009-07-02  2:11 ` [PATCH 3/9] [RFC] Add a back-pointer from struct cg_cgroup_link to struct cgroup Paul Menage
2009-07-03  7:07   ` Li Zefan
2009-07-21 23:48     ` Paul Menage
2009-07-02  2:11 ` [PATCH 4/9] [RFC] Allow cgroup hierarchies to be created with no bound subsystems Paul Menage
2009-07-03  7:57   ` Li Zefan
2009-07-21 23:31     ` Paul Menage
2009-07-02  2:11 ` [PATCH 5/9] [RFC] Remove cgroup_subsys.root pointer Paul Menage
2009-07-02  9:04   ` Louis Rilling
2009-07-02  9:32     ` Paul Menage
2009-07-02  2:11 ` [PATCH 6/9] [RFC] Remove the cgroup_subsys.bind callback Paul Menage
2009-07-02  2:11 ` [PATCH 7/9] [RFC] Support multiply-bindable cgroup subsystems Paul Menage
2009-07-02  2:45   ` KAMEZAWA Hiroyuki
2009-07-02  2:52     ` Paul Menage
2009-07-02  3:16       ` KAMEZAWA Hiroyuki
2009-07-02  5:04         ` Paul Menage
2009-07-03  8:36   ` Li Zefan
2009-07-02  2:11 ` [PATCH 8/9] [RFC] Example multi-bindable subsystem: a per-cgroup notes field Paul Menage
2009-07-02  2:48   ` KAMEZAWA Hiroyuki
2009-07-02  2:56     ` Paul Menage
2009-07-02  3:17       ` KAMEZAWA Hiroyuki
2009-07-02  7:22       ` Paul Menage
2009-07-03  8:58   ` Li Zefan
2009-07-14  0:49     ` Paul Menage
2009-07-02  2:11 ` Paul Menage [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090702021139.14469.3097.stgit@menage.mtv.corp.google.com \
    --to=menage@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®