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.
Unified · Split
| @@ -3049,6 +3049,7 @@ static int io_async_buf_func(struct wait_queue_entry *wait, unsigned mode, · 3048 unmodified lines | |||
| 3049 | if (!wake_page_match(wpq, key)) | 3049 | if (!wake_page_match(wpq, key)) |
| 3050 | return 0; | 3050 | return 0; |
| 3051 | 3051 | ||
| 3052 | req->rw.kiocb.ki_flags &= ~IOCB_WAITQ; | ||
| 3052 | list_del_init(&wait->entry); | 3053 | list_del_init(&wait->entry); |
| 3053 | 3054 | ||
| 3054 | init_task_work(&req->task_work, io_req_task_submit); | 3055 | init_task_work(&req->task_work, io_req_task_submit); |
| @@ -3106,6 +3107,7 @@ static bool io_rw_should_retry(struct io_kiocb *req) · 51 unmodified lines | |||
| 3106 | wait->wait.flags = 0; | 3107 | wait->wait.flags = 0; |
| 3107 | INIT_LIST_HEAD(&wait->wait.entry); | 3108 | INIT_LIST_HEAD(&wait->wait.entry); |
| 3108 | kiocb->ki_flags |= IOCB_WAITQ; | 3109 | kiocb->ki_flags |= IOCB_WAITQ; |
| 3110 | kiocb->ki_flags &= ~IOCB_NOWAIT; | ||
| 3109 | kiocb->ki_waitq = wait; | 3111 | kiocb->ki_waitq = wait; |
| 3110 | 3112 | ||
| 3111 | io_get_req_task(req); | 3113 | io_get_req_task(req); |
| @@ -2267,7 +2267,11 @@ readpage: · 2266 unmodified lines | |||
| 2267 | } | 2267 | } |
| 2268 | 2268 | ||
| 2269 | if (!PageUptodate(page)) { | 2269 | 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 | |||
| 2271 | if (unlikely(error)) | 2275 | if (unlikely(error)) |
| 2272 | goto readpage_error; | 2276 | goto readpage_error; |
| 2273 | if (!PageUptodate(page)) { | 2277 | if (!PageUptodate(page)) { |