cgroup/cpuset: avoid unneeded cpuset_mutex re-lock
authorMiaohe Lin <linmiaohe@huawei.com>
Tue, 4 Jul 2023 12:03:52 +0000 (20:03 +0800)
committerTejun Heo <tj@kernel.org>
Mon, 10 Jul 2023 20:26:06 +0000 (10:26 -1000)
cpuset_mutex unlock and lock pair is only needed when transferring tasks
out of empty cpuset. Avoid unneeded cpuset_mutex re-lock when !is_empty
to save cpu cycles.

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

index 601c40d..e136269 100644 (file)
@@ -3521,17 +3521,16 @@ hotplug_update_tasks_legacy(struct cpuset *cs,
        is_empty = cpumask_empty(cs->cpus_allowed) ||
                   nodes_empty(cs->mems_allowed);
 
-       mutex_unlock(&cpuset_mutex);
-
        /*
         * Move tasks to the nearest ancestor with execution resources,
         * This is full cgroup operation which will also call back into
         * cpuset. Should be done outside any lock.
         */
-       if (is_empty)
+       if (is_empty) {
+               mutex_unlock(&cpuset_mutex);
                remove_tasks_in_empty_cpuset(cs);
-
-       mutex_lock(&cpuset_mutex);
+               mutex_lock(&cpuset_mutex);
+       }
 }
 
 static void