提交 c9cfcddf 编写于 作者: L Linus Torvalds

VM: add common helper function to create the page tables

This logic was duplicated four times, for no good reason.
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 4168f7a3
......@@ -306,9 +306,6 @@ void install_arg_page(struct vm_area_struct *vma,
struct page *page, unsigned long address)
{
struct mm_struct *mm = vma->vm_mm;
pgd_t * pgd;
pud_t * pud;
pmd_t * pmd;
pte_t * pte;
spinlock_t *ptl;
......@@ -316,14 +313,7 @@ void install_arg_page(struct vm_area_struct *vma,
goto out;
flush_dcache_page(page);
pgd = pgd_offset(mm, address);
pud = pud_alloc(mm, pgd, address);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, address);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, address, &ptl);
pte = get_locked_pte(mm, address, &ptl);
if (!pte)
goto out;
if (!pte_none(*pte)) {
......
......@@ -742,6 +742,8 @@ struct shrinker;
extern struct shrinker *set_shrinker(int, shrinker_t);
extern void remove_shrinker(struct shrinker *shrinker);
extern pte_t *FASTCALL(get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl));
int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address);
......
......@@ -55,20 +55,10 @@ int install_page(struct mm_struct *mm, struct vm_area_struct *vma,
pgoff_t size;
int err = -ENOMEM;
pte_t *pte;
pmd_t *pmd;
pud_t *pud;
pgd_t *pgd;
pte_t pte_val;
spinlock_t *ptl;
pgd = pgd_offset(mm, addr);
pud = pud_alloc(mm, pgd, addr);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
pte = get_locked_pte(mm, addr, &ptl);
if (!pte)
goto out;
......@@ -110,20 +100,10 @@ int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma,
{
int err = -ENOMEM;
pte_t *pte;
pmd_t *pmd;
pud_t *pud;
pgd_t *pgd;
pte_t pte_val;
spinlock_t *ptl;
pgd = pgd_offset(mm, addr);
pud = pud_alloc(mm, pgd, addr);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
pte = get_locked_pte(mm, addr, &ptl);
if (!pte)
goto out;
......
......@@ -1146,6 +1146,18 @@ int zeromap_page_range(struct vm_area_struct *vma,
return err;
}
pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl)
{
pgd_t * pgd = pgd_offset(mm, addr);
pud_t * pud = pud_alloc(mm, pgd, addr);
if (pud) {
pmd_t * pmd = pmd_alloc(mm, pgd, addr);
if (pmd)
return pte_alloc_map_lock(mm, pmd, addr, ptl);
}
return NULL;
}
/*
* This is the old fallback for page remapping.
*
......@@ -1156,10 +1168,7 @@ int zeromap_page_range(struct vm_area_struct *vma,
static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *page, pgprot_t prot)
{
int retval;
pgd_t * pgd;
pud_t * pud;
pmd_t * pmd;
pte_t * pte;
pte_t *pte;
spinlock_t *ptl;
retval = -EINVAL;
......@@ -1167,14 +1176,7 @@ static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *pa
goto out;
retval = -ENOMEM;
flush_dcache_page(page);
pgd = pgd_offset(mm, addr);
pud = pud_alloc(mm, pgd, addr);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
pte = get_locked_pte(mm, addr, &ptl);
if (!pte)
goto out;
retval = -EBUSY;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册