Re: [PATCH v4 10/12] khugepaged: improve tracepoints for mTHP orders

Baolin Wang
2025-04-24T07:51:54Z

On 2025/4/17 08:02, Nico Pache wrote:
> Add the order to the tracepoints to give better insight into what order
> is being operated at for khugepaged.
>
> Signed-off-by: Nico Pache <npache@redhat.com>

LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

> ---
> include/trace/events/huge_memory.h | 34 +++++++++++++++++++-----------
> mm/khugepaged.c | 10 +++++----
> 2 files changed, 28 insertions(+), 16 deletions(-)
>
> diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h
> index 9d5c00b0285c..ea2fe20a39f5 100644
> --- a/include/trace/events/huge_memory.h
> +++ b/include/trace/events/huge_memory.h
> @@ -92,34 +92,37 @@ TRACE_EVENT(mm_khugepaged_scan_pmd,
>
> TRACE_EVENT(mm_collapse_huge_page,
>
> - TP_PROTO(struct mm_struct *mm, int isolated, int status),
> + TP_PROTO(struct mm_struct *mm, int isolated, int status, int order),
>
> - TP_ARGS(mm, isolated, status),
> + TP_ARGS(mm, isolated, status, order),
>
> TP_STRUCT__entry(
> __field(struct mm_struct *, mm)
> __field(int, isolated)
> __field(int, status)
> + __field(int, order)
> ),
>
> TP_fast_assign(
> __entry->mm = mm;
> __entry->isolated = isolated;
> __entry->status = status;
> + __entry->order = order;
> ),
>
> - TP_printk("mm=%p, isolated=%d, status=%s",
> + TP_printk("mm=%p, isolated=%d, status=%s order=%d",
> __entry->mm,
> __entry->isolated,
> - __print_symbolic(__entry->status, SCAN_STATUS))
> + __print_symbolic(__entry->status, SCAN_STATUS),
> + __entry->order)
> );
>
> TRACE_EVENT(mm_collapse_huge_page_isolate,
>
> TP_PROTO(struct page *page, int none_or_zero,
> - int referenced, bool writable, int status),
> + int referenced, bool writable, int status, int order),
>
> - TP_ARGS(page, none_or_zero, referenced, writable, status),
> + TP_ARGS(page, none_or_zero, referenced, writable, status, order),
>
> TP_STRUCT__entry(
> __field(unsigned long, pfn)
> @@ -127,6 +130,7 @@ TRACE_EVENT(mm_collapse_huge_page_isolate,
> __field(int, referenced)
> __field(bool, writable)
> __field(int, status)
> + __field(int, order)
> ),
>
> TP_fast_assign(
> @@ -135,27 +139,31 @@ TRACE_EVENT(mm_collapse_huge_page_isolate,
> __entry->referenced = referenced;
> __entry->writable = writable;
> __entry->status = status;
> + __entry->order = order;
> ),
>
> - 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, writable=%d, status=%s order=%d",
> __entry->pfn,
> __entry->none_or_zero,
> __entry->referenced,
> __entry->writable,
> - __print_symbolic(__entry->status, SCAN_STATUS))
> + __print_symbolic(__entry->status, SCAN_STATUS),
> + __entry->order)
> );
>
> TRACE_EVENT(mm_collapse_huge_page_swapin,
>
> - TP_PROTO(struct mm_struct *mm, int swapped_in, int referenced, int ret),
> + TP_PROTO(struct mm_struct *mm, int swapped_in, int referenced, int ret,
> + int order),
>
> - TP_ARGS(mm, swapped_in, referenced, ret),
> + TP_ARGS(mm, swapped_in, referenced, ret, order),
>
> TP_STRUCT__entry(
> __field(struct mm_struct *, mm)
> __field(int, swapped_in)
> __field(int, referenced)
> __field(int, ret)
> + __field(int, order)
> ),
>
> TP_fast_assign(
> @@ -163,13 +171,15 @@ TRACE_EVENT(mm_collapse_huge_page_swapin,
> __entry->swapped_in = swapped_in;
> __entry->referenced = referenced;
> __entry->ret = ret;
> + __entry->order = order;
> ),
>
> - TP_printk("mm=%p, swapped_in=%d, referenced=%d, ret=%d",
> + TP_printk("mm=%p, swapped_in=%d, referenced=%d, ret=%d, order=%d",
> __entry->mm,
> __entry->swapped_in,
> __entry->referenced,
> - __entry->ret)
> + __entry->ret,
> + __entry->order)
> );
>
> TRACE_EVENT(mm_khugepaged_scan_file,
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 738dd9c5751d..67da0950b833 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -721,13 +721,14 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
> } else {
> result = SCAN_SUCCEED;
> trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero,
> - referenced, writable, result);
> + referenced, writable, result,
> + order);
> return result;
> }
> out:
> release_pte_pages(pte, _pte, compound_pagelist);
> trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero,
> - referenced, writable, result);
> + referenced, writable, result, order);
> return result;
> }
>
> @@ -1097,7 +1098,8 @@ static int __collapse_huge_page_swapin(struct mm_struct *mm,
>
> result = SCAN_SUCCEED;
> out:
> - trace_mm_collapse_huge_page_swapin(mm, swapped_in, referenced, result);
> + trace_mm_collapse_huge_page_swapin(mm, swapped_in, referenced, result,
> + order);
> return result;
> }
>
> @@ -1318,7 +1320,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address,
> *mmap_locked = false;
> if (folio)
> folio_put(folio);
> - trace_mm_collapse_huge_page(mm, result == SCAN_SUCCEED, result);
> + trace_mm_collapse_huge_page(mm, result == SCAN_SUCCEED, result, order);
> return result;
> }
>