Re: [PATCH 2/2] mm: Drop all references of writable and SCAN_PAGE_RO

Lorenzo Stoakes
2025-09-03T20:35:46Z

On Wed, Sep 03, 2025 at 11:16:35AM +0530, Dev Jain wrote:
> Now that all actionable outcomes from checking pte_write() are gone,
> drop the related references.
>
> Signed-off-by: Dev Jain <dev.jain@arm.com>

LGTM so:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
> include/trace/events/huge_memory.h | 19 ++++++-------------
> mm/khugepaged.c | 14 +++-----------
> 2 files changed, 9 insertions(+), 24 deletions(-)
>
> diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h
> index 2305df6cb485..dd94d14a2427 100644
> --- a/include/trace/events/huge_memory.h
> +++ b/include/trace/events/huge_memory.h
> @@ -19,7 +19,6 @@
> EM( SCAN_PTE_NON_PRESENT, "pte_non_present") \
> EM( SCAN_PTE_UFFD_WP, "pte_uffd_wp") \
> EM( SCAN_PTE_MAPPED_HUGEPAGE, "pte_mapped_hugepage") \
> - EM( SCAN_PAGE_RO, "no_writable_page") \
> EM( SCAN_LACK_REFERENCED_PAGE, "lack_referenced_page") \
> EM( SCAN_PAGE_NULL, "page_null") \
> EM( SCAN_SCAN_ABORT, "scan_aborted") \
> @@ -55,15 +54,14 @@ SCAN_STATUS
>
> TRACE_EVENT(mm_khugepaged_scan_pmd,
>
> - TP_PROTO(struct mm_struct *mm, struct folio *folio, bool writable,
> + TP_PROTO(struct mm_struct *mm, struct folio *folio,
> int referenced, int none_or_zero, int status, int unmapped),
>
> - TP_ARGS(mm, folio, writable, referenced, none_or_zero, status, unmapped),
> + TP_ARGS(mm, folio, referenced, none_or_zero, status, unmapped),
>
> TP_STRUCT__entry(
> __field(struct mm_struct *, mm)
> __field(unsigned long, pfn)
> - __field(bool, writable)
> __field(int, referenced)
> __field(int, none_or_zero)
> __field(int, status)
> @@ -73,17 +71,15 @@ TRACE_EVENT(mm_khugepaged_scan_pmd,
> TP_fast_assign(
> __entry->mm = mm;
> __entry->pfn = folio ? folio_pfn(folio) : -1;
> - __entry->writable = writable;
> __entry->referenced = referenced;
> __entry->none_or_zero = none_or_zero;
> __entry->status = status;
> __entry->unmapped = unmapped;
> ),
>
> - TP_printk("mm=%p, scan_pfn=0x%lx, writable=%d, referenced=%d, none_or_zero=%d, status=%s, unmapped=%d",
> + TP_printk("mm=%p, scan_pfn=0x%lx, referenced=%d, none_or_zero=%d, status=%s, unmapped=%d",
> __entry->mm,
> __entry->pfn,
> - __entry->writable,
> __entry->referenced,
> __entry->none_or_zero,
> __print_symbolic(__entry->status, SCAN_STATUS),
> @@ -117,15 +113,14 @@ TRACE_EVENT(mm_collapse_huge_page,
> TRACE_EVENT(mm_collapse_huge_page_isolate,
>
> TP_PROTO(struct folio *folio, int none_or_zero,
> - int referenced, bool writable, int status),
> + int referenced, int status),
>
> - TP_ARGS(folio, none_or_zero, referenced, writable, status),
> + TP_ARGS(folio, none_or_zero, referenced, status),
>
> TP_STRUCT__entry(
> __field(unsigned long, pfn)
> __field(int, none_or_zero)
> __field(int, referenced)
> - __field(bool, writable)
> __field(int, status)
> ),
>
> @@ -133,15 +128,13 @@ TRACE_EVENT(mm_collapse_huge_page_isolate,
> __entry->pfn = folio ? folio_pfn(folio) : -1;
> __entry->none_or_zero = none_or_zero;
> __entry->referenced = referenced;
> - __entry->writable = writable;
> __entry->status = status;
> ),
>
> - TP_printk("scan_pfn=0x%lx, none_or_zero=%d, referenced=%d, writable=%d, status=%s",
> + TP_printk("scan_pfn=0x%lx, none_or_zero=%d, referenced=%d, status=%s",
> __entry->pfn,
> __entry->none_or_zero,
> __entry->referenced,
> - __entry->writable,
> __print_symbolic(__entry->status, SCAN_STATUS))
> );
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index a0f1df2a7ae6..af5f5c80fe4e 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -39,7 +39,6 @@ enum scan_result {
> SCAN_PTE_NON_PRESENT,
> SCAN_PTE_UFFD_WP,
> SCAN_PTE_MAPPED_HUGEPAGE,
> - SCAN_PAGE_RO,
> SCAN_LACK_REFERENCED_PAGE,
> SCAN_PAGE_NULL,
> SCAN_SCAN_ABORT,
> @@ -557,7 +556,6 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
> struct folio *folio = NULL;
> pte_t *_pte;
> int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0;
> - bool writable = false;
>
> for (_pte = pte; _pte < pte + HPAGE_PMD_NR;
> _pte++, address += PAGE_SIZE) {
> @@ -671,9 +669,6 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
> folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
> address)))
> referenced++;
> -
> - if (pte_write(pteval))
> - writable = true;
> }
>
> if (unlikely(cc->is_khugepaged && !referenced)) {
> @@ -681,13 +676,13 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
> } else {
> result = SCAN_SUCCEED;
> trace_mm_collapse_huge_page_isolate(folio, none_or_zero,
> - referenced, writable, result);
> + referenced, result);
> return result;
> }
> out:
> release_pte_pages(pte, _pte, compound_pagelist);
> trace_mm_collapse_huge_page_isolate(folio, none_or_zero,
> - referenced, writable, result);
> + referenced, result);
> return result;
> }
>
> @@ -1280,7 +1275,6 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> unsigned long _address;
> spinlock_t *ptl;
> int node = NUMA_NO_NODE, unmapped = 0;
> - bool writable = false;
>
> VM_BUG_ON(address & ~HPAGE_PMD_MASK);
>
> @@ -1344,8 +1338,6 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> result = SCAN_PTE_UFFD_WP;
> goto out_unmap;
> }
> - if (pte_write(pteval))
> - writable = true;
>
> page = vm_normal_page(vma, _address, pteval);
> if (unlikely(!page) || unlikely(is_zone_device_page(page))) {
> @@ -1435,7 +1427,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> *mmap_locked = false;
> }
> out:
> - trace_mm_khugepaged_scan_pmd(mm, folio, writable, referenced,
> + trace_mm_khugepaged_scan_pmd(mm, folio, referenced,
> none_or_zero, result, unmapped);
> return result;
> }
> --
> 2.30.2
>