io_uring: support async buffered reads when readahead is disabled
Subsystems (4)
PATCH 1/1 io_uring: support async buffered reads when readahead is disabled
The async buffered reads feature is not working when readahead is turned off. There are two things to concern:
- when doing retry in io_read, not only the IOCB_WAITQ flag but also the IOCB_NOWAIT flag is still set, which makes it goes to would_block phase in generic_file_buffered_read() and then return -EAGAIN. After that, the io-wq thread work is queued, and later doing the async reads in the old way.
- even if we remove IOCB_NOWAIT when doing retry, the feature is still not running properly, since in generic_file_buffered_read() it goes to lock_page_killable() after calling mapping->a_ops->readpage() to do IO, and thus causing process to sleep.
--- fs/io_uring.c | 1 + mm/filemap.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
fs/io_uring.c +1 -0
@@ -3106,6 +3106,7 @@ static bool io_rw_should_retry(struct io_kiocb *req) wait->wait.flags =0 ;INIT_LIST_HEAD (&wait->wait.entry); kiocb->ki_flags |=IOCB_WAITQ ; + kiocb->ki_flags &= ~IOCB_NOWAIT ; kiocb->ki_waitq = wait;io_get_req_task (req);
mm/filemap.c +5 -1
@@ -2267,7 +2267,11 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, }if (!PageUptodate (page)) { - error =lock_page_killable (page); +if (iocb->ki_flags &IOCB_WAITQ ) + error =lock_page_async (page, iocb->ki_waitq); +else + error =lock_page_killable (page); +if (unlikely (error)) goto readpage_error;if (!PageUptodate (page)) {
Signature · 1 line
1.8.3.1
Jens Axboe
maintainerQuoted 9 lines · Hao Xu
The async buffered reads feature is not working when readahead is turned off. There are two things to concern:
- when doing retry in
io_read, not only theIOCB_WAITQflag but also theIOCB_NOWAITflag is still set, which makes it goes towould_blockphase ingeneric_file_buffered_read()and then return-EAGAIN. After that, the io-wq thread work is queued, and later doing the async reads in the old way.
Quoted 4 lines
- even if we remove
IOCB_NOWAITwhen doing retry, the feature is still not running properly, since ingeneric_file_buffered_read()it goes tolock_page_killable()after callingmapping->a_ops->readpage()to do IO, and thus causing process to sleep.
Thanks, this looks great, and avoids cases of io-wq punt where we don't need it. I'm going to run this through full testing, but I think this looks good to me.
Signature · 1 line
Jens Axboe