From 10b8c31e8085a85d5a71c7e271387c2edbcf7b96 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 12 Oct 2020 16:44:23 -0600 Subject: [PATCH 1/2] readahead: use limited read-ahead to satisfy read Willy reports that there's a case where async buffered reads will be blocking, and that's due to not using read-ahead to generate the reads when read-ahead is disabled. io_uring relies on read-ahead triggering the reads, if not, it needs to fallback to threaded helpers. For the case where read-ahead is disabled on the file, or if the cgroup is congested, ensure that we can at least do 1 page of read-ahead to make progress on the read in an async fashion. This could potentially be larger, but it's not needed in terms of functionality, so let's error on the side of caution as larger counts of pages may run into reclaim issues (particularly if we're congested). Reported-by: Matthew Wilcox (Oracle) Acked-by: Johannes Weiner Signed-off-by: Jens Axboe --- mm/readahead.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 3c9a8dd7c56c..e5975f4e0ee5 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -568,15 +568,21 @@ void page_cache_sync_readahead(struct address_space *mapping, struct file_ra_state *ra, struct file *filp, pgoff_t index, unsigned long req_count) { - /* no read-ahead */ - if (!ra->ra_pages) - return; + bool do_forced_ra = filp && (filp->f_mode & FMODE_RANDOM); - if (blk_cgroup_congested()) - return; + /* + * Even if read-ahead is disabled, start this request as read-ahead. + * This makes regular read-ahead disabled use the same path as normal + * reads, instead of having to punt to ->readpage() manually. We limit + * ourselves to 1 page for this case, to avoid causing problems if + * we're congested or tight on memory. + */ + if (!ra->ra_pages || blk_cgroup_congested()) { + req_count = 1; + do_forced_ra = true; + } - /* be dumb */ - if (filp && (filp->f_mode & FMODE_RANDOM)) { + if (do_forced_ra) { force_page_cache_readahead(mapping, filp, index, req_count); return; } -- 2.28.0