Re: [PATCH] mm/readahead: look two windows ahead for the hole on a marker hit

From: Qiliang Yuan

Date: Tue Nov 17 2026 - 00:42:20 EST


On Sun, Nov 15, 2026 at 08:33:28PM -0800, Andrew Morton wrote:
> And you have QEMU in the way, so reads can get served from host
> pagecache (depends on QEMU setup), which also matters.
>
> So I just don't know what to conclude from your numbers. I *suspect*
> the gains are from reduced CPU & memory-access times which is of course
> good. But was there any actual physical device access involved?

No, the host page cache was warm in those runs too.

I have now repeated them with the file on a raw disk attached with
cache=none, which sits on a hardware RAID of spinning disks in the
host, so every read in the guest goes to the disks. dd with O_DIRECT
reads the 16 GiB file at 440-490 MB/s. Same 8 MiB memcpy() pieces,
read_ahead_kb 8192, guest cache dropped before each run, v7.4-rc3
(666539eecdf4) with and without the patch, three alternating boots,
median, with the amount read from the disk:

time (s) read (MB)
workload before after change before after
1 thread from offset 2 GiB 60.69 28.68 -53% 14340 14340
8 threads, one range each 36.80 31.22 -15% 16384 16384
32 threads, one range each 34.67 30.38 -12% 16384 16384
8 threads, 7 MiB interleaved 27.54 27.20 -1% 16384 16384
8 threads, pread() 32.06 32.27 +1% 16384 16384

The single reader goes from half the disk's bandwidth to all of it, and
its major faults drop from 1793 to 2. With 8 and 32 threads the disk is
already the limit, so the gain shrinks to 12-15%. None of these reads
more than the copy needs.

> I tested the patch on my LLM-driven test setup, which is similar to
> yours. The results are... ambivalent. The things which you want
> faster are indeed faster, but other things slowed down (wall of words
> appended).

I reproduced both costs on the same disk in the same runs: fault in the
middle of a window at 64 places in the file, so read-around marks a
folio 6 MiB in, cache the next 8 MiB (or 16 MiB) with
POSIX_FADV_WILLNEED, then touch each marker once (median of the
per-run median access times):

beyond the window before (us) after (us) read before read after
8 MiB cached, then gap 16.1 43.1 0 MB 512 MB
16 MiB cached 9.3 17.5 0 MB 0 MB

The first row is a real cost of the patch: mainline reads nothing
there, the patch reads one more window (read_ahead_kb) per marker hit.
It is wasted only if the reader stops before that window. A reader that
goes on, like the copies above, would otherwise fault on the hole and
read it synchronously. The second row is the longer lookup when nothing
is read, about 8 us per such marker hit.

v2 is the same change rebased onto v7.4-rc2:
https://lore.kernel.org/r/20261109-bug-mm-readahead-async-overtaken-v2-1-06ead50562a2@xxxxxxxxx

Thanks,
Qiliang