Skip to content

Commit

Permalink
io_uring: fix async buffered reads when readahead is disabled
Browse files Browse the repository at this point in the history
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 <haoxu@linux.alibaba.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Hao Xu authored and Jens Axboe committed Sep 29, 2020
1 parent fad8e0d commit c8d317a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -3049,6 +3049,7 @@ static int io_async_buf_func(struct wait_queue_entry *wait, unsigned mode,
if (!wake_page_match(wpq, key))
return 0;

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

init_task_work(&req->task_work, io_req_task_submit);
Expand Down Expand Up @@ -3106,6 +3107,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);
Expand Down
6 changes: 5 additions & 1 deletion mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit c8d317a

Please sign in to comment.