[RFC PATCH -mm 1/2] cgroup: introduce hierarchy_id

From: Lai Jiangshan
Date: Thu Sep 11 2008 - 10:26:36 EST



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@xxxxxxxxxxxxxx>
---
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;



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/