Skip to contentSkip to conversation

mm/khugepaged: continue to collapse on SCAN_PMD_NONE

PATCH In review Wei Yang 5 participants 11 messages Nov 12, 2025 – Nov 13, 2025

Subsystems (2)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/khugepaged: continue to collapse on SCAN_PMD_NONE

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

---
 mm/khugepaged.c | 1 +
 1 file changed, 1 insertion(+)
mm/khugepaged.c +1 -0
index 7e8cb181d5bd..4c2217076ad3 100644
@@ -2835,6 +2835,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
 			goto handle_result;
 		/* Whitelisted set of results where continuing OK */
 		case SCAN_PMD_NULL:
+		case SCAN_PMD_NONE:
 		case SCAN_PTE_NON_PRESENT:
 		case SCAN_PTE_UFFD_WP:
 		case SCAN_LACK_REFERENCED_PAGE:
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

Right, bailing out of the whole MADV_COLLAPSE request just because we encounter one empty PMD is too strict ...

It makes sense to treat SCAN_PMD_NONE like the other whitelisted cases (e.g., SCAN_PMD_NULL).

Quoted 3 lines

---

LGTM.

Quoted 15 lines
  mm/khugepaged.c | 1 +
  1 file changed, 1 insertion(+)
mm/khugepaged.c +1 -0
index 7e8cb181d5bd..4c2217076ad3 100644
@@ -2835,6 +2835,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
  			goto handle_result;
  		/* Whitelisted set of results where continuing OK */
  		case SCAN_PMD_NULL:
+		case SCAN_PMD_NONE:
  		case SCAN_PTE_NON_PRESENT:
  		case SCAN_PTE_UFFD_WP:
  		case SCAN_LACK_REFERENCED_PAGE:
author
#2 lore raw
Quoted 12 lines · Lance Yang
Quoted 2 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

Right, bailing out of the whole MADV_COLLAPSE request just because we encounter one empty PMD is too strict ...

It makes sense to treat SCAN_PMD_NONE like the other whitelisted cases (e.g., SCAN_PMD_NULL).

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

---

LGTM.

Thanks for the review.

I'm currently evaluating the use of SCAN_NULL versus SCAN_NONE. It seems their usage in the current code is intermixed, and I'm questioning if there's a strong, practical reason to maintain a distinction between these two states. Should they be unified?

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#3 lore raw
Quoted 14 lines · Wei Yang
Quoted 13 lines · Lance Yang
Quoted 2 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

Right, bailing out of the whole MADV_COLLAPSE request just because we encounter one empty PMD is too strict ...

It makes sense to treat SCAN_PMD_NONE like the other whitelisted cases (e.g., SCAN_PMD_NULL).

Quoted 2 lines

---

LGTM.

Quoted 8 lines
Quoted 2 lines

Thanks for the review.

I'm currently evaluating the use of SCAN_NULL versus SCAN_NONE. It seems their usage in the current code is intermixed, and I'm questioning if there's a strong, practical reason to maintain a distinction between these two states. Should they be unified?

There was some discussion about that in this thread:

https://lore.kernel.org/all/v5ivpub6z2n2uyemlnxgbilzs52ep4lrary7lm7o6axxoneb75@yfacfl5rkzeh/

There are some cleanups mentioned in the thread which you can try if you want :)

author
#4 lore raw
Quoted 25 lines · Dev Jain
Quoted 14 lines · Wei Yang
Quoted 13 lines · Lance Yang
Quoted 2 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

Right, bailing out of the whole MADV_COLLAPSE request just because we encounter one empty PMD is too strict ...

It makes sense to treat SCAN_PMD_NONE like the other whitelisted cases (e.g., SCAN_PMD_NULL).

Quoted 2 lines

---

LGTM.

Quoted 8 lines
Quoted 2 lines

Thanks for the review.

I'm currently evaluating the use of SCAN_NULL versus SCAN_NONE. It seems their usage in the current code is intermixed, and I'm questioning if there's a strong, practical reason to maintain a distinction between these two states. Should they be unified?

Quoted 6 lines

There was some discussion about that in this thread:

https://lore.kernel.org/all/v5ivpub6z2n2uyemlnxgbilzs52ep4lrary7lm7o6axxoneb75@yfacfl5rkzeh/

There are some cleanups mentioned in the thread which you can try if you want :)

Thanks, will take a look.

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

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

---
  mm/khugepaged.c | 1 +
  1 file changed, 1 insertion(+)
mm/khugepaged.c +0 -0
index 7e8cb181d5bd..4c2217076ad3 100644

mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2841

Quoted 7 lines
mm/khugepaged.c +1 -0
@@ -2835,6 +2835,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
  			goto handle_result;
  		/* Whitelisted set of results where continuing OK */
  		case SCAN_PMD_NULL:
+		case SCAN_PMD_NONE:
  		case SCAN_PTE_NON_PRESENT:
  		case SCAN_PTE_UFFD_WP:
  		case SCAN_LACK_REFERENCED_PAGE:

Looks ok to me.

I am really confused about PMD_NONE vs. PMD_NULL.

Is my understanding correct, hat with your patch we can just merge both into a single NO_PMD_TABLE or sth. like that?

Signature · 3 lines
Cheers

David
#7 lore raw
Quoted 24 lines · David Hildenbrand (Red Hat)
Quoted 13 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

---
   mm/khugepaged.c | 1 +
   1 file changed, 1 insertion(+)
mm/khugepaged.c +0 -0
index 7e8cb181d5bd..4c2217076ad3 100644

mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2841

Quoted 7 lines
mm/khugepaged.c +1 -0
@@ -2835,6 +2835,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
   			goto handle_result;
   		/* Whitelisted set of results where continuing OK */
   		case SCAN_PMD_NULL:
+		case SCAN_PMD_NONE:
   		case SCAN_PTE_NON_PRESENT:
   		case SCAN_PTE_UFFD_WP:
   		case SCAN_LACK_REFERENCED_PAGE:

Looks ok to me.

Quoted 4 lines

I am really confused about PMD_NONE vs. PMD_NULL.

Is my understanding correct, hat with your patch we can just merge both into a single NO_PMD_TABLE or sth. like that?

NO_PTE_TABLE, actually

Signature · 3 lines
Cheers

David
author
#8 lore raw
Quoted 25 lines · David Hildenbrand (Red Hat)
Quoted 24 lines · David Hildenbrand (Red Hat)
Quoted 13 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

---
   mm/khugepaged.c | 1 +
   1 file changed, 1 insertion(+)
mm/khugepaged.c +0 -0
index 7e8cb181d5bd..4c2217076ad3 100644

mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2841

Quoted 7 lines
mm/khugepaged.c +1 -0
@@ -2835,6 +2835,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
   			goto handle_result;
   		/* Whitelisted set of results where continuing OK */
   		case SCAN_PMD_NULL:
+		case SCAN_PMD_NONE:
   		case SCAN_PTE_NON_PRESENT:
   		case SCAN_PTE_UFFD_WP:
   		case SCAN_LACK_REFERENCED_PAGE:

Looks ok to me.

Quoted 7 lines
Quoted 4 lines

I am really confused about PMD_NONE vs. PMD_NULL.

Is my understanding correct, hat with your patch we can just merge both into a single NO_PMD_TABLE or sth. like that?

NO_PTE_TABLE, actually

I am thinking about this too.

If no other objections, I will prepare a v2 with this.

BTW, you prefer merge them directly, or merge on top of this change?

Quoted 4 lines
Signature · 3 lines
Cheers

David
Signature · 2 lines
Wei Yang
Help you, Help me
#9 lore raw
Quoted 31 lines · Wei Yang
Quoted 30 lines · David Hildenbrand (Red Hat)
Quoted 28 lines · David Hildenbrand (Red Hat)
Quoted 13 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

---
    mm/khugepaged.c | 1 +
    1 file changed, 1 insertion(+)
mm/khugepaged.c +0 -0
index 7e8cb181d5bd..4c2217076ad3 100644

mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2841

Quoted 7 lines
mm/khugepaged.c +1 -0
@@ -2835,6 +2835,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
    			goto handle_result;
    		/* Whitelisted set of results where continuing OK */
    		case SCAN_PMD_NULL:
+		case SCAN_PMD_NONE:
    		case SCAN_PTE_NON_PRESENT:
    		case SCAN_PTE_UFFD_WP:
    		case SCAN_LACK_REFERENCED_PAGE:

Looks ok to me.

I am really confused about PMD_NONE vs. PMD_NULL.

Is my understanding correct, hat with your patch we can just merge both into a single NO_PMD_TABLE or sth. like that?

Quoted 8 lines
Quoted 2 lines

NO_PTE_TABLE, actually

I am thinking about this too.

If no other objections, I will prepare a v2 with this.

BTW, you prefer merge them directly, or merge on top of this change?

I'd probably do it in a single commit, stating that both scenarios should be handled completely the same.

But no strong opinion against doing it in two commits from my side.

Signature · 3 lines
Cheers

David
reviewer Reviewed-by on v1 1/1
#10 lore raw
In reply to Wei Yang
Quoted 5 lines · Wei Yang

SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range.

---

Make sense to me. And I agree with others' opinions to unify SCAN_PMD_NULL and SCAN_PMD_NONE.

Quoted 15 lines
  mm/khugepaged.c | 1 +
  1 file changed, 1 insertion(+)
mm/khugepaged.c +1 -0
index 7e8cb181d5bd..4c2217076ad3 100644
@@ -2835,6 +2835,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
  			goto handle_result;
  		/* Whitelisted set of results where continuing OK */
  		case SCAN_PMD_NULL:
+		case SCAN_PMD_NONE:
  		case SCAN_PTE_NON_PRESENT:
  		case SCAN_PTE_UFFD_WP:
  		case SCAN_LACK_REFERENCED_PAGE: