mm/khugepaged: use ALIGN helpers for PMD alignment
Subsystems (2)
PATCH v2 1/1 mm/khugepaged: use ALIGN helpers for PMD alignment
From: Ye Liu <[email protected]>
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.
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/[email protected]/
--- mm/khugepaged.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/khugepaged.c +4 -4
@@ -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 ;
Signature · 1 line
2.43.0
Quoted 18 lines · Ye Liu
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Use
ALIGN()andALIGN_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 <[email protected]>Changes in v2:
- Switch to ALIGN()/ALIGN_DOWN() per David's suggestion.
- Also convertcollapse_scan_mm_slot()to keep PMD alignment helpers consistent within khugepaged.
- Update the changelog accordingly.
- Link to v1:https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
--- mm/khugepaged.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
LGTM.
Best Regards,
Yan, Zi
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Quoted 6 lines
Use
ALIGN()andALIGN_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 <[email protected]>
Best Regards
Barry
Lance Yang
reviewerQuoted 7 lines · Ye Liu
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Use
ALIGN()andALIGN_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
Quoted 7 lines · Lance Yang
Quoted 5 lines · Ye Liu
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Quoted 8 lines
Quoted 2 lines
Use
ALIGN()andALIGN_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.
Quoted 4 lines
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.
Quoted 3 lines
Just a thought :)
Lance
Cheers, Lorenzo
Quoted 11 lines · Ye Liu
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Use
ALIGN()andALIGN_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 <[email protected]>
LGTM, so:
Quoted 40 lines
Changes in v2:
- Switch to ALIGN()/ALIGN_DOWN() per David's suggestion.
- Also convertcollapse_scan_mm_slot()to keep PMD alignment helpers consistent within khugepaged.
- Update the changelog accordingly.
- Link to v1:https://lore.kernel.org/all/[email protected]/--- mm/khugepaged.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)mm/khugepaged.c +4
-5@@ -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
Quoted 12 lines · Ye Liu
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Use
ALIGN()andALIGN_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 <[email protected]>
Quoted 7 lines
Changes in v2:
- Switch to ALIGN()/ALIGN_DOWN() per David's suggestion.
- Also convertcollapse_scan_mm_slot()to keep PMD alignment helpers consistent within khugepaged.
- Update the changelog accordingly.
- Link to v1:https://lore.kernel.org/all/[email protected]/
---
Signature · 3 lines
Cheers, David
Quoted 12 lines · Ye Liu
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Use
ALIGN()andALIGN_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 <[email protected]>
Quoted 7 lines
Changes in v2:
- Switch to ALIGN()/ALIGN_DOWN() per David's suggestion.
- Also convertcollapse_scan_mm_slot()to keep PMD alignment helpers consistent within khugepaged.
- Update the changelog accordingly.
- Link to v1:https://lore.kernel.org/all/[email protected]/
---
Quoted 11 lines · On Thu, 9 Apr 2026 09:43:22 +0800 Ye Liu <[email protected]> wrote:
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Use
ALIGN()andALIGN_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 <[email protected]>
Quoted 7 lines
Changes in v2:
- Switch to ALIGN()/ALIGN_DOWN() per David's suggestion.
- Also convertcollapse_scan_mm_slot()to keep PMD alignment helpers consistent within khugepaged.
- Update the changelog accordingly.
- Link to v1:https://lore.kernel.org/all/[email protected]/
Nit. Changelog should go to the commentary area [1].
[1] https://docs.kernel.org/process/submitting-patches.html#commentary
Thanks,
SJ
[...]
Quoted 24 lines · SeongJae Park
Quoted 11 lines · On Thu, 9 Apr 2026 09:43:22 +0800 Ye Liu <[email protected]> wrote:
From: Ye Liu <[email protected]>
PMD alignment in khugepaged is currently implemented using a mix of rounding helpers and open-coded bitmask operations.
Use
ALIGN()andALIGN_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 <[email protected]>Reviewed-by SeongJae Park <[email protected]>Quoted 7 lines
Changes in v2:
- Switch to ALIGN()/ALIGN_DOWN() per David's suggestion.
- Also convertcollapse_scan_mm_slot()to keep PMD alignment helpers consistent within khugepaged.
- Update the changelog accordingly.
- Link to v1:https://lore.kernel.org/all/[email protected]/
Quoted 5 lines
Nit. Changelog should go to the commentary area [1].
[1] https://docs.kernel.org/process/submitting-patches.html#commentary
Hi SJ,
Thanks for the review, the Reviewed-by, and the helpful note.
Got it. I'll keep the changelog in the commentary area for future revisions.
Quoted 4 lines
Thanks,
SJ[...]
Signature · 2 lines
Thanks, Ye Liu