Skip to content

Commit 10ea839

Browse files
laoarjfvogel
authored andcommitted
mm/readahead: fix large folio support in async readahead
commit 158cdce upstream. When testing large folio support with XFS on our servers, we observed that only a few large folios are mapped when reading large files via mmap. After a thorough analysis, I identified it was caused by the `/sys/block/*/queue/read_ahead_kb` setting. On our test servers, this parameter is set to 128KB. After I tune it to 2MB, the large folio can work as expected. However, I believe the large folio behavior should not be dependent on the value of read_ahead_kb. It would be more robust if the kernel can automatically adopt to it. With /sys/block/*/queue/read_ahead_kb set to 128KB and performing a sequential read on a 1GB file using MADV_HUGEPAGE, the differences in /proc/meminfo are as follows: - before this patch FileHugePages: 18432 kB FilePmdMapped: 4096 kB - after this patch FileHugePages: 1067008 kB FilePmdMapped: 1048576 kB This shows that after applying the patch, the entire 1GB file is mapped to huge pages. The stable list is CCed, as without this patch, large folios don't function optimally in the readahead path. It's worth noting that if read_ahead_kb is set to a larger value that isn't aligned with huge page sizes (e.g., 4MB + 128KB), it may still fail to map to hugepages. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 4687fdb ("mm/filemap: Support VM_HUGEPAGE for file mappings") Signed-off-by: Yafang Shao <[email protected]> Tested-by: kernel test robot <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 5802fe9cfc05a34170d100d02bea5c16b4f178ea) Signed-off-by: Jack Vogel <[email protected]>
1 parent 5ca1e37 commit 10ea839

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mm/readahead.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,11 @@ void page_cache_async_ra(struct readahead_control *ractl,
641641
1UL << order);
642642
if (index == expected) {
643643
ra->start += ra->size;
644-
ra->size = get_next_ra_size(ra, max_pages);
644+
/*
645+
* In the case of MADV_HUGEPAGE, the actual size might exceed
646+
* the readahead window.
647+
*/
648+
ra->size = max(ra->size, get_next_ra_size(ra, max_pages));
645649
ra->async_size = ra->size;
646650
goto readit;
647651
}

0 commit comments

Comments
 (0)