Skip to content

Commit 65d4302

Browse files
committed
io-wq: wait for worker startup when forking a new one
We need to have our worker count updated before continuing, to avoid cases where we repeatedly think we need a new worker, but a fork is already in progress. Signed-off-by: Jens Axboe <[email protected]>
1 parent fe07bfd commit 65d4302

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/io-wq.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct io_worker {
5656
const struct cred *saved_creds;
5757

5858
struct completion ref_done;
59+
struct completion started;
5960

6061
struct rcu_head rcu;
6162
};
@@ -267,6 +268,7 @@ static void io_worker_start(struct io_worker *worker)
267268
{
268269
worker->flags |= (IO_WORKER_F_UP | IO_WORKER_F_RUNNING);
269270
io_wqe_inc_running(worker);
271+
complete(&worker->started);
270272
}
271273

272274
/*
@@ -644,6 +646,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
644646
worker->wqe = wqe;
645647
spin_lock_init(&worker->lock);
646648
init_completion(&worker->ref_done);
649+
init_completion(&worker->started);
647650

648651
refcount_inc(&wq->refs);
649652

@@ -656,6 +659,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
656659
kfree(worker);
657660
return false;
658661
}
662+
wait_for_completion(&worker->started);
659663
return true;
660664
}
661665

0 commit comments

Comments
 (0)