From: "Kiryl Shutsemau (Meta)" <[email protected]> collapse_single_pmd() bumps khugepaged_pages_collapsed for its caller, and tests cc->is_khugepaged to know whether it should: the counter belongs to the daemon, and MADV_COLLAPSE must not touch it. So the one thing the shared path still asks about its caller is bookkeeping, not policy.
Count in khugepaged's own walk instead, at the call it already makes. The question goes away, and cc->is_khugepaged with it -- nothing else read it. current_is_khugepaged() is a different test, on the task rather than on the request. Preparation for moving the dispatcher into collapse.c, from where a static in khugepaged.c is out of reach. Assisted-by: Claude-Code:claude-opus-5 Signed-off-by: Kiryl Shutsemau (Meta) <[email protected]> --- mm/collapse.h | 2 -- mm/khugepaged.c | 9 +++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/collapse.h b/mm/collapse.h index 94c11051f06a..11f51c6ea444 100644 --- a/mm/collapse.h +++ b/mm/collapse.h @@ -114,8 +114,6 @@ struct collapse_policy { struct collapse_control { struct collapse_policy policy; - bool is_khugepaged; - /* Num pages scanned per node */ u32 node_load[MAX_NUMNODES]; diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 8c770e251c22..907ed1131460 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -458,9 +458,7 @@ static void khugepaged_alloc_sleep(void) remove_wait_queue(&khugepaged_wait, &wait); } -static struct collapse_control khugepaged_collapse_control = { - .is_khugepaged = true, -}; +static struct collapse_control khugepaged_collapse_control; #define khugepaged_defrag() \ (transparent_hugepage_flags & \ @@ -1639,8 +1637,6 @@ static enum scan_result collapse_single_pmd(unsigned long addr, mmap_read_unlock(mm); } end: - if (cc->is_khugepaged && result == SCAN_SUCCEED) - ++khugepaged_pages_collapsed; return result; } @@ -1731,6 +1727,8 @@ static void collapse_scan_mm_slot(unsigned int progress_max, *result = collapse_single_pmd(khugepaged_scan.address, range_end, vma, &lock_dropped, cc); + if (*result == SCAN_SUCCEED) + ++khugepaged_pages_collapsed; /* move to next address */ khugepaged_scan.address = range_end; if (lock_dropped) @@ -2039,7 +2037,6 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, cc = kmalloc_obj(*cc); if (!cc) return -ENOMEM; - cc->is_khugepaged = false; collapse_policy_forced(&cc->policy); cc->progress = 0; err = collapse_control_init(cc); -- 2.54.0
