cgroup: Remove call to synchronize_rcu in cgroup_attach_task
authorColin Cross <ccross@android.com>
Wed, 24 Nov 2010 05:37:04 +0000 (21:37 -0800)
committerColin Cross <ccross@android.com>
Tue, 14 Jun 2011 16:09:40 +0000 (09:09 -0700)
commitdbc38c633f4b7abe97c53036df55fbb2040188bc
tree57123eb96e4b840a3efd1fc4c51073f7229dd23d
parent6d51e762b1b58226ddaf922673970162e71c9ed9
cgroup: Remove call to synchronize_rcu in cgroup_attach_task

synchronize_rcu can be very expensive, averaging 100 ms in
some cases.  In cgroup_attach_task, it is used to prevent
a task->cgroups pointer dereferenced in an RCU read side
critical section from being invalidated, by delaying the
call to put_css_set until after an RCU grace period.

To avoid the call to synchronize_rcu, make the put_css_set
call rcu-safe by moving the deletion of the css_set links
into free_css_set_work, scheduled by the rcu callback
free_css_set_rcu.

The decrement of the cgroup refcount is no longer
synchronous with the call to put_css_set, which can result
in the cgroup refcount staying positive after the last call
to cgroup_attach_task returns.  To allow the cgroup to be
deleted with cgroup_rmdir synchronously after
cgroup_attach_task, have rmdir check the refcount of all
associated css_sets.  If cgroup_rmdir is called on a cgroup
for which the css_sets all have refcount zero but the
cgroup refcount is nonzero, reuse the rmdir waitqueue to
block the rmdir until free_css_set_work is called.

Signed-off-by: Colin Cross <ccross@android.com>
include/linux/cgroup.h
kernel/cgroup.c