Re: [PATCH v2 0/2] Optimise io_uring completion waiting
From: Jens Axboe
Date: Tue Sep 24 2019 - 08:57:07 EST
On 9/24/19 5:43 AM, Peter Zijlstra wrote:
> On Tue, Sep 24, 2019 at 02:11:29PM +0300, Pavel Begunkov wrote:
>
>> @@ -2717,15 +2757,18 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
>> return ret;
>> }
>>
>> + iowq.nr_timeouts = atomic_read(&ctx->cq_timeouts);
>> + prepare_to_wait_exclusive(&ctx->wait, &iowq.wq, TASK_INTERRUPTIBLE);
>> + do {
>> + if (io_should_wake(&iowq))
>> + break;
>> + schedule();
>> + if (signal_pending(current))
>> + break;
>> + set_current_state(TASK_INTERRUPTIBLE);
>> + } while (1);
>> + finish_wait(&ctx->wait, &iowq.wq);
>
> It it likely OK, but for paranoia, I'd prefer this form:
>
> for (;;) {
> prepare_to_wait_exclusive(&ctx->wait, &iowq.wq, TASK_INTERRUPTIBLE);
> if (io_should_wake(&iowq))
> break;
> schedule();
> if (signal_pending(current))
> break;
> }
> finish_wait(&ctx->wait, &iowq.wq);
>
> The thing is, if we ever succeed with io_wake_function() (that CPU
> observes io_should_wake()), but when waking here, we do not observe
> is_wake_function() and go sleep again, we might never wake up if we
> don't put ourselves back on the wait-list again.
Might be paranoia indeed, but especially after this change, we don't
expect to make frequent roundtrips there. So better safe than sorry,
I'll make the change.
--
Jens Axboe