All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Subject: Re: [PATCH 3/3] io_uring: briefly loose locks while reaping events
Date: Mon, 6 Jul 2020 17:45:29 +0300	[thread overview]
Message-ID: <323d7cb4-c88f-9d58-f337-1da61ea54280@gmail.com> (raw)
In-Reply-To: <6a21bbfd-d1b2-09f0-af08-b964b810a449@gmail.com>



On 06/07/2020 17:42, Pavel Begunkov wrote:
> On 06/07/2020 17:31, Jens Axboe wrote:
>> On 7/6/20 8:14 AM, Pavel Begunkov wrote:
>>> It's not nice to hold @uring_lock for too long io_iopoll_reap_events().
>>> For instance, the lock is needed to publish requests to @poll_list, and
>>> that locks out tasks doing that for no good reason. Loose it
>>> occasionally.
>>>
>>> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
>>> ---
>>>  fs/io_uring.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>>> index 020944a193d0..568e25bcadd6 100644
>>> --- a/fs/io_uring.c
>>> +++ b/fs/io_uring.c
>>> @@ -2059,11 +2059,14 @@ static void io_iopoll_reap_events(struct io_ring_ctx *ctx)
>>>  
>>>  		io_iopoll_getevents(ctx, &nr_events, 1);
>>>  
>>> +		/* task_work takes the lock to publish a req to @poll_list */
>>> +		mutex_unlock(&ctx->uring_lock);
>>>  		/*
>>>  		 * Ensure we allow local-to-the-cpu processing to take place,
>>>  		 * in this case we need to ensure that we reap all events.
>>>  		 */
>>>  		cond_resched();
>>> +		mutex_lock(&ctx->uring_lock);
>>>  	}
>>>  	mutex_unlock(&ctx->uring_lock);
>>>  }
>>
>> This would be much better written as:
>>
>> if (need_resched()) {
>> 	mutex_unlock(&ctx->uring_lock);
>> 	cond_resched();
>> 	mutex_lock(&ctx->uring_lock);
>> }
>>
>> to avoid shuffling the lock when not needed to. Every cycle counts for
>> polled IO.
> 
> It happens only when io_uring is being killed, can't imagine any sane app
> trying to catch CQEs after doing that. I'll resend

Also, io_iopoll_getevents() already does need_resched(). Hmm, do you wan't
me to resend?

-- 
Pavel Begunkov

  reply	other threads:[~2020-07-06 14:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 14:14 [PATCH 0/3] iopoll improvements Pavel Begunkov
2020-07-06 14:14 ` [PATCH 1/3] io_uring: don't delay iopoll'ed req completion Pavel Begunkov
2020-07-06 14:14 ` [PATCH 2/3] io_uring: fix stopping iopoll'ing too early Pavel Begunkov
2020-07-06 14:14 ` [PATCH 3/3] io_uring: briefly loose locks while reaping events Pavel Begunkov
2020-07-06 14:31   ` Jens Axboe
2020-07-06 14:42     ` Pavel Begunkov
2020-07-06 14:45       ` Pavel Begunkov [this message]
2020-07-06 14:50         ` 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=323d7cb4-c88f-9d58-f337-1da61ea54280@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.