Commit 344aa35c authored by Bob Liu's avatar Bob Liu Committed by Linus Torvalds

thp: clean up __collapse_huge_page_isolate

There are duplicated places using release_pte_pages().
And release_all_pte_pages() can be removed.
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>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d84da3f9
...@@ -1701,64 +1701,49 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte) ...@@ -1701,64 +1701,49 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte)
} }
} }
static void release_all_pte_pages(pte_t *pte)
{
release_pte_pages(pte, pte + HPAGE_PMD_NR);
}
static int __collapse_huge_page_isolate(struct vm_area_struct *vma, static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
unsigned long address, unsigned long address,
pte_t *pte) pte_t *pte)
{ {
struct page *page; struct page *page;
pte_t *_pte; pte_t *_pte;
int referenced = 0, isolated = 0, none = 0; int referenced = 0, none = 0;
for (_pte = pte; _pte < pte+HPAGE_PMD_NR; for (_pte = pte; _pte < pte+HPAGE_PMD_NR;
_pte++, address += PAGE_SIZE) { _pte++, address += PAGE_SIZE) {
pte_t pteval = *_pte; pte_t pteval = *_pte;
if (pte_none(pteval)) { if (pte_none(pteval)) {
if (++none <= khugepaged_max_ptes_none) if (++none <= khugepaged_max_ptes_none)
continue; continue;
else { else
release_pte_pages(pte, _pte);
goto out; goto out;
} }
} if (!pte_present(pteval) || !pte_write(pteval))
if (!pte_present(pteval) || !pte_write(pteval)) {
release_pte_pages(pte, _pte);
goto out; goto out;
}
page = vm_normal_page(vma, address, pteval); page = vm_normal_page(vma, address, pteval);
if (unlikely(!page)) { if (unlikely(!page))
release_pte_pages(pte, _pte);
goto out; goto out;
}
VM_BUG_ON(PageCompound(page)); VM_BUG_ON(PageCompound(page));
BUG_ON(!PageAnon(page)); BUG_ON(!PageAnon(page));
VM_BUG_ON(!PageSwapBacked(page)); VM_BUG_ON(!PageSwapBacked(page));
/* cannot use mapcount: can't collapse if there's a gup pin */ /* cannot use mapcount: can't collapse if there's a gup pin */
if (page_count(page) != 1) { if (page_count(page) != 1)
release_pte_pages(pte, _pte);
goto out; goto out;
}
/* /*
* We can do it before isolate_lru_page because the * We can do it before isolate_lru_page because the
* page can't be freed from under us. NOTE: PG_lock * page can't be freed from under us. NOTE: PG_lock
* is needed to serialize against split_huge_page * is needed to serialize against split_huge_page
* when invoked from the VM. * when invoked from the VM.
*/ */
if (!trylock_page(page)) { if (!trylock_page(page))
release_pte_pages(pte, _pte);
goto out; goto out;
}
/* /*
* Isolate the page to avoid collapsing an hugepage * Isolate the page to avoid collapsing an hugepage
* currently in use by the VM. * currently in use by the VM.
*/ */
if (isolate_lru_page(page)) { if (isolate_lru_page(page)) {
unlock_page(page); unlock_page(page);
release_pte_pages(pte, _pte);
goto out; goto out;
} }
/* 0 stands for page_is_file_cache(page) == false */ /* 0 stands for page_is_file_cache(page) == false */
...@@ -1771,12 +1756,11 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -1771,12 +1756,11 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
mmu_notifier_test_young(vma->vm_mm, address)) mmu_notifier_test_young(vma->vm_mm, address))
referenced = 1; referenced = 1;
} }
if (unlikely(!referenced)) if (likely(referenced))
release_all_pte_pages(pte); return 1;
else
isolated = 1;
out: out:
return isolated; release_pte_pages(pte, _pte);
return 0;
} }
static void __collapse_huge_page_copy(pte_t *pte, struct page *page, static void __collapse_huge_page_copy(pte_t *pte, struct page *page,
......
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