public inbox for [email protected]
 help / color / mirror / Atom feed
From: Hao Xu <[email protected]>
To: Jens Axboe <[email protected]>, io-uring <[email protected]>
Subject: Re: [PATCH] io-wq: check max_worker limits if a worker transitions bound state
Date: Mon, 30 Aug 2021 11:06:15 +0800	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

在 2021/8/30 上午6:19, Jens Axboe 写道:
> For the two places where new workers are created, we diligently check if
> we are allowed to create a new worker. If we're currently at the limit
> of how many workers of a given type we can have, then we don't create
> any new ones.
> 
> If you have a mixed workload with various types of bound and unbounded
> work, then it can happen that a worker finishes one type of work and
> is then transitioned to the other type. For this case, we don't check
> if we are actually allowed to do so. This can cause io-wq to temporarily
> exceed the allowed number of workers for a given type.
> 
> When retrieving work, check that the types match. If they don't, check
> if we are allowed to transition to the other type. If not, then don't
> handle the new work.
> 
> Cc: [email protected]
> Reported-by: Johannes Lundberg <[email protected]>
> Signed-off-by: Jens Axboe <[email protected]>
> 
> ---
> 
> diff --git a/fs/io-wq.c b/fs/io-wq.c
> index 4b5fc621ab39..dced22288983 100644
> --- a/fs/io-wq.c
> +++ b/fs/io-wq.c
> @@ -424,7 +424,31 @@ static void io_wait_on_hash(struct io_wqe *wqe, unsigned int hash)
>   	spin_unlock(&wq->hash->wait.lock);
>   }
>   
> -static struct io_wq_work *io_get_next_work(struct io_wqe *wqe)
> +/*
> + * We can always run the work if the worker is currently the same type as
> + * the work (eg both are bound, or both are unbound). If they are not the
> + * same, only allow it if incrementing the worker count would be allowed.
> + */
> +static bool io_worker_can_run_work(struct io_worker *worker,
> +				   struct io_wq_work *work)
> +{
> +	struct io_wqe_acct *acct;
> +
> +	if ((worker->flags & IO_WORKER_F_BOUND) &&
> +	    !(work->flags & IO_WQ_WORK_UNBOUND))
> +		return true;
> +	else if (!(worker->flags & IO_WORKER_F_BOUND) &&
> +		 (work->flags & IO_WQ_WORK_UNBOUND))
> +		return true;

How about:
bool a = !(worker->flags & IO_WORKER_F_BOUND);
bool b = !(work->flags & IO_WQ_WORK_UNBOUND);

if (a != b)
     return true;
> +
> +	/* not the same type, check if we'd go over the limit */
> +	acct = io_work_get_acct(worker->wqe, work);
> +	return acct->nr_workers < acct->max_workers;
> +}
> +



  reply	other threads:[~2021-08-30  3:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-29 22:19 [PATCH] io-wq: check max_worker limits if a worker transitions bound state Jens Axboe
2021-08-30  3:06 ` Hao Xu [this message]
2021-08-30 12:20   ` Jens Axboe

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 \
    --in-reply-to=10bab869-3875-4510-e38a-03193f0b6dfa@linux.alibaba.com \
    [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