]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
readahead: fix return value of page_cache_next_miss() when no hole is found
authorChi Zhiling <chizhiling@kylinos.cn>
Thu, 5 Jun 2025 05:49:35 +0000 (13:49 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 05:41:59 +0000 (22:41 -0700)
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 <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>
mm/filemap.c

index bada249b9fb7622d625b0e606fd9c69ecfff24c2..a6459874bb2aaa221086a927b76f631f4d574fca 100644 (file)
@@ -1778,8 +1778,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;