]> www.infradead.org Git - linux.git/commitdiff
async: Use a dedicated unbound workqueue with raised min_active
authorTejun Heo <tj@kernel.org>
Fri, 9 Feb 2024 00:14:16 +0000 (14:14 -1000)
committerTejun Heo <tj@kernel.org>
Fri, 9 Feb 2024 21:13:59 +0000 (11:13 -1000)
Async can schedule a number of interdependent work items. However, since
5797b1c18919 ("workqueue: Implement system-wide nr_active enforcement for
unbound workqueues"), unbound workqueues have separate min_active which sets
the number of interdependent work items that can be handled. This default
value is 8 which isn't sufficient for async and can lead to stalls during
resume from suspend in some cases.

Let's use a dedicated unbound workqueue with raised min_active.

Link: http://lkml.kernel.org/r/708a65cc-79ec-44a6-8454-a93d0f3114c3@samsung.com
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/async.h
init/main.c
kernel/async.c

index 33c9ff4afb492f4852d503f53f88029b7a72c797..19b778d08600f1d1e1bf25a8cd0e8a390b39cac5 100644 (file)
@@ -120,4 +120,5 @@ extern void async_synchronize_cookie(async_cookie_t cookie);
 extern void async_synchronize_cookie_domain(async_cookie_t cookie,
                                            struct async_domain *domain);
 extern bool current_is_async(void);
+extern void async_init(void);
 #endif
index e24b0780fdff7a807bd027ab26e61fc303c624ef..685db36c999f3456013fe9dd93274bf4d9b72237 100644 (file)
@@ -1545,6 +1545,7 @@ static noinline void __init kernel_init_freeable(void)
        sched_init_smp();
 
        workqueue_init_topology();
+       async_init();
        padata_init();
        page_alloc_init_late();
 
index 97f224a5257b4e49ed959580ae1566a46e09f3fe..4c3e6a44595fa176f06108c869d164cca26546a1 100644 (file)
@@ -64,6 +64,7 @@ static async_cookie_t next_cookie = 1;
 static LIST_HEAD(async_global_pending);        /* pending from all registered doms */
 static ASYNC_DOMAIN(async_dfl_domain);
 static DEFINE_SPINLOCK(async_lock);
+static struct workqueue_struct *async_wq;
 
 struct async_entry {
        struct list_head        domain_list;
@@ -174,7 +175,7 @@ static async_cookie_t __async_schedule_node_domain(async_func_t func,
        spin_unlock_irqrestore(&async_lock, flags);
 
        /* schedule for execution */
-       queue_work_node(node, system_unbound_wq, &entry->work);
+       queue_work_node(node, async_wq, &entry->work);
 
        return newcookie;
 }
@@ -345,3 +346,17 @@ bool current_is_async(void)
        return worker && worker->current_func == async_run_entry_fn;
 }
 EXPORT_SYMBOL_GPL(current_is_async);
+
+void __init async_init(void)
+{
+       /*
+        * Async can schedule a number of interdependent work items. However,
+        * unbound workqueues can handle only upto min_active interdependent
+        * work items. The default min_active of 8 isn't sufficient for async
+        * and can lead to stalls. Let's use a dedicated workqueue with raised
+        * min_active.
+        */
+       async_wq = alloc_workqueue("async", WQ_UNBOUND, 0);
+       BUG_ON(!async_wq);
+       workqueue_set_min_active(async_wq, WQ_DFL_ACTIVE);
+}