Commit d364d9e5 authored by Jens Axboe's avatar Jens Axboe

io-wq: wait for manager exit on wq destroy

The manager waits for the workers, hence the manager is always valid if
workers are running. Now also have wq destroy wait for the manager on
exit, so we now everything is gone.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent dbf99620
...@@ -119,6 +119,7 @@ struct io_wq { ...@@ -119,6 +119,7 @@ struct io_wq {
refcount_t refs; refcount_t refs;
struct completion started; struct completion started;
struct completion exited;
atomic_t worker_refs; atomic_t worker_refs;
struct completion worker_done; struct completion worker_done;
...@@ -771,6 +772,7 @@ static int io_wq_manager(void *data) ...@@ -771,6 +772,7 @@ static int io_wq_manager(void *data)
if (atomic_read(&wq->worker_refs)) if (atomic_read(&wq->worker_refs))
wait_for_completion(&wq->worker_done); wait_for_completion(&wq->worker_done);
wq->manager = NULL; wq->manager = NULL;
complete(&wq->exited);
io_wq_put(wq); io_wq_put(wq);
do_exit(0); do_exit(0);
} }
...@@ -1066,6 +1068,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data) ...@@ -1066,6 +1068,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
wq->task_pid = current->pid; wq->task_pid = current->pid;
init_completion(&wq->started); init_completion(&wq->started);
init_completion(&wq->exited);
refcount_set(&wq->refs, 1); refcount_set(&wq->refs, 1);
init_completion(&wq->worker_done); init_completion(&wq->worker_done);
...@@ -1095,8 +1098,10 @@ static void io_wq_destroy(struct io_wq *wq) ...@@ -1095,8 +1098,10 @@ static void io_wq_destroy(struct io_wq *wq)
cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node); cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
set_bit(IO_WQ_BIT_EXIT, &wq->state); set_bit(IO_WQ_BIT_EXIT, &wq->state);
if (wq->manager) if (wq->manager) {
wake_up_process(wq->manager); wake_up_process(wq->manager);
wait_for_completion(&wq->exited);
}
spin_lock_irq(&wq->hash->wait.lock); spin_lock_irq(&wq->hash->wait.lock);
for_each_node(node) { for_each_node(node) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment