Skip to content

Commit

Permalink
io-wq: ensure task is running before processing task_work
Browse files Browse the repository at this point in the history
Mark the current task as running if we need to run task_work from the
io-wq threads as part of work handling. If that is the case, then return
as such so that the caller can appropriately loop back and reset if it
was part of a going-to-sleep flush.

Fixes: 3bfe610 ("io-wq: fork worker threads from original task")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jens Axboe committed Mar 21, 2021
1 parent 4db4b1a commit 00ddff4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs/io-wq.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,16 @@ static struct io_wq_work *io_get_next_work(struct io_wqe *wqe)
return NULL;
}

static void io_flush_signals(void)
static bool io_flush_signals(void)
{
if (unlikely(test_tsk_thread_flag(current, TIF_NOTIFY_SIGNAL))) {
__set_current_state(TASK_RUNNING);
if (current->task_works)
task_work_run();
clear_tsk_thread_flag(current, TIF_NOTIFY_SIGNAL);
return true;
}
return false;
}

static void io_assign_current_work(struct io_worker *worker,
Expand Down Expand Up @@ -499,7 +502,8 @@ static int io_wqe_worker(void *data)
}
__io_worker_idle(wqe, worker);
raw_spin_unlock_irq(&wqe->lock);
io_flush_signals();
if (io_flush_signals())
continue;
ret = schedule_timeout(WORKER_IDLE_TIMEOUT);
if (try_to_freeze() || ret)
continue;
Expand Down

0 comments on commit 00ddff4

Please sign in to comment.