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

Lorenzo Stoakes
2026-04-09T07:28:25Z

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.
>
> No functional change intended.
>
> Signed-off-by: Ye Liu <liuye@kylinos.cn>

LGTM, so:

Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>

>
> Changes in v2:
> - Switch to ALIGN()/ALIGN_DOWN() per David's suggestion.
> - Also convert collapse_scan_mm_slot() to keep PMD alignment helpers
> consistent within khugepaged.
> - Update the changelog accordingly.
> - Link to v1:https://lore.kernel.org/all/20260408093534.2373007-1-ye.liu@linux.dev/
> ---
> mm/khugepaged.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 1e2bff40d014..1b1d1a881ec3 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2518,8 +2518,8 @@ static void collapse_scan_mm_slot(unsigned int progress_max,
> cc->progress++;
> continue;
> }
> - hstart = round_up(vma->vm_start, HPAGE_PMD_SIZE);
> - hend = round_down(vma->vm_end, HPAGE_PMD_SIZE);
> + hstart = ALIGN(vma->vm_start, HPAGE_PMD_SIZE);
> + hend = ALIGN_DOWN(vma->vm_end, HPAGE_PMD_SIZE);
> if (khugepaged_scan.address > hend) {
> cc->progress++;
> continue;
> @@ -2835,8 +2835,8 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
> mmgrab(mm);
> lru_add_drain_all();
>
> - hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
> - hend = end & HPAGE_PMD_MASK;
> + hstart = ALIGN(start, HPAGE_PMD_SIZE);
> + hend = ALIGN_DOWN(end, HPAGE_PMD_SIZE);
>
> for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
> enum scan_result result = SCAN_FAIL;
> --
> 2.43.0
>