Re: [PATCH] mm/filemap: restart mmap readahead on sequential faults after many misses
From: Jan Kara
Date: Tue Nov 10 2026 - 11:34:40 EST
On Mon 09-11-26 09:14:44, Gopal Malaviya wrote:
> Since commit 9b0fcac3cfe7 ("mm/filemap: do not count FAULT_FLAG_TRIED
> retries as mmap hits"), about a hundred sparse mmap faults push
> mmap_miss over MMAP_LOTSAMISS and turn off mmap read-around, as
> intended. But mmap_miss only comes down on hits on pages that
> read-around brought in, and with read-around off there are none. A file
> that is then read sequentially gets a synchronous single-page read for
> every page until it is opened again.
>
> When a miss above the limit is on the page right after the previous
> miss, start readahead the way a sequential read() miss does, with
> page_cache_sync_ra(), and keep mmap_miss at its cap so that hits on
> that small first window do not bring back full read-around for random
> access.
>
> Tested in a KVM guest (x86_64, 2 vCPUs, 3 GiB) with ext4 on virtio-blk.
> "base" is mm-hotfixes-unstable. "95b8e" is commit 95b8e432265f ("mm: use
> zone lock guard in __offline_isolated_pages()"), the last one before the
> series of 9b0fcac3cfe7. Commit 0b9c0aeba938 ("mm/filemap: count only the
> faulting address as a mmap hit"), the first of that series, gives the
> same results as 95b8e for the reproducer.
>
> Reproducer from the report, read_ahead_kb 128, major faults:
>
> 95b8e base patched
> sequential only 1 1 1
> sparse pass, then sequential 1 16384 2
> sparse, MADV_SEQUENTIAL, sequential 512 512 512
> sparse, close and reopen, sequential 1 1 1
>
> Touching 1% of the pages of a cold 20 GiB file, larger than memory,
> MiB read from disk:
>
> read_ahead_kb 128 read_ahead_kb 8192
> 95b8e base patched 95b8e base patched
> random 5656 215 215 344731 1032 1032
> stride 2053 pages 6545 216 216 419003 992 992
> random 2-page runs 2992 215 528 173093 1099 2248
> random 4-page runs 1570 216 594 86797 1266 2301
>
> After the sparse pass, reading 32 regions of 2 MiB in turn takes 512
> major faults per region on base and 2 with this patch.
>
> Not tested: NFS, the GPU workload from the report, and other
> architectures and page sizes.
>
> An AI assistant (Claude) helped with the analysis and the approach, and
> wrote the test programs and drafts of the comment and this changelog.
> I reviewed, implemented, built and tested the change.
>
> Fixes: 9b0fcac3cfe7 ("mm/filemap: do not count FAULT_FLAG_TRIED retries as mmap hits")
> Reported-by: Trace <tracekotae@xxxxxxxxx>
> Closes: https://lore.kernel.org/all/20261105192517.228523-1-tracekotae@xxxxxxxxx/
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Gopal Malaviya <gopalmalaviya53@xxxxxxxxx>
I think this [1] looks like a nicer solution to your problem.
[1] https://lore.kernel.org/all/20261109-mmap-miss-v1-1-8b44b33f3358@xxxxxxxx/
Honza
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR