Skip to content

Commit 49e7f0c

Browse files
Hao Xuaxboe
authored andcommitted
io-wq: fix bug of creating io-wokers unconditionally
The former patch to add check between nr_workers and max_workers has a bug, which will cause unconditionally creating io-workers. That's because the result of the check doesn't affect the call of create_io_worker(), fix it by bringing in a boolean value for it. Fixes: 2169827 ("io-wq: fix lack of acct->nr_workers < acct->max_workers judgement") Signed-off-by: Hao Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected] [axboe: drop hunk that isn't strictly needed] Signed-off-by: Jens Axboe <[email protected]>
1 parent 4956b9e commit 49e7f0c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fs/io-wq.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,24 @@ static void create_worker_cb(struct callback_head *cb)
282282
struct io_wq *wq;
283283
struct io_wqe *wqe;
284284
struct io_wqe_acct *acct;
285+
bool do_create = false;
285286

286287
cwd = container_of(cb, struct create_worker_data, work);
287288
wqe = cwd->wqe;
288289
wq = wqe->wq;
289290
acct = &wqe->acct[cwd->index];
290291
raw_spin_lock_irq(&wqe->lock);
291-
if (acct->nr_workers < acct->max_workers)
292+
if (acct->nr_workers < acct->max_workers) {
292293
acct->nr_workers++;
294+
do_create = true;
295+
}
293296
raw_spin_unlock_irq(&wqe->lock);
294-
create_io_worker(wq, cwd->wqe, cwd->index);
297+
if (do_create) {
298+
create_io_worker(wq, cwd->wqe, cwd->index);
299+
} else {
300+
atomic_dec(&acct->nr_running);
301+
io_worker_ref_put(wq);
302+
}
295303
kfree(cwd);
296304
}
297305

0 commit comments

Comments
 (0)