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

From: Lance Yang

Date: Wed Apr 08 2026 - 23:13:09 EST



On Thu, Apr 09, 2026 at 09:43:22AM +0800, Ye Liu wrote:
>From: Ye Liu <liuye@xxxxxxxxxx>
>
>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