Skip to content

Commit cd4ea81

Browse files
MaxKellermannaxboe
authored andcommitted
io_uring/io-wq: fix max_workers breakage and nr_workers underflow
Commit 88e6c42 ("io_uring/io-wq: add check free worker before create new worker") reused the variable `do_create` for something else, abusing it for the free worker check. This caused the value to effectively always be `true` at the time `nr_workers < max_workers` was checked, but it should really be `false`. This means the `max_workers` setting was ignored, and worse: if the limit had already been reached, incrementing `nr_workers` was skipped even though another worker would be created. When later lots of workers exit, the `nr_workers` field could easily underflow, making the problem worse because more and more workers would be created without incrementing `nr_workers`. The simple solution is to use a different variable for the free worker check instead of using one variable for two different things. Cc: stable@vger.kernel.org Fixes: 88e6c42 ("io_uring/io-wq: add check free worker before create new worker") Signed-off-by: Max Kellermann <max.kellermann@ionos.com> Reviewed-by: Fengnan Chang <changfengnan@bytedance.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 98b6fa6 commit cd4ea81

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

io_uring/io-wq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,16 @@ static void create_worker_cb(struct callback_head *cb)
352352
struct io_wq *wq;
353353

354354
struct io_wq_acct *acct;
355-
bool do_create = false;
355+
bool activated_free_worker, do_create = false;
356356

357357
worker = container_of(cb, struct io_worker, create_work);
358358
wq = worker->wq;
359359
acct = worker->acct;
360360

361361
rcu_read_lock();
362-
do_create = !io_acct_activate_free_worker(acct);
362+
activated_free_worker = io_acct_activate_free_worker(acct);
363363
rcu_read_unlock();
364-
if (!do_create)
364+
if (activated_free_worker)
365365
goto no_need_create;
366366

367367
raw_spin_lock(&acct->workers_lock);

0 commit comments

Comments
 (0)