Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment

Lance Yang
2026-04-09T03:13:01Z

On Thu, Apr 09, 2026 at 09:43:22AM +0800, Ye Liu wrote:
>From: Ye Liu <liuye@kylinos.cn>
>
>PMD alignment in khugepaged is currently implemented using a mix of
>rounding helpers and open-coded bitmask operations.
>
>Use ALIGN() and ALIGN_DOWN() consistently for PMD-sized address range
>alignment, matching the preferred style for address and size handling.

One more spot in madvise_collapse():

hend = min(hend, vma->vm_end & HPAGE_PMD_MASK);

Maybe switch that one to ALIGN_DOWN() as well.

And there is also in try_collapse_pte_mapped_thp():

unsigned long haddr = addr & HPAGE_PMD_MASK;

Just a thought :)
Lance