Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Frederick Mayle <fmayle@google.com>
Cc: android-mm@google.com, kernel-team@android.com,
	 Frederick Mayle <fmayle@google.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Jan Kara <jack@suse.cz>,
	 Andrew Morton <akpm@linux-foundation.org>,
	linux-fsdevel@vger.kernel.org,  linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] mm/readahead: simplify page_cache_ra_unbounded loop counter reset
Date: Tue, 12 May 2026 13:31:36 -0700	[thread overview]
Message-ID: <20260512203154.754075-3-fmayle@google.com> (raw)
In-Reply-To: <20260512203154.754075-1-fmayle@google.com>

Minor cleanup, no behavior change intended.

`read_pages` ensures that `ractl->_nr_pages` is zero before it returns,
so the `ractl->_nr_pages` term in these expressions contributes nothing.
This seems to have been true since the statements were introduced in
commit f615bd5c4725f ("mm/readahead: Handle ractl nr_pages being
modified").

The new expression has an intuitive explanation. When filesystems
perform readahead, they increment `ractl->_index` by the number of pages
processed, so, after `read_pages` returns, `ractl->_index` points to the
first page after those already processed. `index` points to the first
page considered in the loop. So, `ractl->_index - index` is the number
of pages processed by the loop so far.

Signed-off-by: Frederick Mayle <fmayle@google.com>
---
 mm/readahead.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/readahead.c b/mm/readahead.c
index 23bec5497308..42f2f20633b0 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -281,7 +281,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
 			 */
 			read_pages(ractl);
 			ractl->_index += min_nrpages;
-			i = ractl->_index + ractl->_nr_pages - index;
+			i = ractl->_index - index;
 			continue;
 		}
 
@@ -297,7 +297,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
 				break;
 			read_pages(ractl);
 			ractl->_index += min_nrpages;
-			i = ractl->_index + ractl->_nr_pages - index;
+			i = ractl->_index - index;
 			continue;
 		}
 		if (i == mark)
-- 
2.54.0.563.g4f69b47b94-goog



  parent reply	other threads:[~2026-05-12 20:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 20:31 [PATCH 0/2] mm: document read_pages and simplify usage Frederick Mayle
2026-05-12 20:31 ` [PATCH 1/2] mm/readahead: add kerneldoc for read_pages Frederick Mayle
2026-05-12 21:05   ` Matthew Wilcox
2026-05-13  2:14     ` Andrew Morton
2026-05-12 20:31 ` Frederick Mayle [this message]
2026-05-12 20:37 ` [PATCH 0/2] mm: document read_pages and simplify usage Frederick Mayle

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=20260512203154.754075-3-fmayle@google.com \
    --to=fmayle@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=android-mm@google.com \
    --cc=jack@suse.cz \
    --cc=kernel-team@android.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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