Skip to content

Commit c8d317a

Browse files
Hao Xuaxboe
authored andcommitted
io_uring: fix 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: 1a0a785 ("mm: support async buffered reads in generic_file_buffered_read()") Fixes: 3b2a443 ("io_uring: get rid of kiocb_wait_page_queue_init()") Signed-off-by: Hao Xu <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent fad8e0d commit c8d317a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

fs/io_uring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,7 @@ static int io_async_buf_func(struct wait_queue_entry *wait, unsigned mode,
30493049
if (!wake_page_match(wpq, key))
30503050
return 0;
30513051

3052+
req->rw.kiocb.ki_flags &= ~IOCB_WAITQ;
30523053
list_del_init(&wait->entry);
30533054

30543055
init_task_work(&req->task_work, io_req_task_submit);
@@ -3106,6 +3107,7 @@ static bool io_rw_should_retry(struct io_kiocb *req)
31063107
wait->wait.flags = 0;
31073108
INIT_LIST_HEAD(&wait->wait.entry);
31083109
kiocb->ki_flags |= IOCB_WAITQ;
3110+
kiocb->ki_flags &= ~IOCB_NOWAIT;
31093111
kiocb->ki_waitq = wait;
31103112

31113113
io_get_req_task(req);

mm/filemap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,11 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb,
22672267
}
22682268

22692269
if (!PageUptodate(page)) {
2270-
error = lock_page_killable(page);
2270+
if (iocb->ki_flags & IOCB_WAITQ)
2271+
error = lock_page_async(page, iocb->ki_waitq);
2272+
else
2273+
error = lock_page_killable(page);
2274+
22712275
if (unlikely(error))
22722276
goto readpage_error;
22732277
if (!PageUptodate(page)) {

0 commit comments

Comments
 (0)