* Re: [PATCH] [PATCH V2] mm/filemap: fix page end in filemap_get_read_batch
[not found] <20230208022400.28962-1-coolqyj@163.com>
@ 2023-02-08 2:28 ` Matthew Wilcox
0 siblings, 0 replies; only message in thread
From: Matthew Wilcox @ 2023-02-08 2:28 UTC (permalink / raw)
To: coolqyj; +Cc: linux-fsdevel, linux-mm, Qian Yingjin, Andrew Morton
On Wed, Feb 08, 2023 at 10:24:00AM +0800, coolqyj@163.com wrote:
> From: Qian Yingjin <qian@ddn.com>
>
> 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.
>
> Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
> Signed-off-by: Qian Yingjin <qian@ddn.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: stable@vger.kernel.org
> ---
> mm/filemap.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index c4d4ace9cc70..0e20a8d6dd93 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2588,18 +2588,19 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
> struct folio *folio;
> int err = 0;
>
> + /* "last_index" is the index of the page beyond the end of the read */
> last_index = DIV_ROUND_UP(iocb->ki_pos + iter->count, PAGE_SIZE);
> retry:
> if (fatal_signal_pending(current))
> return -EINTR;
>
> - filemap_get_read_batch(mapping, index, last_index, fbatch);
> + filemap_get_read_batch(mapping, index, last_index - 1, fbatch);
> if (!folio_batch_count(fbatch)) {
> if (iocb->ki_flags & IOCB_NOIO)
> return -EAGAIN;
> page_cache_sync_readahead(mapping, ra, filp, index,
> last_index - index);
> - filemap_get_read_batch(mapping, index, last_index, fbatch);
> + filemap_get_read_batch(mapping, index, last_index - 1, fbatch);
> }
> if (!folio_batch_count(fbatch)) {
> if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-08 2:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20230208022400.28962-1-coolqyj@163.com>
2023-02-08 2:28 ` [PATCH] [PATCH V2] mm/filemap: fix page end in filemap_get_read_batch Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).