public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Hao Xu <[email protected]>, [email protected]
Cc: Jens Axboe <[email protected]>, Wanpeng Li <[email protected]>,
	[email protected]
Subject: Re: [PATCH 05/11] io-wq: add a new parameter for creating a new fixed worker
Date: Wed, 5 Jul 2023 13:54:45 +0100	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 6/9/23 13:20, Hao Xu wrote:
> From: Hao Xu <[email protected]>
> 
> Add a new parameter when creating new workers to indicate if users
> want a normal or fixed worker.
> 
> Signed-off-by: Hao Xu <[email protected]>
> ---
>   io_uring/io-wq.c | 33 ++++++++++++++++++++-------------
>   1 file changed, 20 insertions(+), 13 deletions(-)
> 
> diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
> index bf9e9af8d9ca..048856eef4d4 100644
> --- a/io_uring/io-wq.c
> +++ b/io_uring/io-wq.c
[...]
>   
> +static bool is_fixed_worker(struct io_worker *worker)
> +{
> +	return worker->flags & IO_WORKER_F_FIXED;
> +} 

That's what I mentioned in the other comment.

> +
>   static void create_worker_cb(struct callback_head *cb)
>   {
>   	struct io_worker *worker;
> @@ -331,7 +337,7 @@ static void create_worker_cb(struct callback_head *cb)
>   	}
>   	raw_spin_unlock(&wq->lock);
>   	if (do_create) {
> -		create_io_worker(wq, worker->create_index);
> +		create_io_worker(wq, worker->create_index, is_fixed_worker(worker));
>   	} else {
>   		atomic_dec(&acct->nr_running);
>   		io_worker_ref_put(wq);
> @@ -398,6 +404,8 @@ static void io_wq_dec_running(struct io_worker *worker)
>   		return;
>   	if (!io_acct_run_queue(acct))
>   		return;
> +	if (is_fixed_worker(worker))
> +		return;

Aha, it's here. I was thinking about it a little bit more.
Is it even correct? If you have a mixed fixed/non-fixed setup
you presumably want non-fixed workers to kick in such situations.
I don't remember this creation voodoo well, maybe Jens does have
an idea.

>   
>   	atomic_inc(&acct->nr_running);
>   	atomic_inc(&wq->worker_refs);
> @@ -601,11 +609,6 @@ static bool is_worker_exiting(struct io_worker *worker)
>   	return worker->flags & IO_WORKER_F_EXIT;
>   }
[...]
> -static bool create_io_worker(struct io_wq *wq, int index)
> +static bool create_io_worker(struct io_wq *wq, int index, bool fixed)
>   {
>   	struct io_wq_acct *acct = &wq->acct[index];
>   	struct io_worker *worker;
> @@ -833,10 +836,14 @@ static bool create_io_worker(struct io_wq *wq, int index)
>   	if (index == IO_WQ_ACCT_BOUND)
>   		worker->flags |= IO_WORKER_F_BOUND;
>   
> +	if (fixed)
> +		worker->flags |= IO_WORKER_F_FIXED;
> +
>   	tsk = create_io_thread(io_wq_worker, worker, NUMA_NO_NODE);
>   	if (!IS_ERR(tsk)) {
> -		io_init_new_worker(wq, worker, tsk);
> -	} else if (!io_should_retry_thread(PTR_ERR(tsk))) {
> +		if (!fixed)
> +			io_init_new_worker(wq, worker, tsk);

Why do we skip io_init_new_worker()? I assume you putting it
into lists, but what about the rest? I.e.

	tsk->worker_private = worker;
	worker->task = tsk;
	set_cpus_allowed_ptr(tsk, wq->cpu_mask);


> +	} else if (fixed || !io_should_retry_thread(PTR_ERR(tsk))) {
>   		kfree(worker);
>   		goto fail;
>   	} else {
> @@ -947,7 +954,7 @@ void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work)
>   	    !atomic_read(&acct->nr_running))) {
>   		bool did_create;
>   
> -		did_create = io_wq_create_worker(wq, acct);
> +		did_create = io_wq_create_worker(wq, acct, false);
>   		if (likely(did_create))
>   			return;

-- 
Pavel Begunkov

  reply	other threads:[~2023-07-05 12:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09 12:20 [RFC PATCH 00/11] fixed worker Hao Xu
2023-06-09 12:20 ` [PATCH 01/11] io-wq: fix worker counting after worker received exit signal Hao Xu
2023-07-05 12:10   ` Pavel Begunkov
2023-06-09 12:20 ` [PATCH 02/11] io-wq: add a new worker flag to indicate worker exit Hao Xu
2023-07-05 12:16   ` Pavel Begunkov
2023-06-09 12:20 ` [PATCH 03/11] io-wq: add a new type io-wq worker Hao Xu
2023-07-05 12:26   ` Pavel Begunkov
2023-06-09 12:20 ` [PATCH 04/11] io-wq: add fixed worker members in io_wq_acct Hao Xu
2023-06-09 12:20 ` [PATCH 05/11] io-wq: add a new parameter for creating a new fixed worker Hao Xu
2023-07-05 12:54   ` Pavel Begunkov [this message]
2023-06-09 12:20 ` [PATCH 06/11] io-wq: return io_worker after successful inline worker creation Hao Xu
2023-07-05 13:05   ` Pavel Begunkov
2023-06-09 12:20 ` [PATCH 07/11] io_uring: add new api to register fixed workers Hao Xu
2023-06-09 13:07   ` Ammar Faizi
2023-06-12 13:46     ` Hao Xu
2023-06-09 13:54   ` Ammar Faizi
2023-06-12 13:47     ` Hao Xu
2023-07-05 13:10   ` Pavel Begunkov
2023-06-09 12:20 ` [PATCH 08/11] io_uring: add function to unregister " Hao Xu
2023-07-05 13:13   ` Pavel Begunkov
2023-06-09 12:20 ` [PATCH 09/11] io-wq: add strutures to allow to wait fixed workers exit Hao Xu
2023-06-09 12:20 ` [PATCH 10/11] io-wq: distinguish fixed worker by its name Hao Xu
2023-07-05 13:15   ` Pavel Begunkov
2023-06-09 12:20 ` [PATCH 11/11] io_uring: add IORING_SETUP_FIXED_WORKER_ONLY and its friend Hao Xu
2023-07-05 13:17   ` Pavel Begunkov
2023-06-20 12:35 ` [RFC PATCH 00/11] fixed worker Hao Xu
2023-06-28  9:19 ` Hao Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox