diff mbox series

[mm-unstable,3/4] mm/khugepaged: delay computation of hpage boundaries until use

Message ID 20220720140603.1958773-4-zokeefe@google.com (mailing list archive)
State New
Headers show
Series mm: fixes for userspace hugepage collapse, v7 | expand

Commit Message

Zach O'Keefe July 20, 2022, 2:06 p.m. UTC
Only compute hstart/hend once we've passed all checks that would
cause early return in madvise_collapse().

Fixes: c9d968ffd9ba ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse")
Signed-off-by: Zach O'Keefe <zokeefe@google.com>
---
 mm/khugepaged.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Yang Shi July 20, 2022, 5:30 p.m. UTC | #1
On Wed, Jul 20, 2022 at 7:06 AM Zach O'Keefe <zokeefe@google.com> wrote:
>
> Only compute hstart/hend once we've passed all checks that would
> cause early return in madvise_collapse().
>
> Fixes: c9d968ffd9ba ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse")
> Signed-off-by: Zach O'Keefe <zokeefe@google.com>

Reviewed-by: Yang Shi <shy828301@gmail.com>


> ---
>  mm/khugepaged.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 290422577172..70e9d9950415 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2417,9 +2417,6 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
>         if (!vma->anon_vma || !vma_is_anonymous(vma))
>                 return -EINVAL;
>
> -       hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
> -       hend = end & HPAGE_PMD_MASK;
> -
>         if (!hugepage_vma_check(vma, vma->vm_flags, false, false, false))
>                 return -EINVAL;
>
> @@ -2432,6 +2429,9 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
>         mmgrab(mm);
>         lru_add_drain_all();
>
> +       hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
> +       hend = end & HPAGE_PMD_MASK;
> +
>         for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
>                 int result = SCAN_FAIL;
>
> --
> 2.37.0.170.g444d1eabd0-goog
>
David Rientjes July 21, 2022, 12:43 a.m. UTC | #2
On Wed, 20 Jul 2022, Zach O'Keefe wrote:

> Only compute hstart/hend once we've passed all checks that would
> cause early return in madvise_collapse().
> 
> Fixes: c9d968ffd9ba ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse")
> Signed-off-by: Zach O'Keefe <zokeefe@google.com>

Acked-by: David Rientjes <rientjes@google.com>
diff mbox series

Patch

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 290422577172..70e9d9950415 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2417,9 +2417,6 @@  int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
 	if (!vma->anon_vma || !vma_is_anonymous(vma))
 		return -EINVAL;
 
-	hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
-	hend = end & HPAGE_PMD_MASK;
-
 	if (!hugepage_vma_check(vma, vma->vm_flags, false, false, false))
 		return -EINVAL;
 
@@ -2432,6 +2429,9 @@  int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
 	mmgrab(mm);
 	lru_add_drain_all();
 
+	hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
+	hend = end & HPAGE_PMD_MASK;
+
 	for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
 		int result = SCAN_FAIL;