Skip to contentSkip to conversation

mm/khugepaged: use page_cache_sync_ra() directly

PATCH In review Aditya Prakash Srivastava 4 participants 5 messages Jul 16

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

PATCH 1/1 mm/khugepaged: use page_cache_sync_ra() directly

The static inline page_cache_sync_readahead() wrapper in pagemap.h is legacy and only wraps page_cache_sync_ra() after initializing a local readahead_control structure using DEFINE_READAHEAD.

Modernize the khugepaged readahead call by using page_cache_sync_ra() directly. This avoids the legacy wrapper and aligns the khugepaged readahead implementation with other subsystems in the kernel.

No functional change is introduced, as the logic and behavior remain identical.

---
 mm/khugepaged.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/khugepaged.c +3 -3
index 617bca76db49..2682b39401b2 100644
@@ -2331,10 +2331,10 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
 			}
 		} else {	/* !is_shmem */
 			if (!folio || xa_is_value(folio)) {
+				DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, index);
+
 				xas_unlock_irq(&xas);
-				page_cache_sync_readahead(mapping, &file->f_ra,
-							  file, index,
-							  end - index);
+				page_cache_sync_ra(&ractl, end - index);
 				/* drain lru cache to help folio_isolate_lru() */
 				lru_add_drain();
 				folio = filemap_lock_folio(mapping, index);
Signature · 1 line
2.47.3
reviewer
#1 lore raw
Quoted 2 lines · Aditya Prakash Srivastava

The static inline page_cache_sync_readahead() wrapper in pagemap.h is legacy and only wraps page_cache_sync_ra() after initializing

How exactly is this a legacy interface?

Quoted 5 lines

a local readahead_control structure using DEFINE_READAHEAD.

Modernize the khugepaged readahead call by using page_cache_sync_ra() directly. This avoids the legacy wrapper and aligns the khugepaged readahead implementation with other subsystems in the kernel.

I can see multiple callers of page_cache_sync_readahead.

Quoted 27 lines

No functional change is introduced, as the logic and behavior remain identical.

---
 mm/khugepaged.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/khugepaged.c +3 -3
index 617bca76db49..2682b39401b2 100644
@@ -2331,10 +2331,10 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
 			}
 		} else {	/* !is_shmem */
 			if (!folio || xa_is_value(folio)) {
+				DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, index);
+
 				xas_unlock_irq(&xas);
-				page_cache_sync_readahead(mapping, &file->f_ra,
-							  file, index,
-							  end - index);
+				page_cache_sync_ra(&ractl, end - index);
 				/* drain lru cache to help folio_isolate_lru() */
 				lru_add_drain();
 				folio = filemap_lock_folio(mapping, index);
#2 lore raw
In reply to Aditya Prakash Srivastava
Quoted 21 lines · Aditya Prakash Srivastava

The static inline page_cache_sync_readahead() wrapper in pagemap.h is legacy and only wraps page_cache_sync_ra() after initializing a local readahead_control structure using DEFINE_READAHEAD.

Modernize the khugepaged readahead call by using page_cache_sync_ra() directly. This avoids the legacy wrapper and aligns the khugepaged readahead implementation with other subsystems in the kernel.

No functional change is introduced, as the logic and behavior remain identical.

---
 mm/khugepaged.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/khugepaged.c +0 -0
index 617bca76db49..2682b39401b2 100644

mm/khugepaged.c static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, · line 2337

Quoted 10 lines
mm/khugepaged.c +3 -3
@@ -2331,10 +2331,10 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
 			}
 		} else {	/* !is_shmem */
 			if (!folio || xa_is_value(folio)) {
+				DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, index);
+
 				xas_unlock_irq(&xas);
-				page_cache_sync_readahead(mapping, &file->f_ra,
-							  file, index,
-							  end - index);
+				page_cache_sync_ra(&ractl, end - index);

The page_cache_sync_readahead() call nicely wraps these two things.

You are essentially duplicating code, no?

So I also miss the point.

Signature · 3 lines
Cheers,

David
#3 lore raw
In reply to Aditya Prakash Srivastava
Quoted 3 lines · Aditya Prakash Srivastava

The static inline page_cache_sync_readahead() wrapper in pagemap.h is legacy and only wraps page_cache_sync_ra() after initializing a local readahead_control structure using DEFINE_READAHEAD.

As Dev notes there's nothing legacy about it, it's used in multiple places.

Quoted 4 lines

Modernize the khugepaged readahead call by using page_cache_sync_ra() directly. This avoids the legacy wrapper and aligns the khugepaged readahead implementation with other subsystems in the kernel.

Nope, it's replacing a helper function that wraps something with open coding it instead for no good reason.

Quoted 5 lines

No functional change is introduced, as the logic and behavior remain identical.

Sorry this patch is replacing a wrapper with open code for not really much benefit.

Quoted 23 lines
---
 mm/khugepaged.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/khugepaged.c +3 -4
index 617bca76db49..2682b39401b2 100644
@@ -2331,10 +2331,10 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
 			}
 		} else {	/* !is_shmem */
 			if (!folio || xa_is_value(folio)) {
+				DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, index);
+
 				xas_unlock_irq(&xas);
-				page_cache_sync_readahead(mapping, &file->f_ra,
-							  file, index,
-							  end - index);
+				page_cache_sync_ra(&ractl, end - index);
 				/* drain lru cache to help folio_isolate_lru() */
 				lru_add_drain();
 				folio = filemap_lock_folio(mapping, index);
--
Quoted 2 lines

2.47.3

Cheers, Lorenzo

#4 lore raw

Thanks for the feedback. I agree that replacing the helper with its open-coded implementation at a single call site doesn't provide a meaningful improvement. I'll drop this patch.

Thanks,
Aditya

Quoted 52 lines · Lorenzo Stoakes (ARM)
Quoted 3 lines · Aditya Prakash Srivastava

The static inline page_cache_sync_readahead() wrapper in pagemap.h is legacy and only wraps page_cache_sync_ra() after initializing a local readahead_control structure using DEFINE_READAHEAD.

As Dev notes there's nothing legacy about it, it's used in multiple places.

Quoted 4 lines

Modernize the khugepaged readahead call by using page_cache_sync_ra() directly. This avoids the legacy wrapper and aligns the khugepaged readahead implementation with other subsystems in the kernel.

Nope, it's replacing a helper function that wraps something with open coding it instead for no good reason.

Quoted 5 lines

No functional change is introduced, as the logic and behavior remain identical.

Sorry this patch is replacing a wrapper with open code for not really much benefit.

Quoted 23 lines
---
 mm/khugepaged.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/khugepaged.c +3 -4
index 617bca76db49..2682b39401b2 100644
@@ -2331,10 +2331,10 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
                      }
              } else {        /* !is_shmem */
                      if (!folio || xa_is_value(folio)) {
+                             DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, index);
+
                              xas_unlock_irq(&xas);
-                             page_cache_sync_readahead(mapping, &file->f_ra,
-                                                       file, index,
-                                                       end - index);
+                             page_cache_sync_ra(&ractl, end - index);
                              /* drain lru cache to help folio_isolate_lru() */
                              lru_add_drain();
                              folio = filemap_lock_folio(mapping, index);
--
Quoted 2 lines

2.47.3

Cheers, Lorenzo