diff options
author | Tejun Heo <tj@kernel.org> | 2013-04-07 12:29:50 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-04-07 12:29:50 -0400 |
commit | 8cc9934520e7f752fe45d5199664d741ba24a932 (patch) | |
tree | 881744c4c1c69f4c5afc46b80adb1dd71caf58ff /kernel/cgroup.c | |
parent | d9c10ddddc98db0a316243cd266c466875975a94 (diff) |
cgroup, cpuset: replace move_member_tasks_to_cpuset() with cgroup_transfer_tasks()
When a cpuset becomes empty (no CPU or memory), its tasks are
transferred with the nearest ancestor with execution resources. This
is implemented using cgroup_scan_tasks() with a callback which grabs
cgroup_mutex and invokes cgroup_attach_task() on each task.
Both cgroup_mutex and cgroup_attach_task() are scheduled to be
unexported. Implement cgroup_transfer_tasks() in cgroup proper which
is essentially the same as move_member_tasks_to_cpuset() except that
it takes cgroups instead of cpusets and @to comes before @from like
normal functions with those arguments, and replace
move_member_tasks_to_cpuset() with it.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 4aee5bdd66c8..147d7ccb3b0b 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -3269,6 +3269,34 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan) | |||
3269 | return 0; | 3269 | return 0; |
3270 | } | 3270 | } |
3271 | 3271 | ||
3272 | static void cgroup_transfer_one_task(struct task_struct *task, | ||
3273 | struct cgroup_scanner *scan) | ||
3274 | { | ||
3275 | struct cgroup *new_cgroup = scan->data; | ||
3276 | |||
3277 | cgroup_lock(); | ||
3278 | cgroup_attach_task(new_cgroup, task, false); | ||
3279 | cgroup_unlock(); | ||
3280 | } | ||
3281 | |||
3282 | /** | ||
3283 | * cgroup_trasnsfer_tasks - move tasks from one cgroup to another | ||
3284 | * @to: cgroup to which the tasks will be moved | ||
3285 | * @from: cgroup in which the tasks currently reside | ||
3286 | */ | ||
3287 | int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from) | ||
3288 | { | ||
3289 | struct cgroup_scanner scan; | ||
3290 | |||
3291 | scan.cg = from; | ||
3292 | scan.test_task = NULL; /* select all tasks in cgroup */ | ||
3293 | scan.process_task = cgroup_transfer_one_task; | ||
3294 | scan.heap = NULL; | ||
3295 | scan.data = to; | ||
3296 | |||
3297 | return cgroup_scan_tasks(&scan); | ||
3298 | } | ||
3299 | |||
3272 | /* | 3300 | /* |
3273 | * Stuff for reading the 'tasks'/'procs' files. | 3301 | * Stuff for reading the 'tasks'/'procs' files. |
3274 | * | 3302 | * |