* [PATCH] mm/readahead: keep at least half of the async window when aligning it
@ 2026-10-30 3:52 Daejun Park via B4 Relay
2026-11-02 19:15 ` Andrew Morton
2026-11-02 21:46 ` Jan Kara
0 siblings, 2 replies; 3+ messages in thread
From: Daejun Park via B4 Relay @ 2026-10-30 3:52 UTC (permalink / raw)
To: Andrew Morton, Matthew Wilcox (Oracle), Jan Kara
Cc: Ryan Roberts, linux-fsdevel, linux-mm, linux-kernel, Daejun Park
From: Daejun Park <daejun7.park@samsung.com>
page_cache_async_ra() trims the end of each new window to a multiple of
1 << ra->order pages. A window that starts just below such a boundary
keeps only a few pages. With read_ahead_kb=128 and max_sectors_kb=512,
1 MiB reads after a 4 KiB read at offset 0 hit this on about one window
in three. They issue three times as many device reads.
Halve the alignment until the trim keeps at least half of the window.
Fixes: 18ebe55a9236 ("mm/readahead: terminate async readahead on natural boundary")
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
Tested on mm-new in a QEMU guest with XFS on an emulated NVMe,
read_ahead_kb 128 and a cold cache.
- max_sectors_kb 512, median of 5 runs: reading a 512 MiB file this
way takes 0.247 s before and 0.180 s after. The device sees 3329 and
1032 reads.
- Other reads with max_sectors_kb 512: without the 4 KiB read, and with
64 KiB reads, the times do not change. Random 4 KiB and 64 KiB reads,
two interleaved streams on one file, and 2 MiB reads at random
offsets also take the same time. They read the same amount from the
device, within 0.3%.
With the device's transfer limit at 2 MiB:
- max_sectors_kb 256: 512 KiB reads after the 4 KiB read take 0.626 s
before and 0.322 s after. The device sees 6147 and 2056 reads.
- max_sectors_kb 1024 or 2048: 1 MiB reads are not trimmed.
- max_sectors_kb 2048, 3 MiB reads: the device sees 343 instead of 271
reads. The time is 0.120 s instead of 0.118 s, the median of 40 runs.
The interquartile range is about 0.10 to 0.13 s for both. The window
stays at 3/4 of the maximum, off the 2 MiB boundary. mm-new reaches
that boundary by trimming deeply.
---
mm/readahead.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/mm/readahead.c b/mm/readahead.c
index 6e55632902..f4da9b4606 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -713,6 +713,17 @@ void page_cache_async_ra(struct readahead_control *ractl,
align = 1UL << min(ra->order, ffs(max_pages) - 1);
end = ra->start + ra->size;
aligned_end = round_down(end, align);
+ /*
+ * Keep at least half of the window when aligning its end. A
+ * window that starts just below a large boundary would otherwise
+ * shrink to a few pages and cap the folio order. Use a smaller
+ * alignment instead.
+ */
+ while (aligned_end > ra->start &&
+ 2 * (aligned_end - ra->start) < ra->size) {
+ align >>= 1;
+ aligned_end = round_down(end, align);
+ }
if (aligned_end > ra->start)
ra->size -= end - aligned_end;
ra->async_size = ra->size;
---
base-commit: 9c449f885765cf8d80b2c60b1971e774bba51a3f
change-id: 20261029-mm-readahead-async-align-e491b3dc16a6
Best regards,
--
Daejun Park <daejun7.park@samsung.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/readahead: keep at least half of the async window when aligning it
2026-10-30 3:52 [PATCH] mm/readahead: keep at least half of the async window when aligning it Daejun Park via B4 Relay
@ 2026-11-02 19:15 ` Andrew Morton
2026-11-02 21:46 ` Jan Kara
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-11-02 19:15 UTC (permalink / raw)
To: daejun7.park
Cc: Daejun Park via B4 Relay, Matthew Wilcox (Oracle),
Jan Kara, Ryan Roberts, linux-fsdevel, linux-mm, linux-kernel
On Fri, 30 Oct 2026 12:52:57 +0900 Daejun Park via B4 Relay <devnull+daejun7.park.samsung.com@kernel.org> wrote:
> From: Daejun Park <daejun7.park@samsung.com>
>
> page_cache_async_ra() trims the end of each new window to a multiple of
> 1 << ra->order pages. A window that starts just below such a boundary
> keeps only a few pages. With read_ahead_kb=128 and max_sectors_kb=512,
> 1 MiB reads after a 4 KiB read at offset 0 hit this on about one window
> in three. They issue three times as many device reads.
>
> Halve the alignment until the trim keeps at least half of the window.
>
Thanks, but...
> ---
> Tested on mm-new in a QEMU guest with XFS on an emulated NVMe,
> read_ahead_kb 128 and a cold cache.
>
> - max_sectors_kb 512, median of 5 runs: reading a 512 MiB file this
> way takes 0.247 s before and 0.180 s after. The device sees 3329 and
> 1032 reads.
>
> - Other reads with max_sectors_kb 512: without the 4 KiB read, and with
> 64 KiB reads, the times do not change. Random 4 KiB and 64 KiB reads,
> two interleaved streams on one file, and 2 MiB reads at random
> offsets also take the same time. They read the same amount from the
> device, within 0.3%.
>
> With the device's transfer limit at 2 MiB:
>
> - max_sectors_kb 256: 512 KiB reads after the 4 KiB read take 0.626 s
> before and 0.322 s after. The device sees 6147 and 2056 reads.
>
> - max_sectors_kb 1024 or 2048: 1 MiB reads are not trimmed.
>
> - max_sectors_kb 2048, 3 MiB reads: the device sees 343 instead of 271
> reads. The time is 0.120 s instead of 0.118 s, the median of 40 runs.
> The interquartile range is about 0.10 to 0.13 s for both. The window
> stays at 3/4 of the maximum, off the 2 MiB boundary. mm-new reaches
> that boundary by trimming deeply.
The whole objective of the patch is "speed things up". So a description
of how much the patch sped things up is essential changelog material!
IOW, please summarize it heavily and include the performance testing
results in the actual changelog. Low-level testing details can be
retained below the ---.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/readahead: keep at least half of the async window when aligning it
2026-10-30 3:52 [PATCH] mm/readahead: keep at least half of the async window when aligning it Daejun Park via B4 Relay
2026-11-02 19:15 ` Andrew Morton
@ 2026-11-02 21:46 ` Jan Kara
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2026-11-02 21:46 UTC (permalink / raw)
To: daejun7.park
Cc: Andrew Morton, Matthew Wilcox (Oracle),
Jan Kara, Ryan Roberts, linux-fsdevel, linux-mm, linux-kernel
On Fri 30-10-26 12:52:57, Daejun Park via B4 Relay wrote:
> From: Daejun Park <daejun7.park@samsung.com>
>
> page_cache_async_ra() trims the end of each new window to a multiple of
> 1 << ra->order pages. A window that starts just below such a boundary
> keeps only a few pages. With read_ahead_kb=128 and max_sectors_kb=512,
> 1 MiB reads after a 4 KiB read at offset 0 hit this on about one window
> in three. They issue three times as many device reads.
>
> Halve the alignment until the trim keeps at least half of the window.
>
> Fixes: 18ebe55a9236 ("mm/readahead: terminate async readahead on natural boundary")
> Signed-off-by: Daejun Park <daejun7.park@samsung.com>
> ---
> Tested on mm-new in a QEMU guest with XFS on an emulated NVMe,
> read_ahead_kb 128 and a cold cache.
>
> - max_sectors_kb 512, median of 5 runs: reading a 512 MiB file this
> way takes 0.247 s before and 0.180 s after. The device sees 3329 and
> 1032 reads.
>
> - Other reads with max_sectors_kb 512: without the 4 KiB read, and with
> 64 KiB reads, the times do not change. Random 4 KiB and 64 KiB reads,
> two interleaved streams on one file, and 2 MiB reads at random
> offsets also take the same time. They read the same amount from the
> device, within 0.3%.
>
> With the device's transfer limit at 2 MiB:
>
> - max_sectors_kb 256: 512 KiB reads after the 4 KiB read take 0.626 s
> before and 0.322 s after. The device sees 6147 and 2056 reads.
>
> - max_sectors_kb 1024 or 2048: 1 MiB reads are not trimmed.
>
> - max_sectors_kb 2048, 3 MiB reads: the device sees 343 instead of 271
> reads. The time is 0.120 s instead of 0.118 s, the median of 40 runs.
> The interquartile range is about 0.10 to 0.13 s for both. The window
> stays at 3/4 of the maximum, off the 2 MiB boundary. mm-new reaches
> that boundary by trimming deeply.
OK, I can see how it easily happens once that we trim the readahead
significantly due to alignment. I'm not fully clear how it happens
periodically. Is it that you do 1 MiB misaligned reads and so we
periodically end up triggering async readahead from positions that are not
aligned to the current value of ra->order?
Anyway, what we want is to align the readahead so that we avoid creating
folios of unnecessarily small order at the end of the readahead window (and
I actually miss evaluation how order of folios changed after your change
because that's also an important metric for this logic). I think the
problem might be that the attempt to align in page_cache_async_ra() is
actually not reflecting what page_cache_ra_order() will end up doing
(it may reduce ra->order based on readahead size, starting index, etc.) so
the alignment we do in page_cache_async_ra() may be unnecessarily large.
Instead of trying to second-guess the logic of page_cache_ra_order() in
page_cache_async_ra() I think we could pass a flag to it in ractl telling
it it's allowed to shrink the window instead of allocating small folios
and then handle the alignment in page_cache_ra_order(). Hum?
Honza
> ---
> mm/readahead.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/mm/readahead.c b/mm/readahead.c
> index 6e55632902..f4da9b4606 100644
> --- a/mm/readahead.c
> +++ b/mm/readahead.c
> @@ -713,6 +713,17 @@ void page_cache_async_ra(struct readahead_control *ractl,
> align = 1UL << min(ra->order, ffs(max_pages) - 1);
> end = ra->start + ra->size;
> aligned_end = round_down(end, align);
> + /*
> + * Keep at least half of the window when aligning its end. A
> + * window that starts just below a large boundary would otherwise
> + * shrink to a few pages and cap the folio order. Use a smaller
> + * alignment instead.
> + */
> + while (aligned_end > ra->start &&
> + 2 * (aligned_end - ra->start) < ra->size) {
> + align >>= 1;
> + aligned_end = round_down(end, align);
> + }
> if (aligned_end > ra->start)
> ra->size -= end - aligned_end;
> ra->async_size = ra->size;
>
> ---
> base-commit: 9c449f885765cf8d80b2c60b1971e774bba51a3f
> change-id: 20261029-mm-readahead-async-align-e491b3dc16a6
>
> Best regards,
> --
> Daejun Park <daejun7.park@samsung.com>
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-02 21:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-30 3:52 [PATCH] mm/readahead: keep at least half of the async window when aligning it Daejun Park via B4 Relay
2026-11-02 19:15 ` Andrew Morton
2026-11-02 21:46 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®