Skip to contentSkip to conversation

cgroup: introduce hierarchy_id

RFC PATCH In review Lai Jiangshan 1 participant 1 message Sep 11, 2008

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 cgroup: introduce hierarchy_id

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.

---

kernel/cgroup.c +20 -0
index c8f9c70..4bd5560 100644
@@ -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;