Re: [PATCH 1/1] mm/readahead: simplify page_cache_ra_unbounded loop counter reset

From: Andrew Morton

Date: Fri May 01 2026 - 09:11:55 EST


On Thu, 30 Apr 2026 18:19:07 -0700 Frederick Mayle <fmayle@xxxxxxxxxx> wrote:

> Minor cleanup, no behavior change intended.
>
> `read_pages` ensures that `ractl->_nr_pages` is zero before it returns,

So it seems, but depending upon this might be a bit fragile?

It would be better to make this a more explicit/formal part of the
read_pages() contract. kerneldocifying read_pages() would be a
suitable way.

> 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.
>
> ...
>
> --- a/mm/readahead.c
> +++ b/mm/readahead.c
> @@ -270,7 +270,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;
> }
>
> @@ -286,7 +286,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)
>