cgroup/cpuset: Optimize cpuset_attach() on v2
authorWaiman Long <longman@redhat.com>
Sat, 12 Nov 2022 22:19:39 +0000 (17:19 -0500)
committerTejun Heo <tj@kernel.org>
Mon, 14 Nov 2022 21:45:56 +0000 (11:45 -1000)
commit7fd4da9c1584be97ffbc40e600a19cb469fd4e78
treea1f94d917121fbeefe0a451a4f252076d996a8fa
parent18f9a4d47527772515ad6cbdac796422566e6440
cgroup/cpuset: Optimize cpuset_attach() on v2

It was found that with the default hierarchy, enabling cpuset in the
child cgroups can trigger a cpuset_attach() call in each of the child
cgroups that have tasks with no change in effective cpus and mems. If
there are many processes in those child cgroups, it will burn quite a
lot of cpu cycles iterating all the tasks without doing useful work.

Optimizing this case by comparing between the old and new cpusets and
skip useless update if there is no change in effective cpus and mems.
Also mems_allowed are less likely to be changed than cpus_allowed. So
skip changing mm if there is no change in effective_mems and
CS_MEMORY_MIGRATE is not set.

By inserting some instrumentation code and running a simple command in
a container 200 times in a cgroup v2 system, it was found that all the
cpuset_attach() calls are skipped (401 times in total) as there was no
change in effective cpus and mems.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cpuset.c