Skip to contentSkip to conversation

mm: minor cleanups in rmap and memory-failure

PATCH Superseded Ye Liu 3 participants 10 messages Apr 18, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ye Liu

author
#0 lore raw

cover mm: minor cleanups in rmap and memory-failure

From: Ye Liu <[email protected]>

Minor cleanups in mm/rmap.c and mm/memory-failure.c:

- Rename a local variable for consistency
- Fix a typo in a comment
- Inline a trivial helper function to its call sites

No functional changes.

Ye Liu (3):
mm/rmap: rename page__anon_vma to page_anon_vma for consistency mm/rmap: fix typo in comment in page_address_in_vma mm/memory-failure: inline add_to_kill_anon_file() logic at call sites

 mm/memory-failure.c | 15 ++++-----------
 mm/rmap.c           | 10 +++++-----
 2 files changed, 9 insertions(+), 16 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/3 mm/rmap: rename page__anon_vma to page_anon_vma for consistency

From: Ye Liu <[email protected]>

Renamed local variable page__anon_vma in page_address_in_vma() to page_anon_vma. The previous naming convention of using double underscores (__) is unnecessary and inconsistent with typical kernel style, which uses single underscores to denote local variables. Also updated comments to reflect the new variable name.

Functionality unchanged.

---
 mm/rmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/rmap.c +4 -4
index 67bb273dfb80..b509c226e50d 100644
@@ -789,13 +789,13 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		const struct page *page, const struct vm_area_struct *vma)
 {
 	if (folio_test_anon(folio)) {
-		struct anon_vma *page__anon_vma = folio_anon_vma(folio);
+		struct anon_vma *page_anon_vma = folio_anon_vma(folio);
 		/*
 		 * Note: swapoff's unuse_vma() is more efficient with this
 		 * check, and needs it to match anon_vma when KSM is active.
 		 */
-		if (!vma->anon_vma || !page__anon_vma ||
-		    vma->anon_vma->root != page__anon_vma->root)
+		if (!vma->anon_vma || !page_anon_vma ||
+		    vma->anon_vma->root != page_anon_vma->root)
 			return -EFAULT;
 	} else if (!vma->vm_file) {
 		return -EFAULT;
@@ -803,7 +803,7 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		return -EFAULT;
 	}
 
-	/* KSM folios don't reach here because of the !page__anon_vma check */
+	/* KSM folios don't reach here because of the !page_anon_vma check */
 	return vma_address(vma, page_pgoff(folio, page), 1);
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] mm/rmap: rename page__anon_vma to page_anon_vma for consistency

Quoted 11 lines · Ye Liu

From: Ye Liu <[email protected]>

Renamed local variable page__anon_vma in page_address_in_vma() to page_anon_vma. The previous naming convention of using double underscores (__) is unnecessary and inconsistent with typical kernel style, which uses single underscores to denote local variables. Also updated comments to reflect the new variable name.

Functionality unchanged.

Thanks, this looks good. I don't know why we named it this way :)

Quoted 37 lines
---
 mm/rmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/rmap.c +4 -5
index 67bb273dfb80..b509c226e50d 100644
@@ -789,13 +789,13 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		const struct page *page, const struct vm_area_struct *vma)
 {
 	if (folio_test_anon(folio)) {
-		struct anon_vma *page__anon_vma = folio_anon_vma(folio);
+		struct anon_vma *page_anon_vma = folio_anon_vma(folio);
 		/*
 		 * Note: swapoff's unuse_vma() is more efficient with this
 		 * check, and needs it to match anon_vma when KSM is active.
 		 */
-		if (!vma->anon_vma || !page__anon_vma ||
-		    vma->anon_vma->root != page__anon_vma->root)
+		if (!vma->anon_vma || !page_anon_vma ||
+		    vma->anon_vma->root != page_anon_vma->root)
 			return -EFAULT;
 	} else if (!vma->vm_file) {
 		return -EFAULT;
@@ -803,7 +803,7 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		return -EFAULT;
 	}
 
-	/* KSM folios don't reach here because of the !page__anon_vma check */
+	/* KSM folios don't reach here because of the !page_anon_vma check */
 	return vma_address(vma, page_pgoff(folio, page), 1);
 }
 
--

2.25.1

#3 lore raw

Re: [PATCH 1/3] mm/rmap: rename page__anon_vma to page_anon_vma for consistency

Quoted 9 lines · Lorenzo Stoakes
Quoted 8 lines · Ye Liu

From: Ye Liu <[email protected]>

Renamed local variable page__anon_vma in page_address_in_vma() to page_anon_vma. The previous naming convention of using double underscores (__) is unnecessary and inconsistent with typical kernel style, which uses single underscores to denote local variables. Also updated comments to reflect the new variable name.

Quoted 5 lines
Quoted 3 lines

Functionality unchanged.

Thanks, this looks good. I don't know why we named it this way :)

At that time there was page_anon_vma() instead of folio_anon_vma() so the author couldn't name the variable page_anon_vma :)

Signature · 2 lines
Cheers,
Harry / Hyeonggon
Quoted 39 lines
Quoted 37 lines
---
 mm/rmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/rmap.c +4 -5
index 67bb273dfb80..b509c226e50d 100644
@@ -789,13 +789,13 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		const struct page *page, const struct vm_area_struct *vma)
 {
 	if (folio_test_anon(folio)) {
-		struct anon_vma *page__anon_vma = folio_anon_vma(folio);
+		struct anon_vma *page_anon_vma = folio_anon_vma(folio);
 		/*
 		 * Note: swapoff's unuse_vma() is more efficient with this
 		 * check, and needs it to match anon_vma when KSM is active.
 		 */
-		if (!vma->anon_vma || !page__anon_vma ||
-		    vma->anon_vma->root != page__anon_vma->root)
+		if (!vma->anon_vma || !page_anon_vma ||
+		    vma->anon_vma->root != page_anon_vma->root)
 			return -EFAULT;
 	} else if (!vma->vm_file) {
 		return -EFAULT;
@@ -803,7 +803,7 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		return -EFAULT;
 	}
 
-	/* KSM folios don't reach here because of the !page__anon_vma check */
+	/* KSM folios don't reach here because of the !page_anon_vma check */
 	return vma_address(vma, page_pgoff(folio, page), 1);
 }
 
--

2.25.1

#4 lore raw

Re: [PATCH 1/3] mm/rmap: rename page__anon_vma to page_anon_vma for consistency

Quoted 10 lines · Harry Yoo
Quoted 9 lines · Lorenzo Stoakes
Quoted 8 lines · Ye Liu

From: Ye Liu <[email protected]>

Renamed local variable page__anon_vma in page_address_in_vma() to page_anon_vma. The previous naming convention of using double underscores (__) is unnecessary and inconsistent with typical kernel style, which uses single underscores to denote local variables. Also updated comments to reflect the new variable name.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Functionality unchanged.

Thanks, this looks good. I don't know why we named it this way :)

At that time there was page_anon_vma() instead of folio_anon_vma() so the author couldn't name the variable page_anon_vma :)

Ahhh mystery__solved! Thanks Harry ;)

Quoted 44 lines

--
Cheers,
Harry / Hyeonggon

Quoted 39 lines
Quoted 37 lines
---
 mm/rmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/rmap.c +4 -5
index 67bb273dfb80..b509c226e50d 100644
@@ -789,13 +789,13 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		const struct page *page, const struct vm_area_struct *vma)
 {
 	if (folio_test_anon(folio)) {
-		struct anon_vma *page__anon_vma = folio_anon_vma(folio);
+		struct anon_vma *page_anon_vma = folio_anon_vma(folio);
 		/*
 		 * Note: swapoff's unuse_vma() is more efficient with this
 		 * check, and needs it to match anon_vma when KSM is active.
 		 */
-		if (!vma->anon_vma || !page__anon_vma ||
-		    vma->anon_vma->root != page__anon_vma->root)
+		if (!vma->anon_vma || !page_anon_vma ||
+		    vma->anon_vma->root != page_anon_vma->root)
 			return -EFAULT;
 	} else if (!vma->vm_file) {
 		return -EFAULT;
@@ -803,7 +803,7 @@ unsigned long page_address_in_vma(const struct folio *folio,
 		return -EFAULT;
 	}
 
-	/* KSM folios don't reach here because of the !page__anon_vma check */
+	/* KSM folios don't reach here because of the !page_anon_vma check */
 	return vma_address(vma, page_pgoff(folio, page), 1);
 }
 
--

2.25.1

author
#5 lore raw

PATCH 2/3 mm/rmap: fix typo in comment in page_address_in_vma

In reply to Ye Liu

From: Ye Liu <[email protected]>

Fixes a minor typo in the comment above page_address_in_vma():
"responsibililty" → "responsibility"

---
 mm/rmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/rmap.c +1 -1
index b509c226e50d..a9eed8981e18 100644
@@ -774,7 +774,7 @@ static bool should_defer_flush(struct mm_struct *mm, enum ttu_flags flags)
  * @vma: The VMA we need to know the address in.
  *
  * Calculates the user virtual address of this page in the specified VMA.
- * It is the caller's responsibililty to check the page is actually
+ * It is the caller's responsibility to check the page is actually
  * within the VMA.  There may not currently be a PTE pointing at this
  * page, but if a page fault occurs at this address, this is the page
  * which will be accessed.
Signature · 1 line
2.25.1
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] mm/rmap: fix typo in comment in page_address_in_vma

Quoted 6 lines · Ye Liu

From: Ye Liu <[email protected]>

Fixes a minor typo in the comment above page_address_in_vma():
"responsibililty" → "responsibility"

LGTM,

Quoted 20 lines
---
 mm/rmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/rmap.c +1 -2
index b509c226e50d..a9eed8981e18 100644
@@ -774,7 +774,7 @@ static bool should_defer_flush(struct mm_struct *mm, enum ttu_flags flags)
  * @vma: The VMA we need to know the address in.
  *
  * Calculates the user virtual address of this page in the specified VMA.
- * It is the caller's responsibililty to check the page is actually
+ * It is the caller's responsibility to check the page is actually
  * within the VMA.  There may not currently be a PTE pointing at this
  * page, but if a page fault occurs at this address, this is the page
  * which will be accessed.
--

2.25.1

author
#7 lore raw

PATCH 3/3 mm/memory-failure: inline add_to_kill_anon_file() logic at call sites

In reply to Ye Liu

From: Ye Liu <[email protected]>

The add_to_kill_anon_file() helper function only checked for -EFAULT return values before calling __add_to_kill(). Removes the unnecessary wrapper and moves the addr == -EFAULT checks directly into collect_procs_anon() and collect_procs_file().

This ensures that error handling is performed close to where the address is derived (via page_mapped_in_vma() or page_address_in_vma()), rather than being obscured inside a helper function.

No functional changes are introduced.

---
 mm/memory-failure.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
mm/memory-failure.c +4 -11
index b91a33fb6c69..ec0041c95b27 100644
@@ -486,15 +486,6 @@ static void __add_to_kill(struct task_struct *tsk, const struct page *p,
 	list_add_tail(&tk->nd, to_kill);
 }
 
-static void add_to_kill_anon_file(struct task_struct *tsk, const struct page *p,
-		struct vm_area_struct *vma, struct list_head *to_kill,
-		unsigned long addr)
-{
-	if (addr == -EFAULT)
-		return;
-	__add_to_kill(tsk, p, vma, to_kill, addr);
-}
-
 #ifdef CONFIG_KSM
 static bool task_in_to_kill_list(struct list_head *to_kill,
 				 struct task_struct *tsk)
@@ -634,7 +625,8 @@ static void collect_procs_anon(const struct folio *folio,
 			if (vma->vm_mm != t->mm)
 				continue;
 			addr = page_mapped_in_vma(page, vma);
-			add_to_kill_anon_file(t, page, vma, to_kill, addr);
+			if (addr != -EFAULT)
+				__add_to_kill(t, page, vma, to_kill, addr);
 		}
 	}
 	rcu_read_unlock();
@@ -674,7 +666,8 @@ static void collect_procs_file(const struct folio *folio,
 			if (vma->vm_mm != t->mm)
 				continue;
 			addr = page_address_in_vma(folio, page, vma);
-			add_to_kill_anon_file(t, page, vma, to_kill, addr);
+			if (addr != -EFAULT)
+				__add_to_kill(t, page, vma, to_kill, addr);
 		}
 	}
 	rcu_read_unlock();
Signature · 1 line
2.25.1
#8 lore raw

Re: [PATCH 3/3] mm/memory-failure: inline add_to_kill_anon_file() logic at call sites

Quoted 10 lines · Ye Liu

From: Ye Liu <[email protected]>

The add_to_kill_anon_file() helper function only checked for -EFAULT return values before calling __add_to_kill(). Removes the unnecessary wrapper and moves the addr == -EFAULT checks directly into collect_procs_anon() and collect_procs_file().

This ensures that error handling is performed close to where the address is derived (via page_mapped_in_vma() or page_address_in_vma()), rather than being obscured inside a helper function.

Yeah, no.

You're duplicating logic here (the old classic - what if we change logic in one call site but not the other etc.) and removing self-documentation of what's going on here.

This is actually a net negative imo. Please drop this patch from the series + send a v2 for the 2 good patches (with correct cc's ;)

Thanks!

Quoted 51 lines

No functional changes are introduced.

---
 mm/memory-failure.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
mm/memory-failure.c +4 -12
index b91a33fb6c69..ec0041c95b27 100644
@@ -486,15 +486,6 @@ static void __add_to_kill(struct task_struct *tsk, const struct page *p,
 	list_add_tail(&tk->nd, to_kill);
 }
 
-static void add_to_kill_anon_file(struct task_struct *tsk, const struct page *p,
-		struct vm_area_struct *vma, struct list_head *to_kill,
-		unsigned long addr)
-{
-	if (addr == -EFAULT)
-		return;
-	__add_to_kill(tsk, p, vma, to_kill, addr);
-}
-
 #ifdef CONFIG_KSM
 static bool task_in_to_kill_list(struct list_head *to_kill,
 				 struct task_struct *tsk)
@@ -634,7 +625,8 @@ static void collect_procs_anon(const struct folio *folio,
 			if (vma->vm_mm != t->mm)
 				continue;
 			addr = page_mapped_in_vma(page, vma);
-			add_to_kill_anon_file(t, page, vma, to_kill, addr);
+			if (addr != -EFAULT)
+				__add_to_kill(t, page, vma, to_kill, addr);
 		}
 	}
 	rcu_read_unlock();
@@ -674,7 +666,8 @@ static void collect_procs_file(const struct folio *folio,
 			if (vma->vm_mm != t->mm)
 				continue;
 			addr = page_address_in_vma(folio, page, vma);
-			add_to_kill_anon_file(t, page, vma, to_kill, addr);
+			if (addr != -EFAULT)
+				__add_to_kill(t, page, vma, to_kill, addr);
 		}
 	}
 	rcu_read_unlock();
--

2.25.1

#9 lore raw
In reply to Ye Liu

Hi Ye,

I asked you in the other thread to cc- rmap stuff to a number of people while we sort out the MAINTAINERS file, please do try to do so in future. I caught this due to a lei rule but otherwise we might miss it.

I have added the cc's here for you manually. Thanks!

Quoted 22 lines · Ye Liu

From: Ye Liu <[email protected]>

Minor cleanups in mm/rmap.c and mm/memory-failure.c:

- Rename a local variable for consistency
- Fix a typo in a comment
- Inline a trivial helper function to its call sites

No functional changes.

Ye Liu (3):
mm/rmap: rename page__anon_vma to page_anon_vma for consistency mm/rmap: fix typo in comment in page_address_in_vma mm/memory-failure: inline add_to_kill_anon_file() logic at call sites

 mm/memory-failure.c | 15 ++++-----------
 mm/rmap.c           | 10 +++++-----
 2 files changed, 9 insertions(+), 16 deletions(-)

--
2.25.1