On 2026/5/18 19:55, Usama Arif wrote:
[...]
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 979885694351..f0e29d5c7b1f 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1068,21 +1068,26 @@ static enum scan_result 
__collapse_huge_page_swapin(struct mm_struct *mm,
  }
static enum scan_result alloc_charge_folio(struct folio **foliop, struct mm_struct *mm,
-               struct collapse_control *cc)
+               struct collapse_control *cc, unsigned int order)
  {
        gfp_t gfp = (cc->is_khugepaged ? alloc_hugepage_khugepaged_gfpmask() :
                     GFP_TRANSHUGE);
        int node = collapse_find_target_node(cc);
        struct folio *folio;
- folio = __folio_alloc(gfp, HPAGE_PMD_ORDER, node, &cc->alloc_nmask);
+       folio = __folio_alloc(gfp, order, node, &cc->alloc_nmask);
        if (!folio) {
                *foliop = NULL;
-               count_vm_event(THP_COLLAPSE_ALLOC_FAILED);
+               if (is_pmd_order(order))
+                       count_vm_event(THP_COLLAPSE_ALLOC_FAILED);
+               count_mthp_stat(order, MTHP_STAT_COLLAPSE_ALLOC_FAILED);
                return SCAN_ALLOC_HUGE_PAGE_FAIL;
        }
- count_vm_event(THP_COLLAPSE_ALLOC);
+       if (is_pmd_order(order))
+               count_vm_event(THP_COLLAPSE_ALLOC);
+       count_mthp_stat(order, MTHP_STAT_COLLAPSE_ALLOC);
+

The vmstat THP_COLLAPSE_ALLOC counter is pmd order only.
But after this we have

        count_memcg_folio_events(folio, THP_COLLAPSE_ALLOC, 1);

which is not being guarded with is_pmd_order().

Good catch!


I think we want this to be pmd order only as well so that
the meaning of the vmstat and cgroup counter remains the same?

Agreed. THP_COLLAPSE_ALLOC should remain PMD order only for
vmstat and memcg events.

So this should be guarded with is_pmd_order() as well :)

Cheers, Lance

Reply via email to