* [PATCH liburing] Fix hang in in io_uring_get_cqe() with iopoll
@ 2020-06-21 10:30 Pavel Begunkov
2020-06-21 15:23 ` Jens Axboe
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2020-06-21 10:30 UTC (permalink / raw)
To: Jens Axboe, io-uring
Because of need_resched() check, io_uring_enter() -> io_iopoll_check()
can return 0 even if @min_complete wasn't satisfied. If that's the
case, __io_uring_get_cqe() sets submit=0 and wait_nr=0, disabling
setting IORING_ENTER_GETEVENTS as well. So, it goes crazy calling
io_uring_enter() in a loop, not actually submitting nor polling.
Set @wait_nr based on actual number of CQEs ready.
BTW, atomic_load_acquire() in io_uring_cq_ready() can be replaced
with a relaxed one for this particular place.
Signed-off-by: Pavel Begunkov <[email protected]>
---
src/queue.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/queue.c b/src/queue.c
index 14a0777..638d0ac 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -32,6 +32,14 @@ static inline bool sq_ring_needs_enter(struct io_uring *ring,
return false;
}
+static inline unsigned int io_adjut_wait_nr(struct io_uring *ring,
+ unsigned int to_wait)
+{
+ unsigned int ready = io_uring_cq_ready(ring);
+
+ return (to_wait <= ready) ? 0 : (to_wait - ready);
+}
+
int __io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr,
unsigned submit, unsigned wait_nr, sigset_t *sigmask)
{
@@ -60,7 +68,8 @@ int __io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr,
err = -errno;
} else if (ret == (int)submit) {
submit = 0;
- wait_nr = 0;
+ if (to_wait)
+ wait_nr = io_adjut_wait_nr(ring, to_wait);
} else {
submit -= ret;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH liburing] Fix hang in in io_uring_get_cqe() with iopoll
2020-06-21 10:30 [PATCH liburing] Fix hang in in io_uring_get_cqe() with iopoll Pavel Begunkov
@ 2020-06-21 15:23 ` Jens Axboe
2020-06-21 15:30 ` Pavel Begunkov
0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2020-06-21 15:23 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 6/21/20 4:30 AM, Pavel Begunkov wrote:
> Because of need_resched() check, io_uring_enter() -> io_iopoll_check()
> can return 0 even if @min_complete wasn't satisfied. If that's the
> case, __io_uring_get_cqe() sets submit=0 and wait_nr=0, disabling
> setting IORING_ENTER_GETEVENTS as well. So, it goes crazy calling
> io_uring_enter() in a loop, not actually submitting nor polling.
>
> Set @wait_nr based on actual number of CQEs ready.
> BTW, atomic_load_acquire() in io_uring_cq_ready() can be replaced
> with a relaxed one for this particular place.
Can you preface this with an addition of __io_uring_cqe_ready() that
doesn't include the load acquire?
Also, s/io_adjut_wait_nr/io_adjust_wait_nr for the patch.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH liburing] Fix hang in in io_uring_get_cqe() with iopoll
2020-06-21 15:23 ` Jens Axboe
@ 2020-06-21 15:30 ` Pavel Begunkov
0 siblings, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2020-06-21 15:30 UTC (permalink / raw)
To: Jens Axboe, io-uring
On 21/06/2020 18:23, Jens Axboe wrote:
> On 6/21/20 4:30 AM, Pavel Begunkov wrote:
>> Because of need_resched() check, io_uring_enter() -> io_iopoll_check()
>> can return 0 even if @min_complete wasn't satisfied. If that's the
>> case, __io_uring_get_cqe() sets submit=0 and wait_nr=0, disabling
>> setting IORING_ENTER_GETEVENTS as well. So, it goes crazy calling
>> io_uring_enter() in a loop, not actually submitting nor polling.
>>
>> Set @wait_nr based on actual number of CQEs ready.
>> BTW, atomic_load_acquire() in io_uring_cq_ready() can be replaced
>> with a relaxed one for this particular place.
>
> Can you preface this with an addition of __io_uring_cqe_ready() that
> doesn't include the load acquire?
Sure
> Also, s/io_adjut_wait_nr/io_adjust_wait_nr for the patch.
Ouch, a typo
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-21 15:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-21 10:30 [PATCH liburing] Fix hang in in io_uring_get_cqe() with iopoll Pavel Begunkov
2020-06-21 15:23 ` Jens Axboe
2020-06-21 15:30 ` Pavel Begunkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox