]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
workqueue: make sysfs of unbound kworker cpumask more clever
authorMenglong Dong <imagedong@tencent.com>
Sun, 17 Oct 2021 12:04:02 +0000 (20:04 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Nov 2021 10:36:06 +0000 (11:36 +0100)
[ Upstream commit d25302e46592c97d29f70ccb1be558df31a9a360 ]

Some unfriendly component, such as dpdk, write the same mask to
unbound kworker cpumask again and again. Every time it write to
this interface some work is queue to cpu, even though the mask
is same with the original mask.

So, fix it by return success and do nothing if the cpumask is
equal with the old one.

Signed-off-by: Mengen Sun <mengensun@tencent.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/workqueue.c

index 1573d1bf6300762176176e6e9bd5f01d43a5f25d..b1bb6cb5802ec8fe567552de776bea9d30a928fa 100644 (file)
@@ -5125,9 +5125,6 @@ int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
        int ret = -EINVAL;
        cpumask_var_t saved_cpumask;
 
-       if (!zalloc_cpumask_var(&saved_cpumask, GFP_KERNEL))
-               return -ENOMEM;
-
        /*
         * Not excluding isolated cpus on purpose.
         * If the user wishes to include them, we allow that.
@@ -5135,6 +5132,15 @@ int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
        cpumask_and(cpumask, cpumask, cpu_possible_mask);
        if (!cpumask_empty(cpumask)) {
                apply_wqattrs_lock();
+               if (cpumask_equal(cpumask, wq_unbound_cpumask)) {
+                       ret = 0;
+                       goto out_unlock;
+               }
+
+               if (!zalloc_cpumask_var(&saved_cpumask, GFP_KERNEL)) {
+                       ret = -ENOMEM;
+                       goto out_unlock;
+               }
 
                /* save the old wq_unbound_cpumask. */
                cpumask_copy(saved_cpumask, wq_unbound_cpumask);
@@ -5147,10 +5153,11 @@ int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
                if (ret < 0)
                        cpumask_copy(wq_unbound_cpumask, saved_cpumask);
 
+               free_cpumask_var(saved_cpumask);
+out_unlock:
                apply_wqattrs_unlock();
        }
 
-       free_cpumask_var(saved_cpumask);
        return ret;
 }