From: Chi Zhiling Date: Thu, 5 Jun 2025 05:49:35 +0000 (+0800) Subject: readahead: fix return value of page_cache_next_miss() when no hole is found X-Git-Tag: v6.12.44~250 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=72e849b5b16a48ac6dc6c09997ce38b90b0f7d86;p=thirdparty%2Fkernel%2Fstable.git readahead: fix return value of page_cache_next_miss() when no hole is found commit bbcaee20e03ecaeeecba32a703816a0d4502b6c4 upstream. max_scan in page_cache_next_miss always decreases to zero when no hole is found, causing the return value to be index + 0. Fix this by preserving the max_scan value throughout the loop. Jan said "From what I know and have seen in the past, wrong responses from page_cache_next_miss() can lead to readahead window reduction and thus reduced read speeds." Link: https://lkml.kernel.org/r/20250605054935.2323451-1-chizhiling@163.com Fixes: 901a269ff3d5 ("filemap: fix page_cache_next_miss() when no hole found") Signed-off-by: Chi Zhiling Reviewed-by: Jan Kara Cc: Josef Bacik Cc: Matthew Wilcox (Oracle) Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- diff --git a/mm/filemap.c b/mm/filemap.c index fa18e71f9c889..ec69fadf014cd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1750,8 +1750,9 @@ pgoff_t page_cache_next_miss(struct address_space *mapping, pgoff_t index, unsigned long max_scan) { XA_STATE(xas, &mapping->i_pages, index); + unsigned long nr = max_scan; - while (max_scan--) { + while (nr--) { void *entry = xas_next(&xas); if (!entry || xa_is_value(entry)) return xas.xa_index;