]> git.ipfire.org Git - thirdparty/linux.git/commit
mm/readahead: no PG_readahead on EOF
authorFrederick Mayle <fmayle@google.com>
Fri, 8 May 2026 18:12:31 +0000 (11:12 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 2 Jun 2026 22:22:16 +0000 (15:22 -0700)
commitde97ae6222c1326db5475467879887d0dd2c62a6
tree610b146e38d5b22954d61c20d49a299abf1b74d8
parent80eacd489a50ab2a560bc233b26b94ad9df68410
mm/readahead: no PG_readahead on EOF

When readahead pulls in all the remaining pages for a file, setting the
readahead bit is counter productive.  The async readahead it would trigger
would almost certainly be a no-op.  Additionally, for mmap'd file IO, the
readahead bit limits the fault around [1], causing an extra minor fault
when the page is accessed.

This was discovered when looking at /sys/kernel/tracing/events/readahead
traces for a simple program.  With the patch applied, fewer
page_cache_ra_unbounded calls are observed.

[1] do_fault_around calls filemap_map_pages, which finds eligible pages
    by calling next_uptodate_folio [2]. next_uptodate_folio skips pages
    with PG_readahead set [3].

Link: https://github.com/torvalds/linux/blob/v7.0/mm/filemap.c#L3921-L3939
Link: https://github.com/torvalds/linux/blob/v7.0/mm/filemap.c#L3721-L3722
Link: https://lore.kernel.org/20260508181237.670645-1-fmayle@google.com
Signed-off-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/readahead.c