* Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
2026-04-09 1:43 [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment Ye Liu
@ 2026-04-09 1:53 ` Zi Yan
2026-04-09 2:27 ` Barry Song
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Zi Yan @ 2026-04-09 1:53 UTC (permalink / raw)
To: Ye Liu
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Ye Liu,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, linux-mm, linux-kernel
On 8 Apr 2026, at 21:43, 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>
>
> 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(-)
>
LGTM.
Reviewed-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
2026-04-09 1:43 [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment Ye Liu
2026-04-09 1:53 ` Zi Yan
@ 2026-04-09 2:27 ` Barry Song
2026-04-09 3:12 ` Lance Yang
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Barry Song @ 2026-04-09 2:27 UTC (permalink / raw)
To: Ye Liu
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Ye Liu, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, linux-mm, linux-kernel
On Thu, Apr 9, 2026 at 9:43 AM Ye Liu <ye.liu@linux.dev> 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>
Reviewed-by: Barry Song <baohua@kernel.org>
Best Regards
Barry
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
2026-04-09 1:43 [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment Ye Liu
2026-04-09 1:53 ` Zi Yan
2026-04-09 2:27 ` Barry Song
@ 2026-04-09 3:12 ` Lance Yang
2026-04-09 7:36 ` Lorenzo Stoakes
2026-04-09 7:28 ` Lorenzo Stoakes
` (2 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Lance Yang @ 2026-04-09 3:12 UTC (permalink / raw)
To: ye.liu
Cc: akpm, david, ljs, liuye, ziy, baolin.wang, Liam.Howlett, npache,
ryan.roberts, dev.jain, baohua, lance.yang, linux-mm,
linux-kernel
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
2026-04-09 3:12 ` Lance Yang
@ 2026-04-09 7:36 ` Lorenzo Stoakes
0 siblings, 0 replies; 8+ messages in thread
From: Lorenzo Stoakes @ 2026-04-09 7:36 UTC (permalink / raw)
To: Lance Yang
Cc: ye.liu, akpm, david, liuye, ziy, baolin.wang, Liam.Howlett,
npache, ryan.roberts, dev.jain, baohua, linux-mm, linux-kernel
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
2026-04-09 1:43 [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment Ye Liu
` (2 preceding siblings ...)
2026-04-09 3:12 ` Lance Yang
@ 2026-04-09 7:28 ` Lorenzo Stoakes
2026-04-09 7:54 ` David Hildenbrand (Arm)
2026-04-09 13:04 ` Dev Jain
5 siblings, 0 replies; 8+ messages in thread
From: Lorenzo Stoakes @ 2026-04-09 7:28 UTC (permalink / raw)
To: Ye Liu
Cc: Andrew Morton, David Hildenbrand, Ye Liu, Zi Yan, Baolin Wang,
Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, linux-mm, linux-kernel
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
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
2026-04-09 1:43 [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment Ye Liu
` (3 preceding siblings ...)
2026-04-09 7:28 ` Lorenzo Stoakes
@ 2026-04-09 7:54 ` David Hildenbrand (Arm)
2026-04-09 13:04 ` Dev Jain
5 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-04-09 7:54 UTC (permalink / raw)
To: Ye Liu, Andrew Morton, Lorenzo Stoakes
Cc: Ye Liu, Zi Yan, Baolin Wang, Liam R. Howlett, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, linux-mm,
linux-kernel
On 4/9/26 03:43, 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>
>
> 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/
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
2026-04-09 1:43 [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment Ye Liu
` (4 preceding siblings ...)
2026-04-09 7:54 ` David Hildenbrand (Arm)
@ 2026-04-09 13:04 ` Dev Jain
5 siblings, 0 replies; 8+ messages in thread
From: Dev Jain @ 2026-04-09 13:04 UTC (permalink / raw)
To: Ye Liu, Andrew Morton, David Hildenbrand, Lorenzo Stoakes
Cc: Ye Liu, Zi Yan, Baolin Wang, Liam R. Howlett, Nico Pache,
Ryan Roberts, Barry Song, Lance Yang, linux-mm, linux-kernel
On 09/04/26 7:13 am, 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>
>
> 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/
> ---
Reviewed-by: Dev Jain <dev.jain@arm.com>
^ permalink raw reply [flat|nested] 8+ messages in thread