* [Patch v2 0/3] unify PMD scan results and remove redundant cleanup
@ 2025-11-14 3:00 Wei Yang
2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Wei Yang @ 2025-11-14 3:00 UTC (permalink / raw)
To: akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett,
npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt,
mhiramat, mathieu.desnoyers
Cc: linux-mm, Wei Yang
This small series addresses two minor cleanup opportunities in the hugepage
collapse logic.
The initial motivation arose during a code review of madvise_collapse(),
where it was noted that the function was missing a handler for
SCAN_PMD_NONE. This oversight exposed the inconsistent handling of
SCAN_PMD_NULL and SCAN_PMD_NONE.
Since both scan results are functionally identical (they indicate the
absence of a PTE table), the primary patch unifies them into a single,
clearer identifier, SCAN_NO_PTE_TABLE.
The series also takes the opportunity to remove a redundant clearing of
the struct collapse_control.
---
v1: http://lkml.kernel.org/r/20251112020031.25350-1-richard.weiyang@gmail.com
Wei Yang (3):
mm/khugepaged: remove redundant clearing of struct collapse_control
mm/khugepaged: continue to collapse on SCAN_PMD_NONE
mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into
SCAN_NO_PTE_TABLE
include/trace/events/huge_memory.h | 3 +--
mm/khugepaged.c | 24 ++++++++++--------------
2 files changed, 11 insertions(+), 16 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control 2025-11-14 3:00 [Patch v2 0/3] unify PMD scan results and remove redundant cleanup Wei Yang @ 2025-11-14 3:00 ` Wei Yang 2025-11-14 4:37 ` Dev Jain ` (3 more replies) 2025-11-14 3:00 ` [Patch v2 2/3] mm/khugepaged: continue to collapse on SCAN_PMD_NONE Wei Yang 2025-11-14 3:00 ` [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE Wei Yang 2 siblings, 4 replies; 13+ messages in thread From: Wei Yang @ 2025-11-14 3:00 UTC (permalink / raw) To: akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm, Wei Yang The structure struct collapse_control is being unnecessarily cleared twice during the huge page collapse process. Both hpage_collapse_scan_file() and hpage_collapse_scan_pmd() currently perform a clear operation on this structure. Remove the redundant clear operation. Signed-off-by: Wei Yang <richard.weiyang@gmail.com> --- mm/khugepaged.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 7e8cb181d5bd..1fc8986a28b3 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2803,8 +2803,6 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, hend = min(hend, vma->vm_end & HPAGE_PMD_MASK); } mmap_assert_locked(mm); - memset(cc->node_load, 0, sizeof(cc->node_load)); - nodes_clear(cc->alloc_nmask); if (!vma_is_anonymous(vma)) { struct file *file = get_file(vma->vm_file); pgoff_t pgoff = linear_page_index(vma, addr); -- 2.34.1 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control 2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang @ 2025-11-14 4:37 ` Dev Jain 2025-11-14 8:53 ` David Hildenbrand (Red Hat) ` (2 subsequent siblings) 3 siblings, 0 replies; 13+ messages in thread From: Dev Jain @ 2025-11-14 4:37 UTC (permalink / raw) To: Wei Yang, akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm On 14/11/25 8:30 am, Wei Yang wrote: > The structure struct collapse_control is being unnecessarily cleared > twice during the huge page collapse process. > > Both hpage_collapse_scan_file() and hpage_collapse_scan_pmd() currently > perform a clear operation on this structure. > > Remove the redundant clear operation. > > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > --- > mm/khugepaged.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 7e8cb181d5bd..1fc8986a28b3 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2803,8 +2803,6 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, > hend = min(hend, vma->vm_end & HPAGE_PMD_MASK); > } > mmap_assert_locked(mm); > - memset(cc->node_load, 0, sizeof(cc->node_load)); > - nodes_clear(cc->alloc_nmask); > if (!vma_is_anonymous(vma)) { > struct file *file = get_file(vma->vm_file); > pgoff_t pgoff = linear_page_index(vma, addr); Reviewed-by: Dev Jain <dev.jain@arm.com> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control 2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang 2025-11-14 4:37 ` Dev Jain @ 2025-11-14 8:53 ` David Hildenbrand (Red Hat) 2025-11-17 8:04 ` Baolin Wang 2025-11-17 17:23 ` Nico Pache 3 siblings, 0 replies; 13+ messages in thread From: David Hildenbrand (Red Hat) @ 2025-11-14 8:53 UTC (permalink / raw) To: Wei Yang, akpm, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm On 14.11.25 04:00, Wei Yang wrote: > The structure struct collapse_control is being unnecessarily cleared > twice during the huge page collapse process. > > Both hpage_collapse_scan_file() and hpage_collapse_scan_pmd() currently > perform a clear operation on this structure. > > Remove the redundant clear operation. > > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> Right, and the structure does not seem to get used in between. Thanks! Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> -- Cheers David ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control 2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang 2025-11-14 4:37 ` Dev Jain 2025-11-14 8:53 ` David Hildenbrand (Red Hat) @ 2025-11-17 8:04 ` Baolin Wang 2025-11-17 17:23 ` Nico Pache 3 siblings, 0 replies; 13+ messages in thread From: Baolin Wang @ 2025-11-17 8:04 UTC (permalink / raw) To: Wei Yang, akpm, david, lorenzo.stoakes, ziy, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm On 2025/11/14 11:00, Wei Yang wrote: > The structure struct collapse_control is being unnecessarily cleared > twice during the huge page collapse process. > > Both hpage_collapse_scan_file() and hpage_collapse_scan_pmd() currently > perform a clear operation on this structure. > > Remove the redundant clear operation. > > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > --- LGTM. Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control 2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang ` (2 preceding siblings ...) 2025-11-17 8:04 ` Baolin Wang @ 2025-11-17 17:23 ` Nico Pache 3 siblings, 0 replies; 13+ messages in thread From: Nico Pache @ 2025-11-17 17:23 UTC (permalink / raw) To: Wei Yang Cc: akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers, linux-mm On Thu, Nov 13, 2025 at 8:01 PM Wei Yang <richard.weiyang@gmail.com> wrote: > > The structure struct collapse_control is being unnecessarily cleared > twice during the huge page collapse process. > > Both hpage_collapse_scan_file() and hpage_collapse_scan_pmd() currently > perform a clear operation on this structure. > > Remove the redundant clear operation. Nice! The more we can simplify/unify madvise_collapse/collapse the better :) LGTM! Reviewed-by: Nico Pache <npache@redhat.com> > > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > --- > mm/khugepaged.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 7e8cb181d5bd..1fc8986a28b3 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2803,8 +2803,6 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, > hend = min(hend, vma->vm_end & HPAGE_PMD_MASK); > } > mmap_assert_locked(mm); > - memset(cc->node_load, 0, sizeof(cc->node_load)); > - nodes_clear(cc->alloc_nmask); > if (!vma_is_anonymous(vma)) { > struct file *file = get_file(vma->vm_file); > pgoff_t pgoff = linear_page_index(vma, addr); > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 13+ messages in thread
* [Patch v2 2/3] mm/khugepaged: continue to collapse on SCAN_PMD_NONE 2025-11-14 3:00 [Patch v2 0/3] unify PMD scan results and remove redundant cleanup Wei Yang 2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang @ 2025-11-14 3:00 ` Wei Yang 2025-11-14 8:54 ` David Hildenbrand (Red Hat) 2025-11-14 3:00 ` [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE Wei Yang 2 siblings, 1 reply; 13+ messages in thread From: Wei Yang @ 2025-11-14 3:00 UTC (permalink / raw) To: akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm, Wei Yang SCAN_PMD_NONE means current pmd is empty, but we can still continue collapse next pmd range. Signed-off-by: Wei Yang <richard.weiyang@gmail.com> Reviewed-by: Lance Yang <lance.yang@linux.dev> Reviewed-by: Dev Jain <dev.jain@arm.com> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> --- mm/khugepaged.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 1fc8986a28b3..2ee5048b764e 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2833,6 +2833,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: -- 2.34.1 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 2/3] mm/khugepaged: continue to collapse on SCAN_PMD_NONE 2025-11-14 3:00 ` [Patch v2 2/3] mm/khugepaged: continue to collapse on SCAN_PMD_NONE Wei Yang @ 2025-11-14 8:54 ` David Hildenbrand (Red Hat) 0 siblings, 0 replies; 13+ messages in thread From: David Hildenbrand (Red Hat) @ 2025-11-14 8:54 UTC (permalink / raw) To: Wei Yang, akpm, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm On 14.11.25 04:00, Wei Yang wrote: > SCAN_PMD_NONE means current pmd is empty, but we can still continue > collapse next pmd range. > > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > Reviewed-by: Lance Yang <lance.yang@linux.dev> > Reviewed-by: Dev Jain <dev.jain@arm.com> > Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> > --- Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> -- Cheers David ^ permalink raw reply [flat|nested] 13+ messages in thread
* [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE 2025-11-14 3:00 [Patch v2 0/3] unify PMD scan results and remove redundant cleanup Wei Yang 2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang 2025-11-14 3:00 ` [Patch v2 2/3] mm/khugepaged: continue to collapse on SCAN_PMD_NONE Wei Yang @ 2025-11-14 3:00 ` Wei Yang 2025-11-14 5:06 ` Dev Jain ` (3 more replies) 2 siblings, 4 replies; 13+ messages in thread From: Wei Yang @ 2025-11-14 3:00 UTC (permalink / raw) To: akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm, Wei Yang The current hugepage collapse scan results include two separate values, SCAN_PMD_NONE and SCAN_PMD_NULL, which are handled identically by the consuming code. To reduce confusion and improve long-term maintenance, this commit merges these two functionally equivalent states into a single, clearer identifier: SCAN_NO_PTE_TABLE Suggested-by: "David Hildenbrand (Red Hat)" <david@kernel.org> Signed-off-by: Wei Yang <richard.weiyang@gmail.com> --- include/trace/events/huge_memory.h | 3 +-- mm/khugepaged.c | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h index dd94d14a2427..4cde53b45a85 100644 --- a/include/trace/events/huge_memory.h +++ b/include/trace/events/huge_memory.h @@ -10,8 +10,7 @@ #define SCAN_STATUS \ EM( SCAN_FAIL, "failed") \ EM( SCAN_SUCCEED, "succeeded") \ - EM( SCAN_PMD_NULL, "pmd_null") \ - EM( SCAN_PMD_NONE, "pmd_none") \ + EM( SCAN_NO_PTE_TABLE, "no_pte_table") \ EM( SCAN_PMD_MAPPED, "page_pmd_mapped") \ EM( SCAN_EXCEED_NONE_PTE, "exceed_none_pte") \ EM( SCAN_EXCEED_SWAP_PTE, "exceed_swap_pte") \ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 2ee5048b764e..40f9d5939aa5 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -30,8 +30,7 @@ enum scan_result { SCAN_FAIL, SCAN_SUCCEED, - SCAN_PMD_NULL, - SCAN_PMD_NONE, + SCAN_NO_PTE_TABLE, SCAN_PMD_MAPPED, SCAN_EXCEED_NONE_PTE, SCAN_EXCEED_SWAP_PTE, @@ -934,7 +933,7 @@ static inline int check_pmd_state(pmd_t *pmd) pmd_t pmde = pmdp_get_lockless(pmd); if (pmd_none(pmde)) - return SCAN_PMD_NONE; + return SCAN_NO_PTE_TABLE; /* * The folio may be under migration when khugepaged is trying to @@ -944,11 +943,11 @@ static inline int check_pmd_state(pmd_t *pmd) if (pmd_is_migration_entry(pmde)) return SCAN_PMD_MAPPED; if (!pmd_present(pmde)) - return SCAN_PMD_NULL; + return SCAN_NO_PTE_TABLE; if (pmd_trans_huge(pmde)) return SCAN_PMD_MAPPED; if (pmd_bad(pmde)) - return SCAN_PMD_NULL; + return SCAN_NO_PTE_TABLE; return SCAN_SUCCEED; } @@ -958,7 +957,7 @@ static int find_pmd_or_thp_or_none(struct mm_struct *mm, { *pmd = mm_find_pmd(mm, address); if (!*pmd) - return SCAN_PMD_NULL; + return SCAN_NO_PTE_TABLE; return check_pmd_state(*pmd); } @@ -1013,7 +1012,7 @@ static int __collapse_huge_page_swapin(struct mm_struct *mm, pte = pte_offset_map_ro_nolock(mm, pmd, addr, &ptl); if (!pte) { mmap_read_unlock(mm); - result = SCAN_PMD_NULL; + result = SCAN_NO_PTE_TABLE; goto out; } } @@ -1187,7 +1186,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, &compound_pagelist); spin_unlock(pte_ptl); } else { - result = SCAN_PMD_NULL; + result = SCAN_NO_PTE_TABLE; } if (unlikely(result != SCAN_SUCCEED)) { @@ -1270,7 +1269,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, nodes_clear(cc->alloc_nmask); pte = pte_offset_map_lock(mm, pmd, start_addr, &ptl); if (!pte) { - result = SCAN_PMD_NULL; + result = SCAN_NO_PTE_TABLE; goto out; } @@ -1544,8 +1543,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, switch (result) { case SCAN_SUCCEED: break; - case SCAN_PMD_NULL: - case SCAN_PMD_NONE: + case SCAN_NO_PTE_TABLE: /* * All pte entries have been removed and pmd cleared. * Skip all the pte checks and just update the pmd mapping. @@ -2832,8 +2830,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, mmap_read_unlock(mm); goto handle_result; /* Whitelisted set of results where continuing OK */ - case SCAN_PMD_NULL: - case SCAN_PMD_NONE: + case SCAN_NO_PTE_TABLE: case SCAN_PTE_NON_PRESENT: case SCAN_PTE_UFFD_WP: case SCAN_LACK_REFERENCED_PAGE: -- 2.34.1 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE 2025-11-14 3:00 ` [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE Wei Yang @ 2025-11-14 5:06 ` Dev Jain 2025-11-14 8:55 ` David Hildenbrand (Red Hat) ` (2 subsequent siblings) 3 siblings, 0 replies; 13+ messages in thread From: Dev Jain @ 2025-11-14 5:06 UTC (permalink / raw) To: Wei Yang, akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm On 14/11/25 8:30 am, Wei Yang wrote: > The current hugepage collapse scan results include two separate values, > SCAN_PMD_NONE and SCAN_PMD_NULL, which are handled identically by > the consuming code. > > To reduce confusion and improve long-term maintenance, this commit > merges these two functionally equivalent states into a single, clearer > identifier: SCAN_NO_PTE_TABLE > > Suggested-by: "David Hildenbrand (Red Hat)" <david@kernel.org> > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > --- > Reviewed-by: Dev Jain <dev.jain@arm.com> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE 2025-11-14 3:00 ` [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE Wei Yang 2025-11-14 5:06 ` Dev Jain @ 2025-11-14 8:55 ` David Hildenbrand (Red Hat) 2025-11-17 8:11 ` Baolin Wang 2025-11-17 17:25 ` Nico Pache 3 siblings, 0 replies; 13+ messages in thread From: David Hildenbrand (Red Hat) @ 2025-11-14 8:55 UTC (permalink / raw) To: Wei Yang, akpm, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm On 14.11.25 04:00, Wei Yang wrote: > The current hugepage collapse scan results include two separate values, > SCAN_PMD_NONE and SCAN_PMD_NULL, which are handled identically by > the consuming code. > > To reduce confusion and improve long-term maintenance, this commit > merges these two functionally equivalent states into a single, clearer > identifier: SCAN_NO_PTE_TABLE > > Suggested-by: "David Hildenbrand (Red Hat)" <david@kernel.org> > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > --- Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> -- Cheers David ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE 2025-11-14 3:00 ` [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE Wei Yang 2025-11-14 5:06 ` Dev Jain 2025-11-14 8:55 ` David Hildenbrand (Red Hat) @ 2025-11-17 8:11 ` Baolin Wang 2025-11-17 17:25 ` Nico Pache 3 siblings, 0 replies; 13+ messages in thread From: Baolin Wang @ 2025-11-17 8:11 UTC (permalink / raw) To: Wei Yang, akpm, david, lorenzo.stoakes, ziy, Liam.Howlett, npache, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers Cc: linux-mm On 2025/11/14 11:00, Wei Yang wrote: > The current hugepage collapse scan results include two separate values, > SCAN_PMD_NONE and SCAN_PMD_NULL, which are handled identically by > the consuming code. > > To reduce confusion and improve long-term maintenance, this commit > merges these two functionally equivalent states into a single, clearer > identifier: SCAN_NO_PTE_TABLE > > Suggested-by: "David Hildenbrand (Red Hat)" <david@kernel.org> > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > --- Looks cleaner. Thanks. Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE 2025-11-14 3:00 ` [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE Wei Yang ` (2 preceding siblings ...) 2025-11-17 8:11 ` Baolin Wang @ 2025-11-17 17:25 ` Nico Pache 3 siblings, 0 replies; 13+ messages in thread From: Nico Pache @ 2025-11-17 17:25 UTC (permalink / raw) To: Wei Yang Cc: akpm, david, lorenzo.stoakes, ziy, baolin.wang, Liam.Howlett, ryan.roberts, dev.jain, baohua, lance.yang, rostedt, mhiramat, mathieu.desnoyers, linux-mm On Thu, Nov 13, 2025 at 8:00 PM Wei Yang <richard.weiyang@gmail.com> wrote: > > The current hugepage collapse scan results include two separate values, > SCAN_PMD_NONE and SCAN_PMD_NULL, which are handled identically by > the consuming code. > > To reduce confusion and improve long-term maintenance, this commit > merges these two functionally equivalent states into a single, clearer > identifier: SCAN_NO_PTE_TABLE Nice cleanup! Reviewed-by: Nico Pache <npache@redhat.com> > > Suggested-by: "David Hildenbrand (Red Hat)" <david@kernel.org> > Signed-off-by: Wei Yang <richard.weiyang@gmail.com> > --- > include/trace/events/huge_memory.h | 3 +-- > mm/khugepaged.c | 23 ++++++++++------------- > 2 files changed, 11 insertions(+), 15 deletions(-) > > diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h > index dd94d14a2427..4cde53b45a85 100644 > --- a/include/trace/events/huge_memory.h > +++ b/include/trace/events/huge_memory.h > @@ -10,8 +10,7 @@ > #define SCAN_STATUS \ > EM( SCAN_FAIL, "failed") \ > EM( SCAN_SUCCEED, "succeeded") \ > - EM( SCAN_PMD_NULL, "pmd_null") \ > - EM( SCAN_PMD_NONE, "pmd_none") \ > + EM( SCAN_NO_PTE_TABLE, "no_pte_table") \ > EM( SCAN_PMD_MAPPED, "page_pmd_mapped") \ > EM( SCAN_EXCEED_NONE_PTE, "exceed_none_pte") \ > EM( SCAN_EXCEED_SWAP_PTE, "exceed_swap_pte") \ > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 2ee5048b764e..40f9d5939aa5 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -30,8 +30,7 @@ > enum scan_result { > SCAN_FAIL, > SCAN_SUCCEED, > - SCAN_PMD_NULL, > - SCAN_PMD_NONE, > + SCAN_NO_PTE_TABLE, > SCAN_PMD_MAPPED, > SCAN_EXCEED_NONE_PTE, > SCAN_EXCEED_SWAP_PTE, > @@ -934,7 +933,7 @@ static inline int check_pmd_state(pmd_t *pmd) > pmd_t pmde = pmdp_get_lockless(pmd); > > if (pmd_none(pmde)) > - return SCAN_PMD_NONE; > + return SCAN_NO_PTE_TABLE; > > /* > * The folio may be under migration when khugepaged is trying to > @@ -944,11 +943,11 @@ static inline int check_pmd_state(pmd_t *pmd) > if (pmd_is_migration_entry(pmde)) > return SCAN_PMD_MAPPED; > if (!pmd_present(pmde)) > - return SCAN_PMD_NULL; > + return SCAN_NO_PTE_TABLE; > if (pmd_trans_huge(pmde)) > return SCAN_PMD_MAPPED; > if (pmd_bad(pmde)) > - return SCAN_PMD_NULL; > + return SCAN_NO_PTE_TABLE; > return SCAN_SUCCEED; > } > > @@ -958,7 +957,7 @@ static int find_pmd_or_thp_or_none(struct mm_struct *mm, > { > *pmd = mm_find_pmd(mm, address); > if (!*pmd) > - return SCAN_PMD_NULL; > + return SCAN_NO_PTE_TABLE; > > return check_pmd_state(*pmd); > } > @@ -1013,7 +1012,7 @@ static int __collapse_huge_page_swapin(struct mm_struct *mm, > pte = pte_offset_map_ro_nolock(mm, pmd, addr, &ptl); > if (!pte) { > mmap_read_unlock(mm); > - result = SCAN_PMD_NULL; > + result = SCAN_NO_PTE_TABLE; > goto out; > } > } > @@ -1187,7 +1186,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, > &compound_pagelist); > spin_unlock(pte_ptl); > } else { > - result = SCAN_PMD_NULL; > + result = SCAN_NO_PTE_TABLE; > } > > if (unlikely(result != SCAN_SUCCEED)) { > @@ -1270,7 +1269,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, > nodes_clear(cc->alloc_nmask); > pte = pte_offset_map_lock(mm, pmd, start_addr, &ptl); > if (!pte) { > - result = SCAN_PMD_NULL; > + result = SCAN_NO_PTE_TABLE; > goto out; > } > > @@ -1544,8 +1543,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, > switch (result) { > case SCAN_SUCCEED: > break; > - case SCAN_PMD_NULL: > - case SCAN_PMD_NONE: > + case SCAN_NO_PTE_TABLE: > /* > * All pte entries have been removed and pmd cleared. > * Skip all the pte checks and just update the pmd mapping. > @@ -2832,8 +2830,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, > mmap_read_unlock(mm); > goto handle_result; > /* Whitelisted set of results where continuing OK */ > - case SCAN_PMD_NULL: > - case SCAN_PMD_NONE: > + case SCAN_NO_PTE_TABLE: > case SCAN_PTE_NON_PRESENT: > case SCAN_PTE_UFFD_WP: > case SCAN_LACK_REFERENCED_PAGE: > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-11-17 17:25 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-11-14 3:00 [Patch v2 0/3] unify PMD scan results and remove redundant cleanup Wei Yang 2025-11-14 3:00 ` [Patch v2 1/3] mm/khugepaged: remove redundant clearing of struct collapse_control Wei Yang 2025-11-14 4:37 ` Dev Jain 2025-11-14 8:53 ` David Hildenbrand (Red Hat) 2025-11-17 8:04 ` Baolin Wang 2025-11-17 17:23 ` Nico Pache 2025-11-14 3:00 ` [Patch v2 2/3] mm/khugepaged: continue to collapse on SCAN_PMD_NONE Wei Yang 2025-11-14 8:54 ` David Hildenbrand (Red Hat) 2025-11-14 3:00 ` [Patch v2 3/3] mm/khugepaged: unify SCAN_PMD_NONE and SCAN_PMD_NULL into SCAN_NO_PTE_TABLE Wei Yang 2025-11-14 5:06 ` Dev Jain 2025-11-14 8:55 ` David Hildenbrand (Red Hat) 2025-11-17 8:11 ` Baolin Wang 2025-11-17 17:25 ` Nico Pache
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox