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 | |
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>
-rw-r--r-- | include/linux/cgroup.h | 1 | ||||
-rw-r--r-- | kernel/cgroup.c | 28 | ||||
-rw-r--r-- | kernel/cpuset.c | 51 |
3 files changed, 35 insertions, 45 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 01c48c6806d6..f8eb01d75ddc 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -696,6 +696,7 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan); | |||
696 | int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk, | 696 | int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk, |
697 | bool threadgroup); | 697 | bool threadgroup); |
698 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); | 698 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); |
699 | int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from); | ||
699 | 700 | ||
700 | /* | 701 | /* |
701 | * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works | 702 | * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works |
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 | * |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 98d458aad789..866d78ee7930 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -1994,50 +1994,6 @@ int __init cpuset_init(void) | |||
1994 | return 0; | 1994 | return 0; |
1995 | } | 1995 | } |
1996 | 1996 | ||
1997 | /** | ||
1998 | * cpuset_do_move_task - move a given task to another cpuset | ||
1999 | * @tsk: pointer to task_struct the task to move | ||
2000 | * @scan: struct cgroup_scanner contained in its struct cpuset_hotplug_scanner | ||
2001 | * | ||
2002 | * Called by cgroup_scan_tasks() for each task in a cgroup. | ||
2003 | * Return nonzero to stop the walk through the tasks. | ||
2004 | */ | ||
2005 | static void cpuset_do_move_task(struct task_struct *tsk, | ||
2006 | struct cgroup_scanner *scan) | ||
2007 | { | ||
2008 | struct cgroup *new_cgroup = scan->data; | ||
2009 | |||
2010 | cgroup_lock(); | ||
2011 | cgroup_attach_task(new_cgroup, tsk, false); | ||
2012 | cgroup_unlock(); | ||
2013 | } | ||
2014 | |||
2015 | /** | ||
2016 | * move_member_tasks_to_cpuset - move tasks from one cpuset to another | ||
2017 | * @from: cpuset in which the tasks currently reside | ||
2018 | * @to: cpuset to which the tasks will be moved | ||
2019 | * | ||
2020 | * Called with cpuset_mutex held | ||
2021 | * callback_mutex must not be held, as cpuset_attach() will take it. | ||
2022 | * | ||
2023 | * The cgroup_scan_tasks() function will scan all the tasks in a cgroup, | ||
2024 | * calling callback functions for each. | ||
2025 | */ | ||
2026 | static void move_member_tasks_to_cpuset(struct cpuset *from, struct cpuset *to) | ||
2027 | { | ||
2028 | struct cgroup_scanner scan; | ||
2029 | |||
2030 | scan.cg = from->css.cgroup; | ||
2031 | scan.test_task = NULL; /* select all tasks in cgroup */ | ||
2032 | scan.process_task = cpuset_do_move_task; | ||
2033 | scan.heap = NULL; | ||
2034 | scan.data = to->css.cgroup; | ||
2035 | |||
2036 | if (cgroup_scan_tasks(&scan)) | ||
2037 | printk(KERN_ERR "move_member_tasks_to_cpuset: " | ||
2038 | "cgroup_scan_tasks failed\n"); | ||
2039 | } | ||
2040 | |||
2041 | /* | 1997 | /* |
2042 | * If CPU and/or memory hotplug handlers, below, unplug any CPUs | 1998 | * If CPU and/or memory hotplug handlers, below, unplug any CPUs |
2043 | * or memory nodes, we need to walk over the cpuset hierarchy, | 1999 | * or memory nodes, we need to walk over the cpuset hierarchy, |
@@ -2058,7 +2014,12 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs) | |||
2058 | nodes_empty(parent->mems_allowed)) | 2014 | nodes_empty(parent->mems_allowed)) |
2059 | parent = parent_cs(parent); | 2015 | parent = parent_cs(parent); |
2060 | 2016 | ||
2061 | move_member_tasks_to_cpuset(cs, parent); | 2017 | if (cgroup_transfer_tasks(parent->css.cgroup, cs->css.cgroup)) { |
2018 | rcu_read_lock(); | ||
2019 | printk(KERN_ERR "cpuset: failed to transfer tasks out of empty cpuset %s\n", | ||
2020 | cgroup_name(cs->css.cgroup)); | ||
2021 | rcu_read_unlock(); | ||
2022 | } | ||
2062 | } | 2023 | } |
2063 | 2024 | ||
2064 | /** | 2025 | /** |