Skip to content

Commit 7c87758

Browse files
jankaraakpm00
authored andcommitted
readahead: properly shorten readahead when falling back to do_page_cache_ra()
When we succeed in creating some folios in page_cache_ra_order() but then need to fallback to single page folios, we don't shorten the amount to read passed to do_page_cache_ra() by the amount we've already read. This then results in reading more and also in placing another readahead mark in the middle of the readahead window which confuses readahead code. Fix the problem by properly reducing number of pages to read. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Tested-by: Zhang Peng <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 901a269 commit 7c87758

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mm/readahead.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ void page_cache_ra_order(struct readahead_control *ractl,
491491
struct file_ra_state *ra, unsigned int new_order)
492492
{
493493
struct address_space *mapping = ractl->mapping;
494-
pgoff_t index = readahead_index(ractl);
494+
pgoff_t start = readahead_index(ractl);
495+
pgoff_t index = start;
495496
pgoff_t limit = (i_size_read(mapping->host) - 1) >> PAGE_SHIFT;
496497
pgoff_t mark = index + ra->size - ra->async_size;
497498
unsigned int nofs;
@@ -544,7 +545,7 @@ void page_cache_ra_order(struct readahead_control *ractl,
544545
if (!err)
545546
return;
546547
fallback:
547-
do_page_cache_ra(ractl, ra->size, ra->async_size);
548+
do_page_cache_ra(ractl, ra->size - (index - start), ra->async_size);
548549
}
549550

550551
/*

0 commit comments

Comments
 (0)