Commit e8d55fdeb882cfcb5e8db5a5ce16edfba78aafc5
Committed by
Linus Torvalds
1 parent
472b1053f3
Exists in
master
and in
4 other branches
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: Li Zefan <lizf@cn.fujitsu.com> Reviewed-by: Paul 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 2 changed files with 10 additions and 28 deletions Side-by-side Diff
Documentation/cgroups.txt
... | ... | @@ -500,8 +500,7 @@ |
500 | 500 | |
501 | 501 | void fork(struct cgroup_subsy *ss, struct task_struct *task) |
502 | 502 | |
503 | -Called when a task is forked into a cgroup. Also called during | |
504 | -registration for all existing tasks. | |
503 | +Called when a task is forked into a cgroup. | |
505 | 504 | |
506 | 505 | void exit(struct cgroup_subsys *ss, struct task_struct *task) |
507 | 506 |
kernel/cgroup.c
... | ... | @@ -2477,7 +2477,6 @@ |
2477 | 2477 | static void __init cgroup_init_subsys(struct cgroup_subsys *ss) |
2478 | 2478 | { |
2479 | 2479 | struct cgroup_subsys_state *css; |
2480 | - struct list_head *l; | |
2481 | 2480 | |
2482 | 2481 | printk(KERN_INFO "Initializing cgroup subsys %s\n", ss->name); |
2483 | 2482 | |
2484 | 2483 | |
2485 | 2484 | |
2486 | 2485 | |
... | ... | @@ -2488,34 +2487,18 @@ |
2488 | 2487 | BUG_ON(IS_ERR(css)); |
2489 | 2488 | init_cgroup_css(css, ss, dummytop); |
2490 | 2489 | |
2491 | - /* Update all cgroup groups to contain a subsys | |
2490 | + /* Update the init_css_set to contain a subsys | |
2492 | 2491 | * pointer to this state - since the subsystem is |
2493 | - * newly registered, all tasks and hence all cgroup | |
2494 | - * groups are in the subsystem's top cgroup. */ | |
2495 | - write_lock(&css_set_lock); | |
2496 | - l = &init_css_set.list; | |
2497 | - do { | |
2498 | - struct css_set *cg = | |
2499 | - list_entry(l, struct css_set, list); | |
2500 | - cg->subsys[ss->subsys_id] = dummytop->subsys[ss->subsys_id]; | |
2501 | - l = l->next; | |
2502 | - } while (l != &init_css_set.list); | |
2503 | - write_unlock(&css_set_lock); | |
2492 | + * newly registered, all tasks and hence the | |
2493 | + * init_css_set is in the subsystem's top cgroup. */ | |
2494 | + init_css_set.subsys[ss->subsys_id] = dummytop->subsys[ss->subsys_id]; | |
2504 | 2495 | |
2505 | - /* If this subsystem requested that it be notified with fork | |
2506 | - * events, we should send it one now for every process in the | |
2507 | - * system */ | |
2508 | - if (ss->fork) { | |
2509 | - struct task_struct *g, *p; | |
2510 | - | |
2511 | - read_lock(&tasklist_lock); | |
2512 | - do_each_thread(g, p) { | |
2513 | - ss->fork(ss, p); | |
2514 | - } while_each_thread(g, p); | |
2515 | - read_unlock(&tasklist_lock); | |
2516 | - } | |
2517 | - | |
2518 | 2496 | need_forkexit_callback |= ss->fork || ss->exit; |
2497 | + | |
2498 | + /* At system boot, before all subsystems have been | |
2499 | + * registered, no tasks have been forked, so we don't | |
2500 | + * need to invoke fork callbacks here. */ | |
2501 | + BUG_ON(!list_empty(&init_task.tasks)); | |
2519 | 2502 | |
2520 | 2503 | ss->active = 1; |
2521 | 2504 | } |