Skip to content

Commit ddd6914

Browse files
committed
cgroup: drop unnecessary RCU dancing from __put_css_set()
__put_css_set() does RCU read access on @CGRP across dropping @cgrp->count so that it can continue accessing @CGRP even if the count reached zero and destruction of the cgroup commenced. Given that both sides - __css_put() and cgroup_destroy_locked() - are cold paths, this is unnecessary. Just making cgroup_destroy_locked() grab css_set_lock while checking @cgrp->count is enough. Remove the RCU read locking from __put_css_set() and make cgroup_destroy_locked() read-lock css_set_lock when checking @cgrp->count. This will also allow removing @cgrp->count. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
1 parent 54766d4 commit ddd6914

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎kernel/cgroup.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,13 @@ static void __put_css_set(struct css_set *cset, int taskexit)
407407
list_del(&link->cset_link);
408408
list_del(&link->cgrp_link);
409409

410-
/*
411-
* We may not be holding cgroup_mutex, and if cgrp->count is
412-
* dropped to 0 the cgroup can be destroyed at any time, hence
413-
* rcu_read_lock is used to keep it alive.
414-
*/
415-
rcu_read_lock();
410+
/* @cgrp can't go away while we're holding css_set_lock */
416411
if (atomic_dec_and_test(&cgrp->count) &&
417412
notify_on_release(cgrp)) {
418413
if (taskexit)
419414
set_bit(CGRP_RELEASABLE, &cgrp->flags);
420415
check_for_release(cgrp);
421416
}
422-
rcu_read_unlock();
423417

424418
kfree(link);
425419
}
@@ -4370,11 +4364,19 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
43704364
struct cgroup *parent = cgrp->parent;
43714365
struct cgroup_event *event, *tmp;
43724366
struct cgroup_subsys *ss;
4367+
bool empty;
43734368

43744369
lockdep_assert_held(&d->d_inode->i_mutex);
43754370
lockdep_assert_held(&cgroup_mutex);
43764371

4377-
if (atomic_read(&cgrp->count) || !list_empty(&cgrp->children))
4372+
/*
4373+
* css_set_lock prevents @cgrp from being removed while
4374+
* __put_css_set() is in progress.
4375+
*/
4376+
read_lock(&css_set_lock);
4377+
empty = !atomic_read(&cgrp->count) && list_empty(&cgrp->children);
4378+
read_unlock(&css_set_lock);
4379+
if (!empty)
43784380
return -EBUSY;
43794381

43804382
/*
@@ -5051,8 +5053,6 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
50515053

50525054
static void check_for_release(struct cgroup *cgrp)
50535055
{
5054-
/* All of these checks rely on RCU to keep the cgroup
5055-
* structure alive */
50565056
if (cgroup_is_releasable(cgrp) &&
50575057
!atomic_read(&cgrp->count) && list_empty(&cgrp->children)) {
50585058
/*

0 commit comments

Comments
 (0)