Re: [PATCH] mm/THP: use hugepage_vma_check() in khugepaged_enter_vma_merge()

From: Rik van Riel
Date: Mon May 21 2018 - 14:58:31 EST


On Mon, 2018-05-21 at 12:38 -0700, Song Liu wrote:

> This patch fixes these problems by reusing hugepage_vma_check() in
> khugepaged_enter_vma_merge().

Lets take a look at this in more detail. This effectively
adds the following conditions to khugepaged_enter_vma_merge:
- fail if MMF_DISABLE_THP bit is set in mm->flags (good)
- allow if merging a tmpfs file and THP tmpfs is enabled (good)
- disallow if is_vma_temporary_stack (good)
- otherwise, allow if !VM_NO_KHUGEPAGED flag (good)

Looks like this covers all the conditions I can think
of, and if I missed any, chances are that condition
should be added to hugepage_vma_check()...

> Signed-off-by: Song Liu <songliubraving@xxxxxx>

Reviewed-by: Rik van Riel <riel@xxxxxxxxxxx>

> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index d7b2a4b..e50c2bd 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -430,18 +430,14 @@ int __khugepaged_enter(struct mm_struct *mm)
> return 0;
> }
>
> +static bool hugepage_vma_check(struct vm_area_struct *vma);
> +
> int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
> unsigned long vm_flags)
> {
> unsigned long hstart, hend;
> - if (!vma->anon_vma)
> - /*
> - * Not yet faulted in so we will register later in
> the
> - * page fault if needed.
> - */
> - return 0;
> - if (vma->vm_ops || (vm_flags & VM_NO_KHUGEPAGED))
> - /* khugepaged not yet working on file or special
> mappings */
> +
> + if (!hugepage_vma_check(vma))
> return 0;
> hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
> hend = vma->vm_end & HPAGE_PMD_MASK;
--
All Rights Reversed.

Attachment: signature.asc
Description: This is a digitally signed message part