Skip to content

Commit 34c78b8

Browse files
calebsanderaxboe
authored andcommitted
io_uring/io-wq: always retry worker create on ERESTART*
If a task has a pending signal when create_io_thread() is called, copy_process() will return -ERESTARTNOINTR. io_should_retry_thread() will request a retry of create_io_thread() up to WORKER_INIT_LIMIT = 3 times. If all retries fail, the io_uring request will fail with ECANCELED. Commit 3918315c5dc ("io-wq: backoff when retrying worker creation") added a linear backoff to allow the thread to handle its signal before the retry. However, a thread receiving frequent signals may get unlucky and have a signal pending at every retry. Since the userspace task doesn't control when it receives signals, there's no easy way for it to prevent the create_io_thread() failure due to pending signals. The task may also lack the information necessary to regenerate the canceled SQE. So always retry the create_io_thread() on the ERESTART* errors, analogous to what a fork() syscall would do. EAGAIN can occur due to various persistent conditions such as exceeding RLIMIT_NPROC, so respect the WORKER_INIT_LIMIT retry limit for EAGAIN errors. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 84230ad commit 34c78b8

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

io_uring/io-wq.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,12 @@ static inline bool io_should_retry_thread(struct io_worker *worker, long err)
805805
*/
806806
if (fatal_signal_pending(current))
807807
return false;
808-
if (worker->init_retries++ >= WORKER_INIT_LIMIT)
809-
return false;
810808

809+
worker->init_retries++;
811810
switch (err) {
812811
case -EAGAIN:
812+
return worker->init_retries <= WORKER_INIT_LIMIT;
813+
/* Analogous to a fork() syscall, always retry on a restartable error */
813814
case -ERESTARTSYS:
814815
case -ERESTARTNOINTR:
815816
case -ERESTARTNOHAND:

0 commit comments

Comments
 (0)