Skip to content

Commit 3f0ea0b

Browse files
pmladekhtejun
authored andcommitted
workqueue: Warn when a new worker could not be created
The workqueue watchdog reports a lockup when there was not any progress in the worker pool for a long time. The progress means that a pending work item starts being proceed. The progress is guaranteed by using idle workers or creating new workers for pending work items. There are several reasons why a new worker could not be created: + there is not enough memory + there is no free pool ID (IDR API) + the system reached PID limit + the process creating the new worker was interrupted + the last idle worker (manager) has not been scheduled for a long time. It was not able to even start creating the kthread. None of these failures is reported at the moment. The only clue is that show_one_worker_pool() prints that there is a manager. It is the last idle worker that is responsible for creating a new one. But it is not clear if create_worker() is failing and why. Make the debugging easier by printing errors in create_worker(). The error code is important, especially from kthread_create_on_node(). It helps to distinguish the various reasons. For example, reaching memory limit (-ENOMEM), other system limits (-EAGAIN), or process interrupted (-EINTR). Use pr_once() to avoid repeating the same error every CREATE_COOLDOWN for each stuck worker pool. Ratelimited printk() might be better. It would help to know if the problem remains. It would be more clear if the create_worker() errors and workqueue stalls are related. Also old messages might get lost when the internal log buffer is full. The problem is that printk() might touch the watchdog. For example, see touch_nmi_watchdog() in serial8250_console_write(). It would require synchronization of the begin and length of the ratelimit interval with the workqueue watchdog. Otherwise, the error messages might break the watchdog. This does not look worth the complexity. Signed-off-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 335a42e commit 3f0ea0b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

kernel/workqueue.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,12 +1936,17 @@ static struct worker *create_worker(struct worker_pool *pool)
19361936

19371937
/* ID is needed to determine kthread name */
19381938
id = ida_alloc(&pool->worker_ida, GFP_KERNEL);
1939-
if (id < 0)
1939+
if (id < 0) {
1940+
pr_err_once("workqueue: Failed to allocate a worker ID: %pe\n",
1941+
ERR_PTR(id));
19401942
return NULL;
1943+
}
19411944

19421945
worker = alloc_worker(pool->node);
1943-
if (!worker)
1946+
if (!worker) {
1947+
pr_err_once("workqueue: Failed to allocate a worker\n");
19441948
goto fail;
1949+
}
19451950

19461951
worker->id = id;
19471952

@@ -1953,8 +1958,11 @@ static struct worker *create_worker(struct worker_pool *pool)
19531958

19541959
worker->task = kthread_create_on_node(worker_thread, worker, pool->node,
19551960
"kworker/%s", id_buf);
1956-
if (IS_ERR(worker->task))
1961+
if (IS_ERR(worker->task)) {
1962+
pr_err_once("workqueue: Failed to create a worker thread: %pe",
1963+
worker->task);
19571964
goto fail;
1965+
}
19581966

19591967
set_user_nice(worker->task, pool->attrs->nice);
19601968
kthread_bind_mask(worker->task, pool->attrs->cpumask);

0 commit comments

Comments
 (0)