linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm/khugepaged: use ALIGN helpers for PMD alignment
@ 2026-04-09  1:43 Ye Liu
  2026-04-09  1:53 ` Zi Yan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ye Liu @ 2026-04-09  1:43 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, 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

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(-)

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] 4+ 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
  2 siblings, 0 replies; 4+ 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] 4+ 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
  2 siblings, 0 replies; 4+ 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] 4+ 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
  2 siblings, 0 replies; 4+ 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] 4+ messages in thread

end of thread, other threads:[~2026-04-09  3:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox