2022-06-15 17:34:39

by Yang Shi

[permalink] [raw]
Subject: [v4 PATCH 3/7] mm: khugepaged: better comments for anon vma check in hugepage_vma_revalidate

The hugepage_vma_revalidate() needs to check if the vma is still
anonymous vma or not since the address may be unmapped then remapped to
file before khugepaged reaquired the mmap_lock.

The old comment is not quite helpful, elaborate this with better
comment.

Signed-off-by: Yang Shi <[email protected]>
---
mm/khugepaged.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index db0b334a7d1f..5baa394e34c8 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -960,7 +960,13 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
return SCAN_ADDRESS_RANGE;
if (!hugepage_vma_check(vma, vma->vm_flags))
return SCAN_VMA_CHECK;
- /* Anon VMA expected */
+ /*
+ * Anon VMA expected, the address may be unmapped then
+ * remapped to file after khugepaged reaquired the mmap_lock.
+ *
+ * hugepage_vma_check may return true for qualified file
+ * vmas.
+ */
if (!vma->anon_vma || !vma_is_anonymous(vma))
return SCAN_VMA_CHECK;
return 0;
--
2.26.3


2022-06-16 00:36:28

by Zach O'Keefe

[permalink] [raw]
Subject: Re: [v4 PATCH 3/7] mm: khugepaged: better comments for anon vma check in hugepage_vma_revalidate

On 15 Jun 10:29, Yang Shi wrote:
> The hugepage_vma_revalidate() needs to check if the vma is still
> anonymous vma or not since the address may be unmapped then remapped to
> file before khugepaged reaquired the mmap_lock.
>
> The old comment is not quite helpful, elaborate this with better
> comment.
>
> Signed-off-by: Yang Shi <[email protected]>
> ---
> mm/khugepaged.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index db0b334a7d1f..5baa394e34c8 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -960,7 +960,13 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
> return SCAN_ADDRESS_RANGE;
> if (!hugepage_vma_check(vma, vma->vm_flags))
> return SCAN_VMA_CHECK;
> - /* Anon VMA expected */
> + /*
> + * Anon VMA expected, the address may be unmapped then
> + * remapped to file after khugepaged reaquired the mmap_lock.
> + *
> + * hugepage_vma_check may return true for qualified file
> + * vmas.
> + */
> if (!vma->anon_vma || !vma_is_anonymous(vma))
> return SCAN_VMA_CHECK;
> return 0;
> --
> 2.26.3
>

Reviewed-by: Zach O'Keefe <[email protected]>