public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH -mm 1/2] cgroup: introduce hierarchy_id
@ 2008-09-11 14:23 Lai Jiangshan
  0 siblings, 0 replies; only message in thread
From: Lai Jiangshan @ 2008-09-11 14:23 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Paul Menage, Linux Kernel Mailing List


every struct cgroupfs_root represent a hierarchy.
and this patch introduces hierarchy_id for every hierarchy,
just like pid for every struct task_struct.

hierarchy_id is very useful for fold struct cg_cgroup_link
into struct css_set.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c8f9c70..4bd5560 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -84,6 +84,9 @@ struct cgroupfs_root {
 	/* Tracks how many cgroups are currently defined in hierarchy.*/
 	int number_of_cgroups;
 
+	/* Unique id for every hierarchy. */
+	int hierarchy_id;
+
 	/* A list running through the mounted hierarchies */
 	struct list_head root_list;
 
@@ -191,6 +194,20 @@ void cgroup_huge_mem_free(void *ptr, cgroup_huge_mem_t *huge)
 		kfree(ptr);
 }
 
+static unsigned long hierarchy_id_bits;
+
+static int get_hierarchy_id(void)
+{
+	int id = find_first_zero_bit(&hierarchy_id_bits, CGROUP_SUBSYS_COUNT);
+	__set_bit(id, &hierarchy_id_bits);
+	return id;
+}
+
+static void put_hierarchy_id(int id)
+{
+	__clear_bit(id, &hierarchy_id_bits);
+}
+
 /*
  * for_each_subsys() allows you to iterate on each subsystem attached to
  * an active hierarchy
@@ -1080,6 +1097,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
 		BUG_ON(ret);
 
 		list_add(&root->root_list, &roots);
+		root->hierarchy_id = get_hierarchy_id();
 		root_count++;
 
 		sb->s_root->d_fsdata = &root->top_cgroup;
@@ -1165,6 +1183,7 @@ static void cgroup_kill_sb(struct super_block *sb) {
 
 	if (!list_empty(&root->root_list)) {
 		list_del(&root->root_list);
+		put_hierarchy_id(root->hierarchy_id);
 		root_count--;
 	}
 	mutex_unlock(&cgroup_mutex);
@@ -2627,6 +2646,7 @@ int __init cgroup_init_early(void)
 	css_set_count = 1;
 	init_cgroup_root(&rootnode);
 	list_add(&rootnode.root_list, &roots);
+	rootnode.hierarchy_id = get_hierarchy_id();
 	root_count = 1;
 	init_task.cgroups = &init_css_set;
 



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-09-11 14:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-11 14:23 [RFC PATCH -mm 1/2] cgroup: introduce hierarchy_id Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox