public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Xiaoguang Wang <[email protected]>,
	[email protected]
Cc: [email protected], [email protected]
Subject: Re: [PATCH] io_uring: reduce one unnecessary io_sqring_entries() call
Date: Sat, 9 Jan 2021 17:02:34 +0000	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 08/01/2021 08:36, Xiaoguang Wang wrote:
> In __io_sq_thread(), we have gotten the number of sqes to submit,
> then in io_submit_sqes(), we can use this number directly, no need
> to call io_sqring_entries() again in io_submit_sqes().
> 
> Signed-off-by: Xiaoguang Wang <[email protected]>
> ---
>  fs/io_uring.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index ca46f314640b..200a9eb72788 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -6830,9 +6830,6 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
>  			return -EBUSY;
>  	}
>  
> -	/* make sure SQ entry isn't read before tail */
> -	nr = min3(nr, ctx->sq_entries, io_sqring_entries(ctx));

the userspace can modify rings->sq.tail, and so io_sqring_entries()
can turn out to be very large. sqpoll still needs min(ctx->sq_entries, ...)

> -
>  	if (!percpu_ref_tryget_many(&ctx->refs, nr))
>  		return -EAGAIN;
>  
> @@ -9211,6 +9208,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
>  		if (unlikely(ret))
>  			goto out;
>  		mutex_lock(&ctx->uring_lock);
> +		/* make sure SQ entry isn't read before tail */
> +		to_submit = min3(to_submit, ctx->sq_entries, io_sqring_entries(ctx));
>  		submitted = io_submit_sqes(ctx, to_submit);
>  		mutex_unlock(&ctx->uring_lock);
>  
> 

-- 
Pavel Begunkov

      reply	other threads:[~2021-01-09 17:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08  8:36 [PATCH] io_uring: reduce one unnecessary io_sqring_entries() call Xiaoguang Wang
2021-01-09 17:02 ` Pavel Begunkov [this message]

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] \
    /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