Commit e8d55fde authored by Li Zefan's avatar Li Zefan Committed by Linus Torvalds

cgroups: simplify init_subsys()

We are at system boot and there is only 1 cgroup group (i,e, init_css_set), so
we don't need to run through the css_set linked list.  Neither do we need to
run through the task list, since no processes have been created yet.

Also referring to a comment in cgroup.h:

struct css_set
{
	...
	/*
	 * Set of subsystem states, one for each subsystem. This array
	 * is immutable after creation apart from the init_css_set
	 * during subsystem registration (at boot time).
	 */
	struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
}
Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Reviewed-by: default avatarPaul Menage <menage@google.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Pavel Emelyanov <xemul@openvz.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 472b1053
...@@ -500,8 +500,7 @@ post-attachment activity that requires memory allocations or blocking. ...@@ -500,8 +500,7 @@ post-attachment activity that requires memory allocations or blocking.
void fork(struct cgroup_subsy *ss, struct task_struct *task) void fork(struct cgroup_subsy *ss, struct task_struct *task)
Called when a task is forked into a cgroup. Also called during Called when a task is forked into a cgroup.
registration for all existing tasks.
void exit(struct cgroup_subsys *ss, struct task_struct *task) void exit(struct cgroup_subsys *ss, struct task_struct *task)
......
...@@ -2477,7 +2477,6 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry) ...@@ -2477,7 +2477,6 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
static void __init cgroup_init_subsys(struct cgroup_subsys *ss) static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
{ {
struct cgroup_subsys_state *css; struct cgroup_subsys_state *css;
struct list_head *l;
printk(KERN_INFO "Initializing cgroup subsys %s\n", ss->name); printk(KERN_INFO "Initializing cgroup subsys %s\n", ss->name);
...@@ -2488,35 +2487,19 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) ...@@ -2488,35 +2487,19 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
BUG_ON(IS_ERR(css)); BUG_ON(IS_ERR(css));
init_cgroup_css(css, ss, dummytop); init_cgroup_css(css, ss, dummytop);
/* Update all cgroup groups to contain a subsys /* Update the init_css_set to contain a subsys
* pointer to this state - since the subsystem is * pointer to this state - since the subsystem is
* newly registered, all tasks and hence all cgroup * newly registered, all tasks and hence the
* groups are in the subsystem's top cgroup. */ * init_css_set is in the subsystem's top cgroup. */
write_lock(&css_set_lock); init_css_set.subsys[ss->subsys_id] = dummytop->subsys[ss->subsys_id];
l = &init_css_set.list;
do {
struct css_set *cg =
list_entry(l, struct css_set, list);
cg->subsys[ss->subsys_id] = dummytop->subsys[ss->subsys_id];
l = l->next;
} while (l != &init_css_set.list);
write_unlock(&css_set_lock);
/* If this subsystem requested that it be notified with fork
* events, we should send it one now for every process in the
* system */
if (ss->fork) {
struct task_struct *g, *p;
read_lock(&tasklist_lock);
do_each_thread(g, p) {
ss->fork(ss, p);
} while_each_thread(g, p);
read_unlock(&tasklist_lock);
}
need_forkexit_callback |= ss->fork || ss->exit; need_forkexit_callback |= ss->fork || ss->exit;
/* At system boot, before all subsystems have been
* registered, no tasks have been forked, so we don't
* need to invoke fork callbacks here. */
BUG_ON(!list_empty(&init_task.tasks));
ss->active = 1; ss->active = 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment