Skip to contentSkip to conversation

io_uring: support async buffered reads when readahead is disabled

PATCH In review Hao Xu 2 participants 2 messages Sep 29, 2020

Subsystems (4)
lore
Share & tools
lore

Hao Xu

author
#0 lore raw

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.

Fixes 1a0a7853b901 ("mm: support async buffered reads in generic_file_buffered_read()")
Fixes 3b2a4439e0ae ("io_uring: get rid of kiocb_wait_page_queue_init()")
---
 fs/io_uring.c | 1 +
 mm/filemap.c  | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
fs/io_uring.c +1 -0
index 556e4a2ead07..e7e8ea58274e 100644
@@ -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
index 1aaea26556cc..ea383478fc22 100644
@@ -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
maintainer
#1 lore raw
Quoted 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 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.

Quoted 4 lines

- 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.

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