Commit 6219049a authored by Bob Liu's avatar Bob Liu Committed by Linus Torvalds

mm: introduce mm_find_pmd()

Several place need to find the pmd by(mm_struct, address), so introduce a
function to simplify it.

[akpm@linux-foundation.org: fix warning]
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 344aa35c
...@@ -1146,22 +1146,14 @@ pmd_t *page_check_address_pmd(struct page *page, ...@@ -1146,22 +1146,14 @@ pmd_t *page_check_address_pmd(struct page *page,
unsigned long address, unsigned long address,
enum page_check_address_pmd_flag flag) enum page_check_address_pmd_flag flag)
{ {
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd, *ret = NULL; pmd_t *pmd, *ret = NULL;
if (address & ~HPAGE_PMD_MASK) if (address & ~HPAGE_PMD_MASK)
goto out; goto out;
pgd = pgd_offset(mm, address); pmd = mm_find_pmd(mm, address);
if (!pgd_present(*pgd)) if (!pmd)
goto out; goto out;
pud = pud_offset(pgd, address);
if (!pud_present(*pud))
goto out;
pmd = pmd_offset(pud, address);
if (pmd_none(*pmd)) if (pmd_none(*pmd))
goto out; goto out;
if (pmd_page(*pmd) != page) if (pmd_page(*pmd) != page)
...@@ -1908,8 +1900,6 @@ static void collapse_huge_page(struct mm_struct *mm, ...@@ -1908,8 +1900,6 @@ static void collapse_huge_page(struct mm_struct *mm,
struct vm_area_struct *vma, struct vm_area_struct *vma,
int node) int node)
{ {
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd, _pmd; pmd_t *pmd, _pmd;
pte_t *pte; pte_t *pte;
pgtable_t pgtable; pgtable_t pgtable;
...@@ -1955,17 +1945,10 @@ static void collapse_huge_page(struct mm_struct *mm, ...@@ -1955,17 +1945,10 @@ static void collapse_huge_page(struct mm_struct *mm,
goto out; goto out;
VM_BUG_ON(vma->vm_flags & VM_NO_THP); VM_BUG_ON(vma->vm_flags & VM_NO_THP);
pgd = pgd_offset(mm, address); pmd = mm_find_pmd(mm, address);
if (!pgd_present(*pgd)) if (!pmd)
goto out; goto out;
if (pmd_trans_huge(*pmd))
pud = pud_offset(pgd, address);
if (!pud_present(*pud))
goto out;
pmd = pmd_offset(pud, address);
/* pmd can't go away or become huge under us */
if (!pmd_present(*pmd) || pmd_trans_huge(*pmd))
goto out; goto out;
anon_vma_lock(vma->anon_vma); anon_vma_lock(vma->anon_vma);
...@@ -2048,8 +2031,6 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, ...@@ -2048,8 +2031,6 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
unsigned long address, unsigned long address,
struct page **hpage) struct page **hpage)
{ {
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
pte_t *pte, *_pte; pte_t *pte, *_pte;
int ret = 0, referenced = 0, none = 0; int ret = 0, referenced = 0, none = 0;
...@@ -2060,16 +2041,10 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, ...@@ -2060,16 +2041,10 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
VM_BUG_ON(address & ~HPAGE_PMD_MASK); VM_BUG_ON(address & ~HPAGE_PMD_MASK);
pgd = pgd_offset(mm, address); pmd = mm_find_pmd(mm, address);
if (!pgd_present(*pgd)) if (!pmd)
goto out; goto out;
if (pmd_trans_huge(*pmd))
pud = pud_offset(pgd, address);
if (!pud_present(*pud))
goto out;
pmd = pmd_offset(pud, address);
if (!pmd_present(*pmd) || pmd_trans_huge(*pmd))
goto out; goto out;
pte = pte_offset_map_lock(mm, pmd, address, &ptl); pte = pte_offset_map_lock(mm, pmd, address, &ptl);
...@@ -2363,22 +2338,12 @@ void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd) ...@@ -2363,22 +2338,12 @@ void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd)
static void split_huge_page_address(struct mm_struct *mm, static void split_huge_page_address(struct mm_struct *mm,
unsigned long address) unsigned long address)
{ {
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
VM_BUG_ON(!(address & ~HPAGE_PMD_MASK)); VM_BUG_ON(!(address & ~HPAGE_PMD_MASK));
pgd = pgd_offset(mm, address); pmd = mm_find_pmd(mm, address);
if (!pgd_present(*pgd)) if (!pmd)
return;
pud = pud_offset(pgd, address);
if (!pud_present(*pud))
return;
pmd = pmd_offset(pud, address);
if (!pmd_present(*pmd))
return; return;
/* /*
* Caller holds the mmap_sem write mode, so a huge pmd cannot * Caller holds the mmap_sem write mode, so a huge pmd cannot
......
...@@ -91,6 +91,11 @@ extern unsigned long highest_memmap_pfn; ...@@ -91,6 +91,11 @@ extern unsigned long highest_memmap_pfn;
extern int isolate_lru_page(struct page *page); extern int isolate_lru_page(struct page *page);
extern void putback_lru_page(struct page *page); extern void putback_lru_page(struct page *page);
/*
* in mm/rmap.c:
*/
extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
/* /*
* in mm/page_alloc.c * in mm/page_alloc.c
*/ */
......
...@@ -778,8 +778,6 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, ...@@ -778,8 +778,6 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
struct page *kpage, pte_t orig_pte) struct page *kpage, pte_t orig_pte)
{ {
struct mm_struct *mm = vma->vm_mm; struct mm_struct *mm = vma->vm_mm;
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
pte_t *ptep; pte_t *ptep;
spinlock_t *ptl; spinlock_t *ptl;
...@@ -792,18 +790,10 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, ...@@ -792,18 +790,10 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
if (addr == -EFAULT) if (addr == -EFAULT)
goto out; goto out;
pgd = pgd_offset(mm, addr); pmd = mm_find_pmd(mm, addr);
if (!pgd_present(*pgd)) if (!pmd)
goto out; goto out;
pud = pud_offset(pgd, addr);
if (!pud_present(*pud))
goto out;
pmd = pmd_offset(pud, addr);
BUG_ON(pmd_trans_huge(*pmd)); BUG_ON(pmd_trans_huge(*pmd));
if (!pmd_present(*pmd))
goto out;
mmun_start = addr; mmun_start = addr;
mmun_end = addr + PAGE_SIZE; mmun_end = addr + PAGE_SIZE;
......
...@@ -91,8 +91,6 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma, ...@@ -91,8 +91,6 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma,
{ {
struct mm_struct *mm = vma->vm_mm; struct mm_struct *mm = vma->vm_mm;
swp_entry_t entry; swp_entry_t entry;
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
pte_t *ptep, pte; pte_t *ptep, pte;
spinlock_t *ptl; spinlock_t *ptl;
...@@ -103,19 +101,11 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma, ...@@ -103,19 +101,11 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma,
goto out; goto out;
ptl = &mm->page_table_lock; ptl = &mm->page_table_lock;
} else { } else {
pgd = pgd_offset(mm, addr); pmd = mm_find_pmd(mm, addr);
if (!pgd_present(*pgd)) if (!pmd)
goto out; goto out;
pud = pud_offset(pgd, addr);
if (!pud_present(*pud))
goto out;
pmd = pmd_offset(pud, addr);
if (pmd_trans_huge(*pmd)) if (pmd_trans_huge(*pmd))
goto out; goto out;
if (!pmd_present(*pmd))
goto out;
ptep = pte_offset_map(pmd, addr); ptep = pte_offset_map(pmd, addr);
......
...@@ -562,6 +562,27 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma) ...@@ -562,6 +562,27 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma)
return address; return address;
} }
pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address)
{
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd = NULL;
pgd = pgd_offset(mm, address);
if (!pgd_present(*pgd))
goto out;
pud = pud_offset(pgd, address);
if (!pud_present(*pud))
goto out;
pmd = pmd_offset(pud, address);
if (!pmd_present(*pmd))
pmd = NULL;
out:
return pmd;
}
/* /*
* Check that @page is mapped at @address into @mm. * Check that @page is mapped at @address into @mm.
* *
...@@ -574,8 +595,6 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma) ...@@ -574,8 +595,6 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma)
pte_t *__page_check_address(struct page *page, struct mm_struct *mm, pte_t *__page_check_address(struct page *page, struct mm_struct *mm,
unsigned long address, spinlock_t **ptlp, int sync) unsigned long address, spinlock_t **ptlp, int sync)
{ {
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
pte_t *pte; pte_t *pte;
spinlock_t *ptl; spinlock_t *ptl;
...@@ -586,17 +605,10 @@ pte_t *__page_check_address(struct page *page, struct mm_struct *mm, ...@@ -586,17 +605,10 @@ pte_t *__page_check_address(struct page *page, struct mm_struct *mm,
goto check; goto check;
} }
pgd = pgd_offset(mm, address); pmd = mm_find_pmd(mm, address);
if (!pgd_present(*pgd)) if (!pmd)
return NULL;
pud = pud_offset(pgd, address);
if (!pud_present(*pud))
return NULL; return NULL;
pmd = pmd_offset(pud, address);
if (!pmd_present(*pmd))
return NULL;
if (pmd_trans_huge(*pmd)) if (pmd_trans_huge(*pmd))
return NULL; return NULL;
...@@ -1345,8 +1357,6 @@ static int try_to_unmap_cluster(unsigned long cursor, unsigned int *mapcount, ...@@ -1345,8 +1357,6 @@ static int try_to_unmap_cluster(unsigned long cursor, unsigned int *mapcount,
struct vm_area_struct *vma, struct page *check_page) struct vm_area_struct *vma, struct page *check_page)
{ {
struct mm_struct *mm = vma->vm_mm; struct mm_struct *mm = vma->vm_mm;
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
pte_t *pte; pte_t *pte;
pte_t pteval; pte_t pteval;
...@@ -1366,16 +1376,8 @@ static int try_to_unmap_cluster(unsigned long cursor, unsigned int *mapcount, ...@@ -1366,16 +1376,8 @@ static int try_to_unmap_cluster(unsigned long cursor, unsigned int *mapcount,
if (end > vma->vm_end) if (end > vma->vm_end)
end = vma->vm_end; end = vma->vm_end;
pgd = pgd_offset(mm, address); pmd = mm_find_pmd(mm, address);
if (!pgd_present(*pgd)) if (!pmd)
return ret;
pud = pud_offset(pgd, address);
if (!pud_present(*pud))
return ret;
pmd = pmd_offset(pud, address);
if (!pmd_present(*pmd))
return ret; return ret;
mmun_start = address; mmun_start = address;
......
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