Skip to contentSkip to conversation

mm/khugepaged: fix the address passed to notifier on testing young

PATCH Applied Wei Yang 6 participants 12 messages Aug 22, 2025 – Aug 26, 2025

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/khugepaged: fix the address passed to notifier on testing young

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test. In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

---
The original commit 8ee53820edfd is at 2011.
Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
 mm/khugepaged.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +1 -1
index 24e18a7f8a93..b000942250d1 100644
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
 		if (cc->is_khugepaged &&
 		    (pte_young(pteval) || folio_test_young(folio) ||
 		     folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-								     address)))
+								     _address)))
 			referenced++;
 	}
 	if (!writable) {
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test. In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

---
The original commit 8ee53820edfd is at 2011.
Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
  mm/khugepaged.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +0 -0
index 24e18a7f8a93..b000942250d1 100644

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1424

Quoted 8 lines
mm/khugepaged.c +1 -1
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
              if (cc->is_khugepaged &&
                  (pte_young(pteval) || folio_test_young(folio) ||
                   folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-                                                                  address)))
+                                                                  _address)))
                      referenced++;
      }
      if (!writable) {

Wow, I have gone through this code so many times and never noticed this.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

author
#2 lore raw
Quoted 30 lines · Dev Jain
Quoted 28 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test. In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

---
The original commit 8ee53820edfd is at 2011.
Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
  mm/khugepaged.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1424

Quoted 13 lines
mm/khugepaged.c +1 -1
index 24e18a7f8a93..b000942250d1 100644
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
              if (cc->is_khugepaged &&
                  (pte_young(pteval) || folio_test_young(folio) ||
                   folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-                                                                  address)))
+                                                                  _address)))
                      referenced++;
      }
      if (!writable) {

Wow, I have gone through this code so many times and never noticed this.

Yeah, also I am surprised when noticing it.

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#3 lore raw
In reply to Wei Yang
Quoted 20 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test. In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>
Quoted 1 line

---

I hope you must have rebased since your previous patch got pulled, and the difference of time between these two events is less than 1.5 hours :)

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

maintainer
#4 lore raw
Quoted 1 line · Dev Jain

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Now deleted.

author
#5 lore raw
In reply to Dev Jain
Quoted 22 lines · Dev Jain
Quoted 20 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test. In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>
Quoted 5 lines
Quoted 1 line

---

I hope you must have rebased since your previous patch got pulled, and the difference of time between these two events is less than 1.5 hours :)

Thanks

I took a look at the latest mm-new, this one applies.

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#6 lore raw
In reply to Wei Yang
Quoted 43 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test. In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

---
The original commit 8ee53820edfd is at 2011.
Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
 mm/khugepaged.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +1 -1
index 24e18a7f8a93..b000942250d1 100644
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
 		if (cc->is_khugepaged &&
 		    (pte_young(pteval) || folio_test_young(folio) ||
 		     folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-								     address)))
+								     _address)))
 			referenced++;
 	}
 	if (!writable) {
Signature · 1 line
2.34.1

LGTM. Reviewed-by: Zi Yan <[email protected]>

--
Best Regards,
Yan, Zi

Acked-by on v1 1/1
#7 lore raw
In reply to Wei Yang
Quoted 2 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test.

... "but we are passing the wrong address".

Quoted 31 lines

In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

---
The original commit 8ee53820edfd is at 2011.
Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
  mm/khugepaged.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +0 -0
index 24e18a7f8a93..b000942250d1 100644

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1421

Quoted 5 lines
mm/khugepaged.c +1 -1
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
  		if (cc->is_khugepaged &&
  		    (pte_young(pteval) || folio_test_young(folio) ||
  		     folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-								     address)))
+								     _address)))

Please just put that into a single line, that's a perfectly reasonable case to exceed 80 chars.

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1424

Quoted 3 lines
mm/khugepaged.c +0 -0
  			referenced++;
  	}
  	if (!writable) {

Maybe, just maybe, it's because of *horrible* variable naming.

Can someone please send a cleanup to rename address -> pmd_addr and _address -> pte_addr or sth like that?

pretty much any naming is better than this.

Signature · 3 lines
Cheers

David / dhildenb
#8 lore raw
Quoted 49 lines · David Hildenbrand
Quoted 2 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test.

... "but we are passing the wrong address".

Quoted 31 lines

In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

---
The original commit 8ee53820edfd is at 2011.
Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
  mm/khugepaged.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +0 -0
index 24e18a7f8a93..b000942250d1 100644

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1421

Quoted 5 lines
mm/khugepaged.c +1 -1
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
  		if (cc->is_khugepaged &&
  		    (pte_young(pteval) || folio_test_young(folio) ||
  		     folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-								     address)))
+								     _address)))

Please just put that into a single line, that's a perfectly reasonable case to exceed 80 chars.

Quoted 8 lines

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1424

Quoted 3 lines
mm/khugepaged.c +0 -0
  			referenced++;
  	}
  	if (!writable) {

Maybe, just maybe, it's because of *horrible* variable naming.

Can someone please send a cleanup to rename address -> pmd_addr and _address -> pte_addr or sth like that?

YES THIS.

Quoted 2 lines

pretty much any naming is better than this.

I despise it, and I realyl underlined this on review in Nico's series because it's just beyond belief.

It's terrible. I mean maybe even I will do something about this, if my review load eases up at some point...

Quoted 6 lines

--
Cheers

David / dhildenb

Cheers, Lorenzo

author
#9 lore raw

On Tue, Aug 26, 2025 at 10:03:27AM +0100, Lorenzo Stoakes wrote:
[...]

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
  			referenced++;
  	}
  	if (!writable) {

Maybe, just maybe, it's because of *horrible* variable naming.

Can someone please send a cleanup to rename address -> pmd_addr and _address -> pte_addr or sth like that?

Quoted 8 lines

YES THIS.

Quoted 2 lines

pretty much any naming is better than this.

I despise it, and I realyl underlined this on review in Nico's series because it's just beyond belief.

I see your comment to Nico's series.

Quoted 3 lines

It's terrible. I mean maybe even I will do something about this, if my review load eases up at some point...

If you are fine, I could help to do the renaming.

Quoted 2 lines

Cheers, Lorenzo

Signature · 2 lines
Wei Yang
Help you, Help me
author
#10 lore raw
In reply to David Hildenbrand
Quoted 47 lines · David Hildenbrand
Quoted 2 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test.

... "but we are passing the wrong address".

Quoted 31 lines

In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

---
The original commit 8ee53820edfd is at 2011.
Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
  mm/khugepaged.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +0 -0
index 24e18a7f8a93..b000942250d1 100644

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1421

Quoted 5 lines
mm/khugepaged.c +1 -1
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
  		if (cc->is_khugepaged &&
  		    (pte_young(pteval) || folio_test_young(folio) ||
  		     folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-								     address)))
+								     _address)))

Please just put that into a single line, that's a perfectly reasonable case to exceed 80 chars.

Quoted 1 line

Thanks.

@Andrew

Would you mind adjust the changelog and put it into one line?

Quoted 16 lines

mm/khugepaged.c static int hpage_collapse_scan_pmd(struct mm_struct *mm, · line 1424

Quoted 4 lines
mm/khugepaged.c +0 -0
  			referenced++;
  	}
  	if (!writable) {

Maybe, just maybe, it's because of *horrible* variable naming.

Can someone please send a cleanup to rename address -> pmd_addr and _address -> pte_addr or sth like that?

pretty much any naming is better than this.

Signature · 3 lines
Cheers

David / dhildenb
Signature · 2 lines
Wei Yang
Help you, Help me
Reviewed-by on v1 1/1
#11 lore raw
In reply to Wei Yang
Quoted 7 lines · Wei Yang

Commit 8ee53820edfd ("thp: mmu_notifier_test_young") introduced mmu_notifier_test_young(), but we should pass the address need to test. In xxx_scan_pmd(), the actual iteration address is "_address" not "address". We seem to misuse the variable on the very beginning.

Change it to the right one.

Quoted 12 lines
Fixes 8ee53820edfd ("thp: mmu_notifier_test_young")
Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>

Good spot. This code is beyond belief.

Quoted 3 lines

---
The original commit 8ee53820edfd is at 2011.

Oopsies!

Quoted 22 lines

Then the code is moved to khugepaged.c in commit b46e756f5e470 ("thp:
extract khugepaged from mm/huge_memory.c") in 2022.

---
 mm/khugepaged.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +1 -2
index 24e18a7f8a93..b000942250d1 100644
@@ -1418,7 +1418,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
 		if (cc->is_khugepaged &&
 		    (pte_young(pteval) || folio_test_young(folio) ||
 		     folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
-								     address)))
+								     _address)))
 			referenced++;
 	}
 	if (!writable) {
--

2.34.1