Re: [PATCH 1/2] io-wq: fix bug of creating io-wokers unconditionally

From
Jens Axboe <axboe@kernel.dk>
Date
2021-08-09 14:01:44
Reply to
Hao Xu, 2021-08-08
On 8/8/21 7:54 AM, Hao Xu wrote:
quoted hunk ↗ jump to hunk
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: 21698274da5b ("io-wq: fix lack of acct->nr_workers < acct->max_workers judgement")
Signed-off-by: Hao Xu <redacted>
---
 fs/io-wq.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/fs/io-wq.c b/fs/io-wq.c
index 12fc19353bb0..5536b2a008d1 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -252,14 +252,15 @@ static void io_wqe_wake_worker(struct io_wqe *wqe, struct io_wqe_acct *acct)
 
 		raw_spin_lock_irq(&wqe->lock);
 		if (acct->nr_workers < acct->max_workers) {
-			atomic_inc(&acct->nr_running);
-			atomic_inc(&wqe->wq->worker_refs);
 			acct->nr_workers++;
 			do_create = true;
 		}
 		raw_spin_unlock_irq(&wqe->lock);
-		if (do_create)
+		if (do_create) {
+			atomic_inc(&acct->nr_running);
+			atomic_inc(&wqe->wq->worker_refs);
 			create_io_worker(wqe->wq, wqe, acct->index);
+		}
 	}
I don't get this hunk - we already know we're creating a worker, what's the
point in moving the incs?

-- 
Jens Axboe
Thread (7 messages) 7 messages, 2 authors, last reply 2021-08-09
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help