linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: coolqyj@163.com
To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Cc: Matthew Wilcox <willy@infradead.org>,
	stable@vger.kernel.org, qian@ddn.com
Subject: [PATCH] mm/filemap: fix page end in filemap_get_read_batch
Date: Wed,  4 Jan 2023 11:21:24 +0800	[thread overview]
Message-ID: <20230104032124.72483-1-coolqyj@163.com> (raw)

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>
---
 mm/filemap.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index c4d4ace9cc70..b7754760c09a 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2371,7 +2371,7 @@ static void shrink_readahead_size_eio(struct file_ra_state *ra)
  * clear so that the caller can take the appropriate action.
  */
 static void filemap_get_read_batch(struct address_space *mapping,
-		pgoff_t index, pgoff_t max, struct folio_batch *fbatch)
+		pgoff_t index, pgoff_t last_index, struct folio_batch *fbatch)
 {
 	XA_STATE(xas, &mapping->i_pages, index);
 	struct folio *folio;
@@ -2380,7 +2380,11 @@ static void filemap_get_read_batch(struct address_space *mapping,
 	for (folio = xas_load(&xas); folio; folio = xas_next(&xas)) {
 		if (xas_retry(&xas, folio))
 			continue;
-		if (xas.xa_index > max || xa_is_value(folio))
+		/*
+		 * "last_index" is the index of the page beyond the end of
+		 * the read.
+		 */
+		if (xas.xa_index >= last_index || xa_is_value(folio))
 			break;
 		if (xa_is_sibling(folio))
 			break;
@@ -2588,6 +2592,7 @@ 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))
-- 
2.34.1


             reply	other threads:[~2023-01-04  3:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04  3:21 coolqyj [this message]
2023-01-04 14:36 ` [PATCH] mm/filemap: fix page end in filemap_get_read_batch Matthew Wilcox
  -- strict thread matches above, loose matches on Subject: below --
2023-01-09  1:58 coolqyj

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230104032124.72483-1-coolqyj@163.com \
    --to=coolqyj@163.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=qian@ddn.com \
    --cc=stable@vger.kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).