diff mbox series

[7/7] mm/readahead: align readahead down to mapping blocksize

Message ID 20230614114637.89759-8-hare@suse.de (mailing list archive)
State New, archived
Headers show
Series RFC: high-order folio support for I/O | expand

Commit Message

Hannes Reinecke June 14, 2023, 11:46 a.m. UTC
If the blocksize of the mapping is larger than the page size we need
to align down readahead to avoid reading past the end of the device.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 mm/readahead.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/mm/readahead.c b/mm/readahead.c
index 031935b78af7..91a7dbf4fa04 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -285,6 +285,7 @@  static void do_page_cache_ra(struct readahead_control *ractl,
 	struct inode *inode = ractl->mapping->host;
 	unsigned long index = readahead_index(ractl);
 	loff_t isize = i_size_read(inode);
+	unsigned int iblksize = i_blocksize(inode);
 	pgoff_t end_index;	/* The last page we want to read */
 
 	if (isize == 0)
@@ -293,6 +294,9 @@  static void do_page_cache_ra(struct readahead_control *ractl,
 	end_index = (isize - 1) >> PAGE_SHIFT;
 	if (index > end_index)
 		return;
+	if (iblksize > PAGE_SIZE)
+		end_index = ALIGN_DOWN(end_index, iblksize);
+
 	/* Don't read past the page containing the last byte of the file */
 	if (nr_to_read > end_index - index)
 		nr_to_read = end_index - index + 1;