mm/readahead: simplify page_cache_ra_unbounded loop counter reset
Subsystems (3)
PATCH 1/1 mm/readahead: simplify page_cache_ra_unbounded loop counter reset
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.
--- mm/readahead.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/readahead.c +2 -2
@@ -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)
base-commit: 88ca94c8849696985b1b70ebec4b01c4b58cafdd
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Andrew Morton
maintainerQuoted 3 lines · On Thu, 30 Apr 2026 18:19:07 -0700 Frederick Mayle <[email protected]> wrote:
Minor cleanup, no behavior change intended.
read_pagesensures thatractl->_nr_pagesis 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.
Quoted 35 lines
so the
ractl->_nr_pagesterm in these expressions contributes nothing. This seems to have been true since the statements were introduced in commitf615bd5c4725f("mm/readahead: Handle ractlnr_pagesbeing modified").The new expression has an intuitive explanation. When filesystems perform readahead, they increment
ractl->_indexby the number of pages processed, so, afterread_pagesreturns,ractl->_indexpoints to the first page after those already processed.indexpoints to the first page considered in the loop. So,ractl->_index - indexis the number of pages processed by the loop so far....
mm/readahead.c +2
-2@@ -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)
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Thu, 30 Apr 2026 18:19:07 -0700 Frederick Mayle <[email protected]> wrote:
Minor cleanup, no behavior change intended.
Quoted 7 lines
Quoted 1 line
read_pagesensures thatractl->_nr_pagesis 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. kerneldocifyingread_pages()would be a suitable way.
I agree. I've sent the following patch to document the invariant
https://lore.kernel.org/r/[email protected]/
Andrew Morton
maintainerQuoted 8 lines · On Thu, 7 May 2026 19:01:27 -0700 Frederick Mayle <[email protected]> wrote:
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Thu, 30 Apr 2026 18:19:07 -0700 Frederick Mayle <[email protected]> wrote:
Minor cleanup, no behavior change intended.
read_pagesensures thatractl->_nr_pagesis zero before it returns,
Quoted 8 lines
Quoted 5 lines
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. kerneldocifyingread_pages()would be a suitable way.I agree. I've sent the following patch to document the invariant
https://lore.kernel.org/r/[email protected]/
Thanks. I suggest you turn both into a single patch and resend when people have returned and recovered from the conference ;)