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/cpuset.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/cpuset.c')
-rw-r--r-- | kernel/cpuset.c | 51 |
1 files changed, 6 insertions, 45 deletions
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 | /** |