Skip to content

Commit bb75842

Browse files
shakeelbhtejun
authored andcommitted
cgroup: remove cgroup_mutex from cgroupstats_build
The function cgroupstats_build extracts cgroup from the kernfs_node's priv pointer which is a RCU pointer. So, there is no need to grab cgroup_mutex. Just get the reference on the cgroup before using and remove the cgroup_mutex altogether. Signed-off-by: Shakeel Butt <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent be28816 commit bb75842

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

kernel/cgroup/cgroup-v1.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,18 +698,15 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
698698
kernfs_type(kn) != KERNFS_DIR)
699699
return -EINVAL;
700700

701-
mutex_lock(&cgroup_mutex);
702-
703701
/*
704702
* We aren't being called from kernfs and there's no guarantee on
705703
* @kn->priv's validity. For this and css_tryget_online_from_dir(),
706704
* @kn->priv is RCU safe. Let's do the RCU dancing.
707705
*/
708706
rcu_read_lock();
709707
cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv);
710-
if (!cgrp || cgroup_is_dead(cgrp)) {
708+
if (!cgrp || !cgroup_tryget(cgrp)) {
711709
rcu_read_unlock();
712-
mutex_unlock(&cgroup_mutex);
713710
return -ENOENT;
714711
}
715712
rcu_read_unlock();
@@ -737,7 +734,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
737734
}
738735
css_task_iter_end(&it);
739736

740-
mutex_unlock(&cgroup_mutex);
737+
cgroup_put(cgrp);
741738
return 0;
742739
}
743740

0 commit comments

Comments
 (0)