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:
@@ -4828,7 +4828,7 @@ static int mem_cgroup_can_attach(struct cgroup_subsys_state *css,
|
||||
{
|
||||
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
|
||||
struct mem_cgroup *from;
|
||||
struct task_struct *p;
|
||||
struct task_struct *leader, *p;
|
||||
struct mm_struct *mm;
|
||||
unsigned long move_flags;
|
||||
int ret = 0;
|
||||
@@ -4842,7 +4842,20 @@ static int mem_cgroup_can_attach(struct cgroup_subsys_state *css,
|
||||
if (!move_flags)
|
||||
return 0;
|
||||
|
||||
p = cgroup_taskset_first(tset);
|
||||
/*
|
||||
* Multi-process migrations only happen on the default hierarchy
|
||||
* where charge immigration is not used. Perform charge
|
||||
* immigration if @tset contains a leader and whine if there are
|
||||
* multiple.
|
||||
*/
|
||||
p = NULL;
|
||||
cgroup_taskset_for_each_leader(leader, tset) {
|
||||
WARN_ON_ONCE(p);
|
||||
p = leader;
|
||||
}
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
from = mem_cgroup_from_task(p);
|
||||
|
||||
VM_BUG_ON(from == memcg);
|
||||
|
Reference in New Issue
Block a user