cgroup: Eliminate the need for cgroup_mutex in proc_cgroup_show()
authorYafang Shao <laoar.shao@gmail.com>
Sun, 29 Oct 2023 06:14:30 +0000 (06:14 +0000)
committerTejun Heo <tj@kernel.org>
Thu, 9 Nov 2023 23:25:47 +0000 (13:25 -1000)
commit9067d90006df089b9a1da0d74f0cad232a5d726a
treef4e9faf68957ba9c800e8776b0840ffab66185e9
parentd23b5c577715892c87533b13923306acc6243f93
cgroup: Eliminate the need for cgroup_mutex in proc_cgroup_show()

The cgroup root_list is already RCU-safe. Therefore, we can replace the
cgroup_mutex with the RCU read lock in some particular paths. This change
will be particularly beneficial for frequent operations, such as
`cat /proc/self/cgroup`, in a cgroup1-based container environment.

I did stress tests with this change, as outlined below
(with CONFIG_PROVE_RCU_LIST enabled):

- Continuously mounting and unmounting named cgroups in some tasks,
  for example:

  cgrp_name=$1
  while true
  do
      mount -t cgroup -o none,name=$cgrp_name none /$cgrp_name
      umount /$cgrp_name
  done

- Continuously triggering proc_cgroup_show() in some tasks concurrently,
  for example:
  while true; do cat /proc/self/cgroup > /dev/null; done

They can ran successfully after implementing this change, with no RCU
warnings in dmesg.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup.c