Skip to content

Commit bc36992

Browse files
isilenceaxboe
authored andcommitted
io-wq: max_worker fixes
First, fix nr_workers checks against max_workers, with max_worker registration, it may pretty easily happen that nr_workers > max_workers. Also, synchronise writing to acct->max_worker with wqe->lock. It's not an actual problem, but as we don't care about io_wqe_create_worker(), it's better than WRITE_ONCE()/READ_ONCE(). Fixes: 2e48005 ("io-wq: provide a way to limit max number of workers") Reported-by: Beld Zhang <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/11f90e6b49410b7d1a88f5d04fb8d95bb86b8cf3.1634671835.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 14cfbb7 commit bc36992

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/io-wq.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static bool io_wqe_create_worker(struct io_wqe *wqe, struct io_wqe_acct *acct)
253253
pr_warn_once("io-wq is not configured for unbound workers");
254254

255255
raw_spin_lock(&wqe->lock);
256-
if (acct->nr_workers == acct->max_workers) {
256+
if (acct->nr_workers >= acct->max_workers) {
257257
raw_spin_unlock(&wqe->lock);
258258
return true;
259259
}
@@ -1291,15 +1291,18 @@ int io_wq_max_workers(struct io_wq *wq, int *new_count)
12911291

12921292
rcu_read_lock();
12931293
for_each_node(node) {
1294+
struct io_wqe *wqe = wq->wqes[node];
12941295
struct io_wqe_acct *acct;
12951296

1297+
raw_spin_lock(&wqe->lock);
12961298
for (i = 0; i < IO_WQ_ACCT_NR; i++) {
1297-
acct = &wq->wqes[node]->acct[i];
1299+
acct = &wqe->acct[i];
12981300
prev = max_t(int, acct->max_workers, prev);
12991301
if (new_count[i])
13001302
acct->max_workers = new_count[i];
13011303
new_count[i] = prev;
13021304
}
1305+
raw_spin_unlock(&wqe->lock);
13031306
}
13041307
rcu_read_unlock();
13051308
return 0;

0 commit comments

Comments
 (0)