aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-08 20:11:26 -0400
committerTejun Heo <tj@kernel.org>2013-08-08 20:11:26 -0400
commit0942eeeef68f9493c1bcb1a52baf612b73fcf9fb (patch)
treed4cbfc6cf3bce4850669fa976ecc00acf01163e4 /kernel
parentd515876e9d951d8cf7fc7c90db2967664bdc89ee (diff)
cgroup: rename cgroup_iter to cgroup_task_iter
cgroup now has multiple iterators and it's quite confusing to have something which walks over tasks of a single cgroup named cgroup_iter. Let's rename it to cgroup_task_iter. While at it, reformat / update comments and replace the overview comment above the interface function decls with proper function comments. Such overview can be useful but function comments should be more than enough here. This is pure rename and doesn't introduce any functional changes. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup.c114
-rw-r--r--kernel/cgroup_freezer.c24
2 files changed, 89 insertions, 49 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index d56d9363d4b3..15c93f9c9e57 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -367,9 +367,11 @@ static struct cgrp_cset_link init_cgrp_cset_link;
367static int cgroup_init_idr(struct cgroup_subsys *ss, 367static int cgroup_init_idr(struct cgroup_subsys *ss,
368 struct cgroup_subsys_state *css); 368 struct cgroup_subsys_state *css);
369 369
370/* css_set_lock protects the list of css_set objects, and the 370/*
371 * chain of tasks off each css_set. Nests outside task->alloc_lock 371 * css_set_lock protects the list of css_set objects, and the chain of
372 * due to cgroup_iter_start() */ 372 * tasks off each css_set. Nests outside task->alloc_lock due to
373 * cgroup_task_iter_start().
374 */
373static DEFINE_RWLOCK(css_set_lock); 375static DEFINE_RWLOCK(css_set_lock);
374static int css_set_count; 376static int css_set_count;
375 377
@@ -394,10 +396,12 @@ static unsigned long css_set_hash(struct cgroup_subsys_state *css[])
394 return key; 396 return key;
395} 397}
396 398
397/* We don't maintain the lists running through each css_set to its 399/*
398 * task until after the first call to cgroup_iter_start(). This 400 * We don't maintain the lists running through each css_set to its task
399 * reduces the fork()/exit() overhead for people who have cgroups 401 * until after the first call to cgroup_task_iter_start(). This reduces
400 * compiled into their kernel but not actually in use */ 402 * the fork()/exit() overhead for people who have cgroups compiled into
403 * their kernel but not actually in use.
404 */
401static int use_task_css_set_links __read_mostly; 405static int use_task_css_set_links __read_mostly;
402 406
403static void __put_css_set(struct css_set *cset, int taskexit) 407static void __put_css_set(struct css_set *cset, int taskexit)
@@ -2982,10 +2986,10 @@ int cgroup_task_count(const struct cgroup *cgrp)
2982} 2986}
2983 2987
2984/* 2988/*
2985 * To reduce the fork() overhead for systems that are not actually 2989 * To reduce the fork() overhead for systems that are not actually using
2986 * using their cgroups capability, we don't maintain the lists running 2990 * their cgroups capability, we don't maintain the lists running through
2987 * through each css_set to its tasks until we see the list actually 2991 * each css_set to its tasks until we see the list actually used - in other
2988 * used - in other words after the first call to cgroup_iter_start(). 2992 * words after the first call to cgroup_task_iter_start().
2989 */ 2993 */
2990static void cgroup_enable_task_cg_lists(void) 2994static void cgroup_enable_task_cg_lists(void)
2991{ 2995{
@@ -3199,11 +3203,15 @@ css_next_descendant_post(struct cgroup_subsys_state *pos,
3199} 3203}
3200EXPORT_SYMBOL_GPL(css_next_descendant_post); 3204EXPORT_SYMBOL_GPL(css_next_descendant_post);
3201 3205
3202/* 3206/**
3203 * Advance a list_head iterator. The iterator should be positioned at 3207 * cgroup_advance_task_iter - advance a task itererator to the next css_set
3204 * the start of a css_set 3208 * @cgrp: the cgroup to walk tasks of
3209 * @it: the iterator to advance
3210 *
3211 * Advance @it to the next css_set to walk.
3205 */ 3212 */
3206static void cgroup_advance_iter(struct cgroup *cgrp, struct cgroup_iter *it) 3213static void cgroup_advance_task_iter(struct cgroup *cgrp,
3214 struct cgroup_task_iter *it)
3207{ 3215{
3208 struct list_head *l = it->cset_link; 3216 struct list_head *l = it->cset_link;
3209 struct cgrp_cset_link *link; 3217 struct cgrp_cset_link *link;
@@ -3223,7 +3231,21 @@ static void cgroup_advance_iter(struct cgroup *cgrp, struct cgroup_iter *it)
3223 it->task = cset->tasks.next; 3231 it->task = cset->tasks.next;
3224} 3232}
3225 3233
3226void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it) 3234/**
3235 * cgroup_task_iter_start - initiate task iteration
3236 * @cgrp: the cgroup to walk tasks of
3237 * @it: the task iterator to use
3238 *
3239 * Initiate iteration through the tasks of @cgrp. The caller can call
3240 * cgroup_task_iter_next() to walk through the tasks until the function
3241 * returns NULL. On completion of iteration, cgroup_task_iter_end() must
3242 * be called.
3243 *
3244 * Note that this function acquires a lock which is released when the
3245 * iteration finishes. The caller can't sleep while iteration is in
3246 * progress.
3247 */
3248void cgroup_task_iter_start(struct cgroup *cgrp, struct cgroup_task_iter *it)
3227 __acquires(css_set_lock) 3249 __acquires(css_set_lock)
3228{ 3250{
3229 /* 3251 /*
@@ -3236,11 +3258,20 @@ void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it)
3236 3258
3237 read_lock(&css_set_lock); 3259 read_lock(&css_set_lock);
3238 it->cset_link = &cgrp->cset_links; 3260 it->cset_link = &cgrp->cset_links;
3239 cgroup_advance_iter(cgrp, it); 3261 cgroup_advance_task_iter(cgrp, it);
3240} 3262}
3241 3263
3242struct task_struct *cgroup_iter_next(struct cgroup *cgrp, 3264/**
3243 struct cgroup_iter *it) 3265 * cgroup_task_iter_next - return the next task for the iterator
3266 * @cgrp: the cgroup to walk tasks of
3267 * @it: the task iterator being iterated
3268 *
3269 * The "next" function for task iteration. @it should have been
3270 * initialized via cgroup_task_iter_start(). Returns NULL when the
3271 * iteration reaches the end.
3272 */
3273struct task_struct *cgroup_task_iter_next(struct cgroup *cgrp,
3274 struct cgroup_task_iter *it)
3244{ 3275{
3245 struct task_struct *res; 3276 struct task_struct *res;
3246 struct list_head *l = it->task; 3277 struct list_head *l = it->task;
@@ -3254,16 +3285,25 @@ struct task_struct *cgroup_iter_next(struct cgroup *cgrp,
3254 l = l->next; 3285 l = l->next;
3255 link = list_entry(it->cset_link, struct cgrp_cset_link, cset_link); 3286 link = list_entry(it->cset_link, struct cgrp_cset_link, cset_link);
3256 if (l == &link->cset->tasks) { 3287 if (l == &link->cset->tasks) {
3257 /* We reached the end of this task list - move on to 3288 /*
3258 * the next cg_cgroup_link */ 3289 * We reached the end of this task list - move on to the
3259 cgroup_advance_iter(cgrp, it); 3290 * next cgrp_cset_link.
3291 */
3292 cgroup_advance_task_iter(cgrp, it);
3260 } else { 3293 } else {
3261 it->task = l; 3294 it->task = l;
3262 } 3295 }
3263 return res; 3296 return res;
3264} 3297}
3265 3298
3266void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it) 3299/**
3300 * cgroup_task_iter_end - finish task iteration
3301 * @cgrp: the cgroup to walk tasks of
3302 * @it: the task iterator to finish
3303 *
3304 * Finish task iteration started by cgroup_task_iter_start().
3305 */
3306void cgroup_task_iter_end(struct cgroup *cgrp, struct cgroup_task_iter *it)
3267 __releases(css_set_lock) 3307 __releases(css_set_lock)
3268{ 3308{
3269 read_unlock(&css_set_lock); 3309 read_unlock(&css_set_lock);
@@ -3312,7 +3352,7 @@ static inline int started_after(void *p1, void *p2)
3312 * Iterate through all the tasks in a cgroup, calling test_task() for each, 3352 * Iterate through all the tasks in a cgroup, calling test_task() for each,
3313 * and if it returns true, call process_task() for it also. 3353 * and if it returns true, call process_task() for it also.
3314 * The test_task pointer may be NULL, meaning always true (select all tasks). 3354 * The test_task pointer may be NULL, meaning always true (select all tasks).
3315 * Effectively duplicates cgroup_iter_{start,next,end}() 3355 * Effectively duplicates cgroup_task_iter_{start,next,end}()
3316 * but does not lock css_set_lock for the call to process_task(). 3356 * but does not lock css_set_lock for the call to process_task().
3317 * The struct cgroup_scanner may be embedded in any structure of the caller's 3357 * The struct cgroup_scanner may be embedded in any structure of the caller's
3318 * creation. 3358 * creation.
@@ -3333,7 +3373,7 @@ static inline int started_after(void *p1, void *p2)
3333int cgroup_scan_tasks(struct cgroup_scanner *scan) 3373int cgroup_scan_tasks(struct cgroup_scanner *scan)
3334{ 3374{
3335 int retval, i; 3375 int retval, i;
3336 struct cgroup_iter it; 3376 struct cgroup_task_iter it;
3337 struct task_struct *p, *dropped; 3377 struct task_struct *p, *dropped;
3338 /* Never dereference latest_task, since it's not refcounted */ 3378 /* Never dereference latest_task, since it's not refcounted */
3339 struct task_struct *latest_task = NULL; 3379 struct task_struct *latest_task = NULL;
@@ -3368,8 +3408,8 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
3368 * guarantees forward progress and that we don't miss any tasks. 3408 * guarantees forward progress and that we don't miss any tasks.
3369 */ 3409 */
3370 heap->size = 0; 3410 heap->size = 0;
3371 cgroup_iter_start(scan->cgrp, &it); 3411 cgroup_task_iter_start(scan->cgrp, &it);
3372 while ((p = cgroup_iter_next(scan->cgrp, &it))) { 3412 while ((p = cgroup_task_iter_next(scan->cgrp, &it))) {
3373 /* 3413 /*
3374 * Only affect tasks that qualify per the caller's callback, 3414 * Only affect tasks that qualify per the caller's callback,
3375 * if he provided one 3415 * if he provided one
@@ -3402,7 +3442,7 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
3402 * the heap and wasn't inserted 3442 * the heap and wasn't inserted
3403 */ 3443 */
3404 } 3444 }
3405 cgroup_iter_end(scan->cgrp, &it); 3445 cgroup_task_iter_end(scan->cgrp, &it);
3406 3446
3407 if (heap->size) { 3447 if (heap->size) {
3408 for (i = 0; i < heap->size; i++) { 3448 for (i = 0; i < heap->size; i++) {
@@ -3608,7 +3648,7 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
3608 pid_t *array; 3648 pid_t *array;
3609 int length; 3649 int length;
3610 int pid, n = 0; /* used for populating the array */ 3650 int pid, n = 0; /* used for populating the array */
3611 struct cgroup_iter it; 3651 struct cgroup_task_iter it;
3612 struct task_struct *tsk; 3652 struct task_struct *tsk;
3613 struct cgroup_pidlist *l; 3653 struct cgroup_pidlist *l;
3614 3654
@@ -3623,8 +3663,8 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
3623 if (!array) 3663 if (!array)
3624 return -ENOMEM; 3664 return -ENOMEM;
3625 /* now, populate the array */ 3665 /* now, populate the array */
3626 cgroup_iter_start(cgrp, &it); 3666 cgroup_task_iter_start(cgrp, &it);
3627 while ((tsk = cgroup_iter_next(cgrp, &it))) { 3667 while ((tsk = cgroup_task_iter_next(cgrp, &it))) {
3628 if (unlikely(n == length)) 3668 if (unlikely(n == length))
3629 break; 3669 break;
3630 /* get tgid or pid for procs or tasks file respectively */ 3670 /* get tgid or pid for procs or tasks file respectively */
@@ -3635,7 +3675,7 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
3635 if (pid > 0) /* make sure to only use valid results */ 3675 if (pid > 0) /* make sure to only use valid results */
3636 array[n++] = pid; 3676 array[n++] = pid;
3637 } 3677 }
3638 cgroup_iter_end(cgrp, &it); 3678 cgroup_task_iter_end(cgrp, &it);
3639 length = n; 3679 length = n;
3640 /* now sort & (if procs) strip out duplicates */ 3680 /* now sort & (if procs) strip out duplicates */
3641 sort(array, length, sizeof(pid_t), cmppid, NULL); 3681 sort(array, length, sizeof(pid_t), cmppid, NULL);
@@ -3669,7 +3709,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
3669{ 3709{
3670 int ret = -EINVAL; 3710 int ret = -EINVAL;
3671 struct cgroup *cgrp; 3711 struct cgroup *cgrp;
3672 struct cgroup_iter it; 3712 struct cgroup_task_iter it;
3673 struct task_struct *tsk; 3713 struct task_struct *tsk;
3674 3714
3675 /* 3715 /*
@@ -3683,8 +3723,8 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
3683 ret = 0; 3723 ret = 0;
3684 cgrp = dentry->d_fsdata; 3724 cgrp = dentry->d_fsdata;
3685 3725
3686 cgroup_iter_start(cgrp, &it); 3726 cgroup_task_iter_start(cgrp, &it);
3687 while ((tsk = cgroup_iter_next(cgrp, &it))) { 3727 while ((tsk = cgroup_task_iter_next(cgrp, &it))) {
3688 switch (tsk->state) { 3728 switch (tsk->state) {
3689 case TASK_RUNNING: 3729 case TASK_RUNNING:
3690 stats->nr_running++; 3730 stats->nr_running++;
@@ -3704,7 +3744,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
3704 break; 3744 break;
3705 } 3745 }
3706 } 3746 }
3707 cgroup_iter_end(cgrp, &it); 3747 cgroup_task_iter_end(cgrp, &it);
3708 3748
3709err: 3749err:
3710 return ret; 3750 return ret;
@@ -5137,7 +5177,7 @@ void cgroup_fork(struct task_struct *child)
5137 * Adds the task to the list running through its css_set if necessary and 5177 * Adds the task to the list running through its css_set if necessary and
5138 * call the subsystem fork() callbacks. Has to be after the task is 5178 * call the subsystem fork() callbacks. Has to be after the task is
5139 * visible on the task list in case we race with the first call to 5179 * visible on the task list in case we race with the first call to
5140 * cgroup_iter_start() - to guarantee that the new task ends up on its 5180 * cgroup_task_iter_start() - to guarantee that the new task ends up on its
5141 * list. 5181 * list.
5142 */ 5182 */
5143void cgroup_post_fork(struct task_struct *child) 5183void cgroup_post_fork(struct task_struct *child)
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 98ca48d9ceb4..c9177f8fc661 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -258,7 +258,7 @@ static void update_if_frozen(struct cgroup_subsys_state *css)
258{ 258{
259 struct freezer *freezer = css_freezer(css); 259 struct freezer *freezer = css_freezer(css);
260 struct cgroup_subsys_state *pos; 260 struct cgroup_subsys_state *pos;
261 struct cgroup_iter it; 261 struct cgroup_task_iter it;
262 struct task_struct *task; 262 struct task_struct *task;
263 263
264 WARN_ON_ONCE(!rcu_read_lock_held()); 264 WARN_ON_ONCE(!rcu_read_lock_held());
@@ -279,9 +279,9 @@ static void update_if_frozen(struct cgroup_subsys_state *css)
279 } 279 }
280 280
281 /* are all tasks frozen? */ 281 /* are all tasks frozen? */
282 cgroup_iter_start(css->cgroup, &it); 282 cgroup_task_iter_start(css->cgroup, &it);
283 283
284 while ((task = cgroup_iter_next(css->cgroup, &it))) { 284 while ((task = cgroup_task_iter_next(css->cgroup, &it))) {
285 if (freezing(task)) { 285 if (freezing(task)) {
286 /* 286 /*
287 * freezer_should_skip() indicates that the task 287 * freezer_should_skip() indicates that the task
@@ -296,7 +296,7 @@ static void update_if_frozen(struct cgroup_subsys_state *css)
296 296
297 freezer->state |= CGROUP_FROZEN; 297 freezer->state |= CGROUP_FROZEN;
298out_iter_end: 298out_iter_end:
299 cgroup_iter_end(css->cgroup, &it); 299 cgroup_task_iter_end(css->cgroup, &it);
300out_unlock: 300out_unlock:
301 spin_unlock_irq(&freezer->lock); 301 spin_unlock_irq(&freezer->lock);
302} 302}
@@ -323,25 +323,25 @@ static int freezer_read(struct cgroup_subsys_state *css, struct cftype *cft,
323static void freeze_cgroup(struct freezer *freezer) 323static void freeze_cgroup(struct freezer *freezer)
324{ 324{
325 struct cgroup *cgroup = freezer->css.cgroup; 325 struct cgroup *cgroup = freezer->css.cgroup;
326 struct cgroup_iter it; 326 struct cgroup_task_iter it;
327 struct task_struct *task; 327 struct task_struct *task;
328 328
329 cgroup_iter_start(cgroup, &it); 329 cgroup_task_iter_start(cgroup, &it);
330 while ((task = cgroup_iter_next(cgroup, &it))) 330 while ((task = cgroup_task_iter_next(cgroup, &it)))
331 freeze_task(task); 331 freeze_task(task);
332 cgroup_iter_end(cgroup, &it); 332 cgroup_task_iter_end(cgroup, &it);
333} 333}
334 334
335static void unfreeze_cgroup(struct freezer *freezer) 335static void unfreeze_cgroup(struct freezer *freezer)
336{ 336{
337 struct cgroup *cgroup = freezer->css.cgroup; 337 struct cgroup *cgroup = freezer->css.cgroup;
338 struct cgroup_iter it; 338 struct cgroup_task_iter it;
339 struct task_struct *task; 339 struct task_struct *task;
340 340
341 cgroup_iter_start(cgroup, &it); 341 cgroup_task_iter_start(cgroup, &it);
342 while ((task = cgroup_iter_next(cgroup, &it))) 342 while ((task = cgroup_task_iter_next(cgroup, &it)))
343 __thaw_task(task); 343 __thaw_task(task);
344 cgroup_iter_end(cgroup, &it); 344 cgroup_task_iter_end(cgroup, &it);
345} 345}
346 346
347/** 347/**