Commit fa475e51 authored by Bob Liu's avatar Bob Liu Committed by Linus Torvalds

thp: introduce hugepage_vma_check()

Multiple places do the same check.
Signed-off-by: default avatarBob Liu <lliubbo@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Minchan Kim <minchan.kim@gmail.com>
Cc: Ni zhan Chen <nizhan.chen@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6219049a
...@@ -1894,6 +1894,20 @@ static struct page ...@@ -1894,6 +1894,20 @@ static struct page
} }
#endif #endif
static bool hugepage_vma_check(struct vm_area_struct *vma)
{
if ((!(vma->vm_flags & VM_HUGEPAGE) && !khugepaged_always()) ||
(vma->vm_flags & VM_NOHUGEPAGE))
return false;
if (!vma->anon_vma || vma->vm_ops)
return false;
if (is_vma_temporary_stack(vma))
return false;
VM_BUG_ON(vma->vm_flags & VM_NO_THP);
return true;
}
static void collapse_huge_page(struct mm_struct *mm, static void collapse_huge_page(struct mm_struct *mm,
unsigned long address, unsigned long address,
struct page **hpage, struct page **hpage,
...@@ -1934,17 +1948,8 @@ static void collapse_huge_page(struct mm_struct *mm, ...@@ -1934,17 +1948,8 @@ static void collapse_huge_page(struct mm_struct *mm,
hend = vma->vm_end & HPAGE_PMD_MASK; hend = vma->vm_end & HPAGE_PMD_MASK;
if (address < hstart || address + HPAGE_PMD_SIZE > hend) if (address < hstart || address + HPAGE_PMD_SIZE > hend)
goto out; goto out;
if (!hugepage_vma_check(vma))
if ((!(vma->vm_flags & VM_HUGEPAGE) && !khugepaged_always()) ||
(vma->vm_flags & VM_NOHUGEPAGE))
goto out;
if (!vma->anon_vma || vma->vm_ops)
goto out;
if (is_vma_temporary_stack(vma))
goto out; goto out;
VM_BUG_ON(vma->vm_flags & VM_NO_THP);
pmd = mm_find_pmd(mm, address); pmd = mm_find_pmd(mm, address);
if (!pmd) if (!pmd)
goto out; goto out;
...@@ -2152,20 +2157,11 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, ...@@ -2152,20 +2157,11 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages,
progress++; progress++;
break; break;
} }
if (!hugepage_vma_check(vma)) {
if ((!(vma->vm_flags & VM_HUGEPAGE) && skip:
!khugepaged_always()) ||
(vma->vm_flags & VM_NOHUGEPAGE)) {
skip:
progress++; progress++;
continue; continue;
} }
if (!vma->anon_vma || vma->vm_ops)
goto skip;
if (is_vma_temporary_stack(vma))
goto skip;
VM_BUG_ON(vma->vm_flags & VM_NO_THP);
hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
hend = vma->vm_end & HPAGE_PMD_MASK; hend = vma->vm_end & HPAGE_PMD_MASK;
if (hstart >= hend) if (hstart >= hend)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment