public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Paul Menage <menage@google.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH -mm 1/2] cgroup: introduce hierarchy_id
Date: Thu, 11 Sep 2008 22:23:21 +0800	[thread overview]
Message-ID: <48C929D9.6070706@cn.fujitsu.com> (raw)


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;
 



                 reply	other threads:[~2008-09-11 14:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=48C929D9.6070706@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menage@google.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