mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ 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] 4+ messages in thread

end of thread, other threads:[~2026-11-03  4:18 UTC | newest]

Thread overview: 4+ 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
     [not found] ` <CGME20261102214705epcas2p4e71e245666406025381037104803dedb@epcms2p1>
2026-11-03  4:18   ` Daejun Park

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®