cgroup, memcg, cpuset: implement cgroup_taskset_for_each_leader()

It wasn't explicitly documented but, when a process is being migrated,
cpuset and memcg depend on cgroup_taskset_first() returning the
threadgroup leader; however, this approach is somewhat ghetto and
would no longer work for the planned multi-process migration.

This patch introduces explicit cgroup_taskset_for_each_leader() which
iterates over only the threadgroup leaders and replaces
cgroup_taskset_first() usages for accessing the leader with it.

This prepares both memcg and cpuset for multi-process migration.  This
patch also updates the documentation for cgroup_taskset_for_each() to
clarify the iteration rules and removes comments mentioning task
ordering in tasksets.

v2: A previous patch which added threadgroup leader test was dropped.
    Patch updated accordingly.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Zefan Li <lizefan@huawei.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
This commit is contained in:
Tejun Heo 2015-09-11 15:00:19 -04:00
parent 3df9ca0a2b
commit 4530eddb59
4 changed files with 41 additions and 18 deletions

View file

@ -1488,7 +1488,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
/* static buf protected by cpuset_mutex */
static nodemask_t cpuset_attach_nodemask_to;
struct task_struct *task;
struct task_struct *leader = cgroup_taskset_first(tset);
struct task_struct *leader;
struct cpuset *cs = css_cs(css);
struct cpuset *oldcs = cpuset_attach_old_cs;
@ -1514,12 +1514,11 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
}
/*
* Change mm, possibly for multiple threads in a threadgroup. This
* is expensive and may sleep and should be moved outside migration
* path proper.
* Change mm for all threadgroup leaders. This is expensive and may
* sleep and should be moved outside migration path proper.
*/
cpuset_attach_nodemask_to = cs->effective_mems;
if (thread_group_leader(leader)) {
cgroup_taskset_for_each_leader(leader, tset) {
struct mm_struct *mm = get_task_mm(leader);
if (mm) {