Skip to contentSkip to conversation

readahead: Use folio_nr_pages() instead of shift operation

PATCH Applied Chi Zhiling 4 participants 6 messages Jul 10, 2025 – Jul 14, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 readahead: Use folio_nr_pages() instead of shift operation

From: Chi Zhiling <[email protected]>

folio_nr_pages() is faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
 mm/readahead.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/readahead.c +1 -1
index 95a24f12d1e7..406756d34309 100644
@@ -649,7 +649,7 @@ void page_cache_async_ra(struct readahead_control *ractl,
 	 * Ramp up sizes, and push forward the readahead window.
 	 */
 	expected = round_down(ra->start + ra->size - ra->async_size,
-			1UL << folio_order(folio));
+			folio_nr_pages(folio));
 	if (index == expected) {
 		ra->start += ra->size;
 		/*
Signature · 1 line
2.43.0
#1 lore raw
Quoted 15 lines · Chi Zhiling

From: Chi Zhiling <[email protected]>

folio_nr_pages() is faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
  mm/readahead.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/readahead.c +0 -0
index 95a24f12d1e7..406756d34309 100644

mm/readahead.c void page_cache_async_ra(struct readahead_control *ractl, · line 655

Quoted 8 lines
mm/readahead.c +1 -1
@@ -649,7 +649,7 @@ void page_cache_async_ra(struct readahead_control *ractl,
  	 * Ramp up sizes, and push forward the readahead window.
  	 */
  	expected = round_down(ra->start + ra->size - ra->async_size,
-			1UL << folio_order(folio));
+			folio_nr_pages(folio));
  	if (index == expected) {
  		ra->start += ra->size;
  		/*

This should probably get squashed in Ryans commit?

LGTM

Signature · 3 lines
Cheers,

David / dhildenb
#2 lore raw
Quoted 11 lines · David Hildenbrand
Quoted 10 lines · Chi Zhiling

From: Chi Zhiling <[email protected]>

folio_nr_pages() is faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
  mm/readahead.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 13 lines
mm/readahead.c +1 -1
index 95a24f12d1e7..406756d34309 100644
@@ -649,7 +649,7 @@ void page_cache_async_ra(struct readahead_control 
 *ractl,
        * Ramp up sizes, and push forward the readahead window.
        */
       expected = round_down(ra->start + ra->size - ra->async_size,
-            1UL << folio_order(folio));
+            folio_nr_pages(folio));
       if (index == expected) {
           ra->start += ra->size;
Quoted 1 line

          /*

This should probably get squashed in Ryans commit?

I have no objection, it's up to Ryan.

Quoted 2 lines

LGTM

Thanks,

Quoted 1 line
maintainer
#3 lore raw
Quoted 29 lines · On Sat, 12 Jul 2025 10:23:32 +0800 Chi Zhiling <[email protected]> wrote:
Quoted 11 lines · David Hildenbrand
Quoted 10 lines · Chi Zhiling

From: Chi Zhiling <[email protected]>

folio_nr_pages() is faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
  mm/readahead.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 13 lines
mm/readahead.c +1 -1
index 95a24f12d1e7..406756d34309 100644
@@ -649,7 +649,7 @@ void page_cache_async_ra(struct readahead_control 
 *ractl,
        * Ramp up sizes, and push forward the readahead window.
        */
       expected = round_down(ra->start + ra->size - ra->async_size,
-            1UL << folio_order(folio));
+            folio_nr_pages(folio));
       if (index == expected) {
           ra->start += ra->size;
Quoted 1 line

          /*

This should probably get squashed in Ryans commit?

Quoted 1 line

I have no objection, it's up to Ryan.

"Ryans commit" is now c4602f9fa77f ("mm/readahead: store folio order in struct file_ra_state") in mm-stable. I'd prefer not to rebase for this!

Reviewed-by
#4 lore raw
Quoted 31 lines · Andrew Morton
Quoted 29 lines · On Sat, 12 Jul 2025 10:23:32 +0800 Chi Zhiling <[email protected]> wrote:
Quoted 27 lines · David Hildenbrand
Quoted 23 lines · Chi Zhiling

From: Chi Zhiling <[email protected]>

folio_nr_pages() is faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
  mm/readahead.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
mm/readahead.c +1 -1
index 95a24f12d1e7..406756d34309 100644
@@ -649,7 +649,7 @@ void page_cache_async_ra(struct readahead_control 
 *ractl,
        * Ramp up sizes, and push forward the readahead window.
        */
       expected = round_down(ra->start + ra->size - ra->async_size,
-            1UL << folio_order(folio));
+            folio_nr_pages(folio));
       if (index == expected) {
           ra->start += ra->size;
Quoted 1 line

          /*

This should probably get squashed in Ryans commit?

Quoted 5 lines
Quoted 1 line

I have no objection, it's up to Ryan.

"Ryans commit" is now c4602f9fa77f ("mm/readahead: store folio order in struct file_ra_state") in mm-stable. I'd prefer not to rebase for this!

Sorry about that... the function was previously using foilio_order() and storing in a local variable and using it in 2 places, one of which was "1UL << order". Because the other user went away I just moved the folio_order() call inline. But agree folio_nr_pages() is better. FWIW:

#5 lore raw
In reply to Andrew Morton
Quoted 31 lines · Andrew Morton
Quoted 29 lines · On Sat, 12 Jul 2025 10:23:32 +0800 Chi Zhiling <[email protected]> wrote:
Quoted 27 lines · David Hildenbrand
Quoted 23 lines · Chi Zhiling

From: Chi Zhiling <[email protected]>

folio_nr_pages() is faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
   mm/readahead.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
mm/readahead.c +1 -1
index 95a24f12d1e7..406756d34309 100644
@@ -649,7 +649,7 @@ void page_cache_async_ra(struct readahead_control
 *ractl,
        * Ramp up sizes, and push forward the readahead window.
        */
       expected = round_down(ra->start + ra->size - ra->async_size,
-            1UL << folio_order(folio));
+            folio_nr_pages(folio));
       if (index == expected) {
           ra->start += ra->size;
Quoted 1 line

          /*

This should probably get squashed in Ryans commit?

Quoted 4 lines
Quoted 1 line

I have no objection, it's up to Ryan.

"Ryans commit" is now c4602f9fa77f ("mm/readahead: store folio order in struct file_ra_state") in mm-stable. I'd prefer not to rebase for this!

Yeah, in that case, obviously no rebase :)

Signature · 3 lines
Cheers,

David / dhildenb