Skip to content

Commit bbcaee2

Browse files
Chi Zhilingakpm00
authored andcommitted
readahead: fix return value of page_cache_next_miss() when no hole is found
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: 901a269 ("filemap: fix page_cache_next_miss() when no hole found") Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn> Reviewed-by: Jan Kara <jack@suse.cz> Cc: Josef Bacik <josef@toxicpanda.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 08e21e2 commit bbcaee2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/filemap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,9 @@ pgoff_t page_cache_next_miss(struct address_space *mapping,
17781778
pgoff_t index, unsigned long max_scan)
17791779
{
17801780
XA_STATE(xas, &mapping->i_pages, index);
1781+
unsigned long nr = max_scan;
17811782

1782-
while (max_scan--) {
1783+
while (nr--) {
17831784
void *entry = xas_next(&xas);
17841785
if (!entry || xa_is_value(entry))
17851786
return xas.xa_index;

0 commit comments

Comments
 (0)