Skip to content

Commit 5956592

Browse files
yingjinqianakpm00
authored andcommitted
mm/filemap: fix page end in filemap_get_read_batch
I was running traces of the read code against an RAID storage system to understand why read requests were being misaligned against the underlying RAID strips. I found that the page end offset calculation in filemap_get_read_batch() was off by one. When a read is submitted with end offset 1048575, then it calculates the end page for read of 256 when it should be 255. "last_index" is the index of the page beyond the end of the read and it should be skipped when get a batch of pages for read in @filemap_get_read_batch(). The below simple patch fixes the problem. This code was introduced in kernel 5.12. Link: https://lkml.kernel.org/r/[email protected] Fixes: cbd59c4 ("mm/filemap: use head pages in generic_file_buffered_read") Signed-off-by: Qian Yingjin <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ce4d9a1 commit 5956592

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mm/filemap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,18 +2588,19 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
25882588
struct folio *folio;
25892589
int err = 0;
25902590

2591+
/* "last_index" is the index of the page beyond the end of the read */
25912592
last_index = DIV_ROUND_UP(iocb->ki_pos + iter->count, PAGE_SIZE);
25922593
retry:
25932594
if (fatal_signal_pending(current))
25942595
return -EINTR;
25952596

2596-
filemap_get_read_batch(mapping, index, last_index, fbatch);
2597+
filemap_get_read_batch(mapping, index, last_index - 1, fbatch);
25972598
if (!folio_batch_count(fbatch)) {
25982599
if (iocb->ki_flags & IOCB_NOIO)
25992600
return -EAGAIN;
26002601
page_cache_sync_readahead(mapping, ra, filp, index,
26012602
last_index - index);
2602-
filemap_get_read_batch(mapping, index, last_index, fbatch);
2603+
filemap_get_read_batch(mapping, index, last_index - 1, fbatch);
26032604
}
26042605
if (!folio_batch_count(fbatch)) {
26052606
if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))

0 commit comments

Comments
 (0)