From: Xiaoguang Wang <[email protected]>
To: Pavel Begunkov <[email protected]>, [email protected]
Cc: [email protected]
Subject: Re: [PATCH v3 3/3] io_uring: don't get completion_lock in io_poll_rewait()
Date: Fri, 29 Oct 2021 13:59:18 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
hi,
> On 10/25/21 06:38, Xiaoguang Wang wrote:
>> In current implementation, if there are not available events,
>> io_poll_rewait() just gets completion_lock, and unlocks it in
>> io_poll_task_func() or io_async_task_func(), which isn't necessary.
>>
>> Change this logic to let io_poll_task_func() or io_async_task_func()
>> get the completion_lock lock.
>>
>> Signed-off-by: Xiaoguang Wang <[email protected]>
>> ---
>> fs/io_uring.c | 58
>> ++++++++++++++++++++++++++--------------------------------
>> 1 file changed, 26 insertions(+), 32 deletions(-)
>>
>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>> index e4c779dac953..41ff8fdafe55 100644
>> --- a/fs/io_uring.c
>> +++ b/fs/io_uring.c
>> @@ -5248,10 +5248,7 @@ static inline int __io_async_wake(struct
>> io_kiocb *req, struct io_poll_iocb *pol
>> }
>> static bool io_poll_rewait(struct io_kiocb *req, struct
>> io_poll_iocb *poll)
>> - __acquires(&req->ctx->completion_lock)
>> {
>> - struct io_ring_ctx *ctx = req->ctx;
>> -
>> /* req->task == current here, checking PF_EXITING is safe */
>> if (unlikely(req->task->flags & PF_EXITING))
>> WRITE_ONCE(poll->canceled, true);
>> @@ -5262,7 +5259,6 @@ static bool io_poll_rewait(struct io_kiocb
>> *req, struct io_poll_iocb *poll)
>> req->result = vfs_poll(req->file, &pt) & poll->events;
>> }
>> - spin_lock(&ctx->completion_lock);
>
> Don't remember poll sync too well but this was synchronising with the
> final section of __io_arm_poll_handler(), and I'm afraid it may go
> completely loose with races.
Yeah, I understand your concerns, and the final section of
__io_arm_poll_handler() sees
very complicated, it maybe need better cleanup.
After checking my patch and __io_arm_poll_handler() again, I think the
race which maybe
introduced in my patch is that:
1) __io_arm_poll_handler() calls list_del_init(&poll->wait.entry)
under completion_lock.
2) io_poll_rewait calls add_wait_queue() without completion_lock.
But __io_arm_poll_handler() only calls list_del_init(&poll->wait.entry)
when mask isn't zero.
and io_poll_rewait() only calls add_wait_queue when no real event
happens(mask is zero).
So 1) and 2) should not happen at the same time, seems that there's no race.
Regards,
Xiaoguang Wang
>
>
>> if (!req->result && !READ_ONCE(poll->canceled)) {
>> if (req->opcode == IORING_OP_POLL_ADD)
>> WRITE_ONCE(poll->active, true);
next prev parent reply other threads:[~2021-10-29 5:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-25 5:38 [PATCH v3 0/3] improvements for multi-shot poll requests Xiaoguang Wang
2021-10-25 5:38 ` [PATCH v3 1/3] io_uring: refactor event check out of __io_async_wake() Xiaoguang Wang
2021-10-25 9:35 ` Praveen Kumar
2021-10-25 5:38 ` [PATCH v3 2/3] io_uring: reduce frequent add_wait_queue() overhead for multi-shot poll request Xiaoguang Wang
2021-10-28 19:21 ` Pavel Begunkov
2021-10-29 2:57 ` Xiaoguang Wang
2021-10-29 10:02 ` Pavel Begunkov
2021-10-29 13:37 ` Xiaoguang Wang
2021-10-29 13:47 ` Pavel Begunkov
2021-10-29 14:12 ` Pavel Begunkov
2021-10-29 14:34 ` Xiaoguang Wang
2021-10-25 5:38 ` [PATCH v3 3/3] io_uring: don't get completion_lock in io_poll_rewait() Xiaoguang Wang
2021-10-28 19:26 ` Pavel Begunkov
2021-10-29 5:59 ` Xiaoguang Wang [this message]
2021-10-28 18:19 ` [PATCH v3 0/3] improvements for multi-shot poll requests Jens Axboe
2021-10-29 18:29 ` Jens Axboe
2021-10-28 18:19 ` Jens Axboe
2021-10-28 19:01 ` Pavel Begunkov
2021-10-28 19:04 ` Pavel Begunkov
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=e989d607-f4d3-bf90-767d-90c7716df895@linux.alibaba.com \
[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