]> git.itanic.dy.fi Git - linux-stable/commit
cgroup: Elide write-locking threadgroup_rwsem when updating csses on an empty subtree
authorTejun Heo <tj@kernel.org>
Fri, 15 Jul 2022 04:38:15 +0000 (18:38 -1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2022 10:04:54 +0000 (12:04 +0200)
commit13d67aadb1c91af420b182f5829c997109c95ea8
tree788e956645a6dd4592962ce6ff8b812d1ce237cc
parent059516952cc9cc303b3bd0c558abef193a736fe2
cgroup: Elide write-locking threadgroup_rwsem when updating csses on an empty subtree

[ Upstream commit 671c11f0619e5ccb380bcf0f062f69ba95fc974a ]

cgroup_update_dfl_csses() write-lock the threadgroup_rwsem as updating the
csses can trigger process migrations. However, if the subtree doesn't
contain any tasks, there aren't gonna be any cgroup migrations. This
condition can be trivially detected by testing whether
mgctx.preloaded_src_csets is empty. Elide write-locking threadgroup_rwsem if
the subtree is empty.

After this optimization, the usage pattern of creating a cgroup, enabling
the necessary controllers, and then seeding it with CLONE_INTO_CGROUP and
then removing the cgroup after it becomes empty doesn't need to write-lock
threadgroup_rwsem at all.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/cgroup/cgroup.c