diff mbox series

[01/11] io-wq: fix worker counting after worker received exit signal

Message ID 20230609122031.183730-2-hao.xu@linux.dev (mailing list archive)
State New
Headers show
Series fixed worker | expand

Commit Message

Hao Xu June 9, 2023, 12:20 p.m. UTC
From: Hao Xu <howeyxu@tencent.com>

acct->nr_workers should be decremented when we break the loop in
io_wq_worker().

Fixes: 78f8876c2d9f ("io-wq: exclusively gate signal based exit on get_signal() return")
Signed-off-by: Hao Xu <howeyxu@tencent.com>
---
 io_uring/io-wq.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Pavel Begunkov July 5, 2023, 12:10 p.m. UTC | #1
On 6/9/23 13:20, Hao Xu wrote:
> From: Hao Xu <howeyxu@tencent.com>
> 
> acct->nr_workers should be decremented when we break the loop in
> io_wq_worker().
> 
> Fixes: 78f8876c2d9f ("io-wq: exclusively gate signal based exit on get_signal() return")
> Signed-off-by: Hao Xu <howeyxu@tencent.com>
> ---
>   io_uring/io-wq.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
> index b2715988791e..b70eebec2845 100644
> --- a/io_uring/io-wq.c
> +++ b/io_uring/io-wq.c
> @@ -634,6 +634,10 @@ static int io_wq_worker(void *data)
>   
>   			if (!get_signal(&ksig))
>   				continue;
> +
> +			raw_spin_lock(&wq->lock);
> +			acct->nr_workers--;
> +			raw_spin_unlock(&wq->lock);

Wouldn't it suffer the same race you fixed with the following?

commit 767a65e9f31789d80e41edd03a802314905e8fbf
Author: Hao Xu <haoxu@linux.alibaba.com>
Date:   Sun Sep 12 03:40:52 2021 +0800

     io-wq: fix potential race of acct->nr_workers



Even more, seems we fail to decrement nr_workers when the loop condition
fails, i.e.

	while (!test_bit(IO_WQ_BIT_EXIT, &wq->state)) {


I.e. the patch looks legit, but what we currently have is a mess and we
have more work to do.
diff mbox series

Patch

diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
index b2715988791e..b70eebec2845 100644
--- a/io_uring/io-wq.c
+++ b/io_uring/io-wq.c
@@ -634,6 +634,10 @@  static int io_wq_worker(void *data)
 
 			if (!get_signal(&ksig))
 				continue;
+
+			raw_spin_lock(&wq->lock);
+			acct->nr_workers--;
+			raw_spin_unlock(&wq->lock);
 			break;
 		}
 		if (!ret) {