Message ID | 20230609122031.183730-3-hao.xu@linux.dev (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | fixed worker | expand |
On 6/9/23 13:20, Hao Xu wrote: > From: Hao Xu <howeyxu@tencent.com> > > Add a new worker flag IO_WORKER_F_EXIT to indicate a worker is going to > exit. This is important for fixed workers. nit: would be nice to add a small sentence _how_ it's important for fixed workers > Signed-off-by: Hao Xu <howeyxu@tencent.com> > --- > io_uring/io-wq.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c > index b70eebec2845..1717f1465613 100644 > --- a/io_uring/io-wq.c > +++ b/io_uring/io-wq.c > @@ -29,6 +29,7 @@ enum { > IO_WORKER_F_RUNNING = 2, /* account as running */ > IO_WORKER_F_FREE = 4, /* worker on free list */ > IO_WORKER_F_BOUND = 8, /* is doing bounded work */ > + IO_WORKER_F_EXIT = 16, /* worker is exiting */ > }; > > enum { > @@ -592,6 +593,11 @@ static void io_worker_handle_work(struct io_worker *worker) > } while (1); > } > > +static bool is_worker_exiting(struct io_worker *worker) > +{ > + return worker->flags & IO_WORKER_F_EXIT; > +} > + > static int io_wq_worker(void *data) > { > struct io_worker *worker = data; > @@ -609,7 +615,7 @@ static int io_wq_worker(void *data) > long ret; > > set_current_state(TASK_INTERRUPTIBLE); > - while (io_acct_run_queue(acct)) > + while (!is_worker_exiting(worker) && io_acct_run_queue(acct)) > io_worker_handle_work(worker); Why it differs from the condition in io_wq_dec_running()? Would sth like this work? bool io_worker_run_queue(worker) { return !is_worker_exiting(worker) && io_acct_run_queue(worker_get_acct(worker)); } > > raw_spin_lock(&wq->lock); > @@ -628,6 +634,12 @@ static int io_wq_worker(void *data) > raw_spin_unlock(&wq->lock); > if (io_run_task_work()) > continue; > + if (is_worker_exiting(worker)) { > + raw_spin_lock(&wq->lock); > + acct->nr_workers--; > + raw_spin_unlock(&wq->lock); > + break; > + } > ret = schedule_timeout(WORKER_IDLE_TIMEOUT); > if (signal_pending(current)) { > struct ksignal ksig;
diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c index b70eebec2845..1717f1465613 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -29,6 +29,7 @@ enum { IO_WORKER_F_RUNNING = 2, /* account as running */ IO_WORKER_F_FREE = 4, /* worker on free list */ IO_WORKER_F_BOUND = 8, /* is doing bounded work */ + IO_WORKER_F_EXIT = 16, /* worker is exiting */ }; enum { @@ -592,6 +593,11 @@ static void io_worker_handle_work(struct io_worker *worker) } while (1); } +static bool is_worker_exiting(struct io_worker *worker) +{ + return worker->flags & IO_WORKER_F_EXIT; +} + static int io_wq_worker(void *data) { struct io_worker *worker = data; @@ -609,7 +615,7 @@ static int io_wq_worker(void *data) long ret; set_current_state(TASK_INTERRUPTIBLE); - while (io_acct_run_queue(acct)) + while (!is_worker_exiting(worker) && io_acct_run_queue(acct)) io_worker_handle_work(worker); raw_spin_lock(&wq->lock); @@ -628,6 +634,12 @@ static int io_wq_worker(void *data) raw_spin_unlock(&wq->lock); if (io_run_task_work()) continue; + if (is_worker_exiting(worker)) { + raw_spin_lock(&wq->lock); + acct->nr_workers--; + raw_spin_unlock(&wq->lock); + break; + } ret = schedule_timeout(WORKER_IDLE_TIMEOUT); if (signal_pending(current)) { struct ksignal ksig;