Re: [PATCH mm-new v6 2/5] mm: khugepaged: refine scan progress number
From: David Hildenbrand (arm)
Date: Wed Feb 04 2026 - 16:36:44 EST
[...]
+ if (cur_progress) {
+ if (_pte >= pte + HPAGE_PMD_NR)
+ *cur_progress = HPAGE_PMD_NR;
+ else
+ *cur_progress = _pte - pte + 1;
*cur_progress = max(_pte - pte + 1, HPAGE_PMD_NR);
?
It's still a bit nasty, though.
Can't we just add one at the beginning of the loop and let the compiler
optimize that? ;)
+ }I would really just keep it simple here and do a
pte_unmap_unlock(pte, ptl);
if (result == SCAN_SUCCEED) {
result = collapse_huge_page(mm, start_addr, referenced,
@@ -2286,8 +2301,9 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
return result;
}
-static enum scan_result hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr,
- struct file *file, pgoff_t start, struct collapse_control *cc)
+static enum scan_result hpage_collapse_scan_file(struct mm_struct *mm,
+ unsigned long addr, struct file *file, pgoff_t start,
+ unsigned int *cur_progress, struct collapse_control *cc)
{
struct folio *folio = NULL;
struct address_space *mapping = file->f_mapping;
@@ -2376,6 +2392,8 @@ static enum scan_result hpage_collapse_scan_file(struct mm_struct *mm, unsigned
cond_resched_rcu();
}
}
+ if (cur_progress)
+ *cur_progress = max(xas.xa_index - start, 1UL);
*cur_progress = HPAGE_PMD_NR;
This stuff is hard to reason about, so I would just leave the file case essentially unchanged.
IIRC, it would not affect the numbers you report in the patch description?
--
Cheers,
David