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

Lorenzo Stoakes
2026-04-09T07:36:09Z

On Thu, Apr 09, 2026 at 11:12:42AM +0800, Lance Yang wrote:
>
> 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.

Sorry to bikeshed but I'm not sure if:

hend = min(hend, ALIGN_DOWN(vma->vm_end, HPAGE_PMD_SIZE));

Really adds any clarity there, possibly better to just leave that one as-is.

>
> And there is also in try_collapse_pte_mapped_thp():
>
> unsigned long haddr = addr & HPAGE_PMD_MASK;

This one's fine though, be good to also const-ify haddr and end there.

>
> Just a thought :)
> Lance

Cheers, Lorenzo