Linux io-uring development
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Dave Chinner <david@fromorbit.com>
Cc: io-uring@vger.kernel.org, Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org,
	"Darrick J . Wong" <djwong@kernel.org>,
	linux-xfs@vger.kernel.org, wu lei <uwydoc@gmail.com>
Subject: Re: [PATCH 1/1] iomap: propagate nowait to block layer
Date: Wed, 26 Feb 2025 12:33:21 +0000	[thread overview]
Message-ID: <7b440d54-b519-4995-9f5f-f3e636c6d477@gmail.com> (raw)
In-Reply-To: <Z76eEu4vxwFIWKj7@dread.disaster.area>

On 2/26/25 04:52, Dave Chinner wrote:
> On Wed, Feb 26, 2025 at 01:33:58AM +0000, Pavel Begunkov wrote:
>> There are reports of high io_uring submission latency for ext4 and xfs,
>> which is due to iomap not propagating nowait flag to the block layer
>> resulting in waiting for IO during tag allocation.
>>
>> Cc: stable@vger.kernel.org
>> Link: https://github.com/axboe/liburing/issues/826#issuecomment-2674131870
>> Reported-by: wu lei <uwydoc@gmail.com>
>> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
>> ---
>>   fs/iomap/direct-io.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
>> index b521eb15759e..25c5e87dbd94 100644
>> --- a/fs/iomap/direct-io.c
>> +++ b/fs/iomap/direct-io.c
>> @@ -81,6 +81,9 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter,
>>   		WRITE_ONCE(iocb->private, bio);
>>   	}
>>   
>> +	if (iocb->ki_flags & IOCB_NOWAIT)
>> +		bio->bi_opf |= REQ_NOWAIT;
> 
> ISTR that this was omitted on purpose because REQ_NOWAIT doesn't
> work in the way iomap filesystems expect IO to behave.
> 
> I think it has to do with large direct IOs that require multiple
> calls to submit_bio(). Each bio that is allocated and submitted
> takes a reference to the iomap_dio object, and the iomap_dio is not
> completed until that reference count goes to zero.
> 
> hence if we have submitted a series of bios in a IOCB_NOWAIT DIO
> and then the next bio submission in the DIO triggers a REQ_NOWAIT
> condition, that bio is marked with a BLK_STS_AGAIN and completed.
> This error is then caught by the iomap dio bio completion function,
> recorded in the iomap_dio structure, but because there is still
> bios in flight, the iomap_dio ref count does not fall to zero and so
> the DIO itself is not completed.
> 
> Then submission loops again, sees dio->error is set and aborts
> submission. Because this is AIO, and the iomap_dio refcount is
> non-zero at this point, __iomap_dio_rw() returns -EIOCBQUEUED.
> It does not return the -EAGAIN state that was reported to bio
> completion because the overall DIO has not yet been completed
> and all the IO completion status gathered.
> 
> Hence when the in flight async bios actually complete, they drop the
> iomap dio reference count to zero, iomap_dio_complete() is called,
> and the BLK_STS_AGAIN error is gathered from the previous submission
> failure. This then calls AIO completion, and reports a -EAGAIN error
> to the AIO/io_uring completion code.
> 
> IOWs, -EAGAIN is *not reported to the IO submitter* that needs
> this information to defer and resubmit the IO - it is reported to IO
> completion where it is completely useless and, most likely, not in a
> context that can resubmit the IO.
> 
> Put simply: any code that submits multiple bios (either individually
> or as a bio chain) for a single high level IO can not use REQ_NOWAIT
> reliably for async IO submission.

I know the issue, but admittedly forgot about it here, thanks for
reminding! Considering that attempts to change the situation failed
some years ago and I haven't heard about it after, I don't think
it'll going to change any time soon.

So how about to follow what the block layer does and disable multi
bio nowait submissions for async IO?

if (!iocb_is_sync(iocb)) {
	if (multi_bio)
		return -EAGAIN;
	bio_opf |= REQ_NOWAIT;
}

Is there anything else but io_uring and AIO that can issue async
IO though this path?

> We have similar limitations on IO polling (IOCB_HIPRI) in iomap, but
> I'm not sure if REQ_NOWAIT can be handled the same way. i.e. only
> setting REQ_NOWAIT on the first bio means that the second+ bio can
> still block and cause latency issues.
> 
> So, yeah, fixing this source of latency is not as simple as just
> setting REQ_NOWAIT. I don't know if there is a better solution that
> what we currently have, but causing large AIO DIOs to
> randomly fail with EAGAIN reported at IO completion (with the likely
> result of unexpected data corruption) is far worse behaviour that
> occasionally having to deal with a long IO submission latency.

By the end of the day, it's waiting for IO, the first and very thing
the user don't want to see for async IO, and that's pretty much what
makes AIO borderline unusable. We just can't have it for an asynchronous
interface. If we can't fix it up here, the only other option I see
is to push all such io_uring requests to a slow path where we can
block, and that'd be quite a large regression.

-- 
Pavel Begunkov


  reply	other threads:[~2025-02-26 12:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26  1:33 [PATCH 1/1] iomap: propagate nowait to block layer Pavel Begunkov
2025-02-26  1:53 ` Darrick J. Wong
2025-02-26  2:06   ` Pavel Begunkov
2025-02-26  2:20     ` Darrick J. Wong
2025-02-26  2:46       ` Pavel Begunkov
2025-02-26  4:52 ` Dave Chinner
2025-02-26 12:33   ` Pavel Begunkov [this message]
2025-02-26 20:49     ` Dave Chinner
2025-02-27 11:58       ` 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=7b440d54-b519-4995-9f5f-f3e636c6d477@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=brauner@kernel.org \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=uwydoc@gmail.com \
    /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