cgroup: fix cgroup_taskset walking order
authorTejun Heo <tj@kernel.org>
Wed, 19 Mar 2014 21:43:21 +0000 (17:43 -0400)
committerTejun Heo <tj@kernel.org>
Wed, 19 Mar 2014 21:43:21 +0000 (17:43 -0400)
commit1b9aba49eab5e85b0d3de8ba630cda6d68546297
tree189d5d24c13399c346e50e1d3be40dbc59ec98e4
parent8cbbf2c972c4444cad36f61cd571714c39b8cf04
cgroup: fix cgroup_taskset walking order

cgroup_taskset is used to track and iterate target tasks while
migrating a task or process and should guarantee that the first task
iterated is the task group leader if a process is being migrated.

b3dc094e9390 ("cgroup: use css_set->mg_tasks to track target tasks
during migration") replaced flex array cgroup_taskset->tc_array with
css_set->mg_tasks list to remove process size limit and dynamic
allocation during migration; unfortunately, it incorrectly used list
operations which don't preserve order breaking the guarantee that
cgroup_taskset_first() returns the leader for a process target.

Fix it by using order preserving list operations.  Note that as
multiple src_csets may map to a single dst_cset, the iteration order
may change across cgroup_task_migrate(); however, the leader is still
guaranteed to be the first entry.

The switch to list_splice_tail_init() at the end of cgroup_migrate()
isn't strictly necessary.  Let's still do it for consistency.

Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup.c