Commit 209b450c authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] mremap: copy_one_pte cleanup

From: Hugh Dickins <hugh@veritas.com>

Clean up mremap move's copy_one_pte:

- get_one_pte_map_nested already weeded out the pte_none case,
  now don't even call copy_one_pte if it has nothing to do.

- check pfn_valid before passing page to page_remove_rmap.
parent 424e44d1
...@@ -79,31 +79,21 @@ static inline pte_t *alloc_one_pte_map(struct mm_struct *mm, unsigned long addr) ...@@ -79,31 +79,21 @@ static inline pte_t *alloc_one_pte_map(struct mm_struct *mm, unsigned long addr)
return pte; return pte;
} }
static int static void
copy_one_pte(struct vm_area_struct *vma, unsigned long old_addr, copy_one_pte(struct vm_area_struct *vma, unsigned long old_addr,
pte_t *src, pte_t *dst, struct pte_chain **pte_chainp) pte_t *src, pte_t *dst, struct pte_chain **pte_chainp)
{ {
int error = 0; pte_t pte = ptep_clear_flush(vma, old_addr, src);
pte_t pte; set_pte(dst, pte);
struct page *page = NULL;
if (pte_present(*src))
page = pte_page(*src);
if (!pte_none(*src)) { if (pte_present(pte)) {
if (page) unsigned long pfn = pte_pfn(pte);
if (pfn_valid(pfn)) {
struct page *page = pfn_to_page(pfn);
page_remove_rmap(page, src); page_remove_rmap(page, src);
pte = ptep_clear_flush(vma, old_addr, src);
if (!dst) {
/* No dest? We must put it back. */
dst = src;
error++;
}
set_pte(dst, pte);
if (page)
*pte_chainp = page_add_rmap(page, dst, *pte_chainp); *pte_chainp = page_add_rmap(page, dst, *pte_chainp);
} }
return error; }
} }
static int static int
...@@ -140,8 +130,11 @@ move_one_page(struct vm_area_struct *vma, unsigned long old_addr, ...@@ -140,8 +130,11 @@ move_one_page(struct vm_area_struct *vma, unsigned long old_addr,
* page_table_lock, we should re-check the src entry... * page_table_lock, we should re-check the src entry...
*/ */
if (src) { if (src) {
error = copy_one_pte(vma, old_addr, src, if (dst)
copy_one_pte(vma, old_addr, src,
dst, &pte_chain); dst, &pte_chain);
else
error = -ENOMEM;
pte_unmap_nested(src); pte_unmap_nested(src);
} }
pte_unmap(dst); pte_unmap(dst);
......
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