Skip to content

Commit

Permalink
io-wq: wait for worker startup when forking a new one
Browse files Browse the repository at this point in the history
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 <axboe@kernel.dk>
  • Loading branch information
Jens Axboe committed Mar 1, 2021
1 parent fe07bfd commit 65d4302
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs/io-wq.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct io_worker {
const struct cred *saved_creds;

struct completion ref_done;
struct completion started;

struct rcu_head rcu;
};
Expand Down Expand Up @@ -267,6 +268,7 @@ static void io_worker_start(struct io_worker *worker)
{
worker->flags |= (IO_WORKER_F_UP | IO_WORKER_F_RUNNING);
io_wqe_inc_running(worker);
complete(&worker->started);
}

/*
Expand Down Expand Up @@ -644,6 +646,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
worker->wqe = wqe;
spin_lock_init(&worker->lock);
init_completion(&worker->ref_done);
init_completion(&worker->started);

refcount_inc(&wq->refs);

Expand All @@ -656,6 +659,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
kfree(worker);
return false;
}
wait_for_completion(&worker->started);
return true;
}

Expand Down

0 comments on commit 65d4302

Please sign in to comment.