Skip to content

Commit

Permalink
cgroup: move css_set_rwsem locking outside of cgroup_task_migrate()
Browse files Browse the repository at this point in the history
Instead of repeatedly locking and unlocking css_set_rwsem inside
cgroup_task_migrate(), update cgroup_attach_task() to grab it outside
of the loop and update cgroup_task_migrate() to use
put_css_set_locked().

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
  • Loading branch information
htejun committed Feb 13, 2014
1 parent 89c5509 commit cb0f1fe
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1715,17 +1715,23 @@ int cgroup_taskset_size(struct cgroup_taskset *tset)
EXPORT_SYMBOL_GPL(cgroup_taskset_size);


/*
/**
* cgroup_task_migrate - move a task from one cgroup to another.
* @old_cgrp; the cgroup @tsk is being migrated from
* @tsk: the task being migrated
* @new_cset: the new css_set @tsk is being attached to
*
* Must be called with cgroup_mutex and threadgroup locked.
* Must be called with cgroup_mutex, threadgroup and css_set_rwsem locked.
*/
static void cgroup_task_migrate(struct cgroup *old_cgrp,
struct task_struct *tsk,
struct css_set *new_cset)
{
struct css_set *old_cset;

lockdep_assert_held(&cgroup_mutex);
lockdep_assert_held(&css_set_rwsem);

/*
* We are synchronized through threadgroup_lock() against PF_EXITING
* setting such that we can't race against cgroup_exit() changing the
Expand All @@ -1738,17 +1744,15 @@ static void cgroup_task_migrate(struct cgroup *old_cgrp,
rcu_assign_pointer(tsk->cgroups, new_cset);
task_unlock(tsk);

down_write(&css_set_rwsem);
list_move(&tsk->cg_list, &new_cset->tasks);
up_write(&css_set_rwsem);

/*
* We just gained a reference on old_cset by taking it from the
* task. As trading it for new_cset is protected by cgroup_mutex,
* we're safe to drop it here; it will be freed under RCU.
*/
set_bit(CGRP_RELEASABLE, &old_cgrp->flags);
put_css_set(old_cset, false);
put_css_set_locked(old_cset, false);
}

/**
Expand Down Expand Up @@ -1871,10 +1875,12 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
* proceed to move all tasks to the new cgroup. There are no
* failure cases after here, so this is the commit point.
*/
down_write(&css_set_rwsem);
for (i = 0; i < group_size; i++) {
tc = flex_array_get(group, i);
cgroup_task_migrate(tc->cgrp, tc->task, tc->cset);
}
up_write(&css_set_rwsem);
/* nothing is sensitive to fork() after this point. */

/*
Expand Down

0 comments on commit cb0f1fe

Please sign in to comment.