diff options
author | Tejun Heo <tj@kernel.org> | 2013-08-08 20:11:26 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-08-08 20:11:26 -0400 |
commit | c59cd3d840b1b0a8f996cbbd9132128dcaabbeb9 (patch) | |
tree | f2ad31b11b14c00cfaa5327a5a587fae56604866 | |
parent | 0942eeeef68f9493c1bcb1a52baf612b73fcf9fb (diff) |
cgroup: make cgroup_task_iter remember the cgroup being iterated
Currently all cgroup_task_iter functions require @cgrp to be passed
in, which is superflous and increases chance of usage error. Make
cgroup_task_iter remember the cgroup being iterated and drop @cgrp
argument from next and end functions.
This patch doesn't introduce any behavior differences.
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>
-rw-r--r-- | include/linux/cgroup.h | 6 | ||||
-rw-r--r-- | kernel/cgroup.c | 32 | ||||
-rw-r--r-- | kernel/cgroup_freezer.c | 12 | ||||
-rw-r--r-- | mm/memcontrol.c | 6 |
4 files changed, 27 insertions, 29 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index ea439794bd9b..0287fccd0f54 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -891,14 +891,14 @@ css_next_descendant_post(struct cgroup_subsys_state *pos, | |||
891 | 891 | ||
892 | /* A cgroup_task_iter should be treated as an opaque object */ | 892 | /* A cgroup_task_iter should be treated as an opaque object */ |
893 | struct cgroup_task_iter { | 893 | struct cgroup_task_iter { |
894 | struct cgroup *origin_cgrp; | ||
894 | struct list_head *cset_link; | 895 | struct list_head *cset_link; |
895 | struct list_head *task; | 896 | struct list_head *task; |
896 | }; | 897 | }; |
897 | 898 | ||
898 | void cgroup_task_iter_start(struct cgroup *cgrp, struct cgroup_task_iter *it); | 899 | void cgroup_task_iter_start(struct cgroup *cgrp, struct cgroup_task_iter *it); |
899 | struct task_struct *cgroup_task_iter_next(struct cgroup *cgrp, | 900 | struct task_struct *cgroup_task_iter_next(struct cgroup_task_iter *it); |
900 | struct cgroup_task_iter *it); | 901 | void cgroup_task_iter_end(struct cgroup_task_iter *it); |
901 | void cgroup_task_iter_end(struct cgroup *cgrp, struct cgroup_task_iter *it); | ||
902 | int cgroup_scan_tasks(struct cgroup_scanner *scan); | 902 | int cgroup_scan_tasks(struct cgroup_scanner *scan); |
903 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); | 903 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); |
904 | int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from); | 904 | int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from); |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 15c93f9c9e57..abc62ea1303c 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -3205,13 +3205,11 @@ EXPORT_SYMBOL_GPL(css_next_descendant_post); | |||
3205 | 3205 | ||
3206 | /** | 3206 | /** |
3207 | * cgroup_advance_task_iter - advance a task itererator to the next css_set | 3207 | * cgroup_advance_task_iter - advance a task itererator to the next css_set |
3208 | * @cgrp: the cgroup to walk tasks of | ||
3209 | * @it: the iterator to advance | 3208 | * @it: the iterator to advance |
3210 | * | 3209 | * |
3211 | * Advance @it to the next css_set to walk. | 3210 | * Advance @it to the next css_set to walk. |
3212 | */ | 3211 | */ |
3213 | static void cgroup_advance_task_iter(struct cgroup *cgrp, | 3212 | static void cgroup_advance_task_iter(struct cgroup_task_iter *it) |
3214 | struct cgroup_task_iter *it) | ||
3215 | { | 3213 | { |
3216 | struct list_head *l = it->cset_link; | 3214 | struct list_head *l = it->cset_link; |
3217 | struct cgrp_cset_link *link; | 3215 | struct cgrp_cset_link *link; |
@@ -3220,7 +3218,7 @@ static void cgroup_advance_task_iter(struct cgroup *cgrp, | |||
3220 | /* Advance to the next non-empty css_set */ | 3218 | /* Advance to the next non-empty css_set */ |
3221 | do { | 3219 | do { |
3222 | l = l->next; | 3220 | l = l->next; |
3223 | if (l == &cgrp->cset_links) { | 3221 | if (l == &it->origin_cgrp->cset_links) { |
3224 | it->cset_link = NULL; | 3222 | it->cset_link = NULL; |
3225 | return; | 3223 | return; |
3226 | } | 3224 | } |
@@ -3257,21 +3255,22 @@ void cgroup_task_iter_start(struct cgroup *cgrp, struct cgroup_task_iter *it) | |||
3257 | cgroup_enable_task_cg_lists(); | 3255 | cgroup_enable_task_cg_lists(); |
3258 | 3256 | ||
3259 | read_lock(&css_set_lock); | 3257 | read_lock(&css_set_lock); |
3258 | |||
3259 | it->origin_cgrp = cgrp; | ||
3260 | it->cset_link = &cgrp->cset_links; | 3260 | it->cset_link = &cgrp->cset_links; |
3261 | cgroup_advance_task_iter(cgrp, it); | 3261 | |
3262 | cgroup_advance_task_iter(it); | ||
3262 | } | 3263 | } |
3263 | 3264 | ||
3264 | /** | 3265 | /** |
3265 | * cgroup_task_iter_next - return the next task for the iterator | 3266 | * 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 | 3267 | * @it: the task iterator being iterated |
3268 | * | 3268 | * |
3269 | * The "next" function for task iteration. @it should have been | 3269 | * The "next" function for task iteration. @it should have been |
3270 | * initialized via cgroup_task_iter_start(). Returns NULL when the | 3270 | * initialized via cgroup_task_iter_start(). Returns NULL when the |
3271 | * iteration reaches the end. | 3271 | * iteration reaches the end. |
3272 | */ | 3272 | */ |
3273 | struct task_struct *cgroup_task_iter_next(struct cgroup *cgrp, | 3273 | struct task_struct *cgroup_task_iter_next(struct cgroup_task_iter *it) |
3274 | struct cgroup_task_iter *it) | ||
3275 | { | 3274 | { |
3276 | struct task_struct *res; | 3275 | struct task_struct *res; |
3277 | struct list_head *l = it->task; | 3276 | struct list_head *l = it->task; |
@@ -3289,7 +3288,7 @@ struct task_struct *cgroup_task_iter_next(struct cgroup *cgrp, | |||
3289 | * We reached the end of this task list - move on to the | 3288 | * We reached the end of this task list - move on to the |
3290 | * next cgrp_cset_link. | 3289 | * next cgrp_cset_link. |
3291 | */ | 3290 | */ |
3292 | cgroup_advance_task_iter(cgrp, it); | 3291 | cgroup_advance_task_iter(it); |
3293 | } else { | 3292 | } else { |
3294 | it->task = l; | 3293 | it->task = l; |
3295 | } | 3294 | } |
@@ -3298,12 +3297,11 @@ struct task_struct *cgroup_task_iter_next(struct cgroup *cgrp, | |||
3298 | 3297 | ||
3299 | /** | 3298 | /** |
3300 | * cgroup_task_iter_end - finish task iteration | 3299 | * cgroup_task_iter_end - finish task iteration |
3301 | * @cgrp: the cgroup to walk tasks of | ||
3302 | * @it: the task iterator to finish | 3300 | * @it: the task iterator to finish |
3303 | * | 3301 | * |
3304 | * Finish task iteration started by cgroup_task_iter_start(). | 3302 | * Finish task iteration started by cgroup_task_iter_start(). |
3305 | */ | 3303 | */ |
3306 | void cgroup_task_iter_end(struct cgroup *cgrp, struct cgroup_task_iter *it) | 3304 | void cgroup_task_iter_end(struct cgroup_task_iter *it) |
3307 | __releases(css_set_lock) | 3305 | __releases(css_set_lock) |
3308 | { | 3306 | { |
3309 | read_unlock(&css_set_lock); | 3307 | read_unlock(&css_set_lock); |
@@ -3409,7 +3407,7 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan) | |||
3409 | */ | 3407 | */ |
3410 | heap->size = 0; | 3408 | heap->size = 0; |
3411 | cgroup_task_iter_start(scan->cgrp, &it); | 3409 | cgroup_task_iter_start(scan->cgrp, &it); |
3412 | while ((p = cgroup_task_iter_next(scan->cgrp, &it))) { | 3410 | while ((p = cgroup_task_iter_next(&it))) { |
3413 | /* | 3411 | /* |
3414 | * Only affect tasks that qualify per the caller's callback, | 3412 | * Only affect tasks that qualify per the caller's callback, |
3415 | * if he provided one | 3413 | * if he provided one |
@@ -3442,7 +3440,7 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan) | |||
3442 | * the heap and wasn't inserted | 3440 | * the heap and wasn't inserted |
3443 | */ | 3441 | */ |
3444 | } | 3442 | } |
3445 | cgroup_task_iter_end(scan->cgrp, &it); | 3443 | cgroup_task_iter_end(&it); |
3446 | 3444 | ||
3447 | if (heap->size) { | 3445 | if (heap->size) { |
3448 | for (i = 0; i < heap->size; i++) { | 3446 | for (i = 0; i < heap->size; i++) { |
@@ -3664,7 +3662,7 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type, | |||
3664 | return -ENOMEM; | 3662 | return -ENOMEM; |
3665 | /* now, populate the array */ | 3663 | /* now, populate the array */ |
3666 | cgroup_task_iter_start(cgrp, &it); | 3664 | cgroup_task_iter_start(cgrp, &it); |
3667 | while ((tsk = cgroup_task_iter_next(cgrp, &it))) { | 3665 | while ((tsk = cgroup_task_iter_next(&it))) { |
3668 | if (unlikely(n == length)) | 3666 | if (unlikely(n == length)) |
3669 | break; | 3667 | break; |
3670 | /* get tgid or pid for procs or tasks file respectively */ | 3668 | /* get tgid or pid for procs or tasks file respectively */ |
@@ -3675,7 +3673,7 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type, | |||
3675 | if (pid > 0) /* make sure to only use valid results */ | 3673 | if (pid > 0) /* make sure to only use valid results */ |
3676 | array[n++] = pid; | 3674 | array[n++] = pid; |
3677 | } | 3675 | } |
3678 | cgroup_task_iter_end(cgrp, &it); | 3676 | cgroup_task_iter_end(&it); |
3679 | length = n; | 3677 | length = n; |
3680 | /* now sort & (if procs) strip out duplicates */ | 3678 | /* now sort & (if procs) strip out duplicates */ |
3681 | sort(array, length, sizeof(pid_t), cmppid, NULL); | 3679 | sort(array, length, sizeof(pid_t), cmppid, NULL); |
@@ -3724,7 +3722,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) | |||
3724 | cgrp = dentry->d_fsdata; | 3722 | cgrp = dentry->d_fsdata; |
3725 | 3723 | ||
3726 | cgroup_task_iter_start(cgrp, &it); | 3724 | cgroup_task_iter_start(cgrp, &it); |
3727 | while ((tsk = cgroup_task_iter_next(cgrp, &it))) { | 3725 | while ((tsk = cgroup_task_iter_next(&it))) { |
3728 | switch (tsk->state) { | 3726 | switch (tsk->state) { |
3729 | case TASK_RUNNING: | 3727 | case TASK_RUNNING: |
3730 | stats->nr_running++; | 3728 | stats->nr_running++; |
@@ -3744,7 +3742,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) | |||
3744 | break; | 3742 | break; |
3745 | } | 3743 | } |
3746 | } | 3744 | } |
3747 | cgroup_task_iter_end(cgrp, &it); | 3745 | cgroup_task_iter_end(&it); |
3748 | 3746 | ||
3749 | err: | 3747 | err: |
3750 | return ret; | 3748 | return ret; |
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c index c9177f8fc661..e0ab9bfd679a 100644 --- a/kernel/cgroup_freezer.c +++ b/kernel/cgroup_freezer.c | |||
@@ -281,7 +281,7 @@ static void update_if_frozen(struct cgroup_subsys_state *css) | |||
281 | /* are all tasks frozen? */ | 281 | /* are all tasks frozen? */ |
282 | cgroup_task_iter_start(css->cgroup, &it); | 282 | cgroup_task_iter_start(css->cgroup, &it); |
283 | 283 | ||
284 | while ((task = cgroup_task_iter_next(css->cgroup, &it))) { | 284 | while ((task = cgroup_task_iter_next(&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; |
298 | out_iter_end: | 298 | out_iter_end: |
299 | cgroup_task_iter_end(css->cgroup, &it); | 299 | cgroup_task_iter_end(&it); |
300 | out_unlock: | 300 | out_unlock: |
301 | spin_unlock_irq(&freezer->lock); | 301 | spin_unlock_irq(&freezer->lock); |
302 | } | 302 | } |
@@ -327,9 +327,9 @@ static void freeze_cgroup(struct freezer *freezer) | |||
327 | struct task_struct *task; | 327 | struct task_struct *task; |
328 | 328 | ||
329 | cgroup_task_iter_start(cgroup, &it); | 329 | cgroup_task_iter_start(cgroup, &it); |
330 | while ((task = cgroup_task_iter_next(cgroup, &it))) | 330 | while ((task = cgroup_task_iter_next(&it))) |
331 | freeze_task(task); | 331 | freeze_task(task); |
332 | cgroup_task_iter_end(cgroup, &it); | 332 | cgroup_task_iter_end(&it); |
333 | } | 333 | } |
334 | 334 | ||
335 | static void unfreeze_cgroup(struct freezer *freezer) | 335 | static void unfreeze_cgroup(struct freezer *freezer) |
@@ -339,9 +339,9 @@ static void unfreeze_cgroup(struct freezer *freezer) | |||
339 | struct task_struct *task; | 339 | struct task_struct *task; |
340 | 340 | ||
341 | cgroup_task_iter_start(cgroup, &it); | 341 | cgroup_task_iter_start(cgroup, &it); |
342 | while ((task = cgroup_task_iter_next(cgroup, &it))) | 342 | while ((task = cgroup_task_iter_next(&it))) |
343 | __thaw_task(task); | 343 | __thaw_task(task); |
344 | cgroup_task_iter_end(cgroup, &it); | 344 | cgroup_task_iter_end(&it); |
345 | } | 345 | } |
346 | 346 | ||
347 | /** | 347 | /** |
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 00b055dd1d3d..5a5f4dc649f0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -1804,7 +1804,7 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, | |||
1804 | struct task_struct *task; | 1804 | struct task_struct *task; |
1805 | 1805 | ||
1806 | cgroup_task_iter_start(cgroup, &it); | 1806 | cgroup_task_iter_start(cgroup, &it); |
1807 | while ((task = cgroup_task_iter_next(cgroup, &it))) { | 1807 | while ((task = cgroup_task_iter_next(&it))) { |
1808 | switch (oom_scan_process_thread(task, totalpages, NULL, | 1808 | switch (oom_scan_process_thread(task, totalpages, NULL, |
1809 | false)) { | 1809 | false)) { |
1810 | case OOM_SCAN_SELECT: | 1810 | case OOM_SCAN_SELECT: |
@@ -1817,7 +1817,7 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, | |||
1817 | case OOM_SCAN_CONTINUE: | 1817 | case OOM_SCAN_CONTINUE: |
1818 | continue; | 1818 | continue; |
1819 | case OOM_SCAN_ABORT: | 1819 | case OOM_SCAN_ABORT: |
1820 | cgroup_task_iter_end(cgroup, &it); | 1820 | cgroup_task_iter_end(&it); |
1821 | mem_cgroup_iter_break(memcg, iter); | 1821 | mem_cgroup_iter_break(memcg, iter); |
1822 | if (chosen) | 1822 | if (chosen) |
1823 | put_task_struct(chosen); | 1823 | put_task_struct(chosen); |
@@ -1834,7 +1834,7 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, | |||
1834 | get_task_struct(chosen); | 1834 | get_task_struct(chosen); |
1835 | } | 1835 | } |
1836 | } | 1836 | } |
1837 | cgroup_task_iter_end(cgroup, &it); | 1837 | cgroup_task_iter_end(&it); |
1838 | } | 1838 | } |
1839 | 1839 | ||
1840 | if (!chosen) | 1840 | if (!chosen) |