diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-06-20 14:18:25 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-06-20 14:18:25 -0400 |
commit | 89f5b7da2a6bad2e84670422ab8192382a5aeb9f (patch) | |
tree | 4f55cf9ef8a76d4b9a960e1b443ed015e63e713f /mm/memory.c | |
parent | 9bedbcb207ed9a571b239231d99c8fd4a34ae24d (diff) |
Reinstate ZERO_PAGE optimization in 'get_user_pages()' and fix XIP
KAMEZAWA Hiroyuki and Oleg Nesterov point out that since the commit
557ed1fa2620dc119adb86b34c614e152a629a80 ("remove ZERO_PAGE") removed
the ZERO_PAGE from the VM mappings, any users of get_user_pages() will
generally now populate the VM with real empty pages needlessly.
We used to get the ZERO_PAGE when we did the "handle_mm_fault()", but
since fault handling no longer uses ZERO_PAGE for new anonymous pages,
we now need to handle that special case in follow_page() instead.
In particular, the removal of ZERO_PAGE effectively removed the core
file writing optimization where we would skip writing pages that had not
been populated at all, and increased memory pressure a lot by allocating
all those useless newly zeroed pages.
This reinstates the optimization by making the unmapped PTE case the
same as for a non-existent page table, which already did this correctly.
While at it, this also fixes the XIP case for follow_page(), where the
caller could not differentiate between the case of a page that simply
could not be used (because it had no "struct page" associated with it)
and a page that just wasn't mapped.
We do that by simply returning an error pointer for pages that could not
be turned into a "struct page *". The error is arbitrarily picked to be
EFAULT, since that was what get_user_pages() already used for the
equivalent IO-mapped page case.
[ Also removed an impossible test for pte_offset_map_lock() failing:
that's not how that function works ]
Acked-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: Nick Piggin <npiggin@suse.de>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memory.c')
-rw-r--r-- | mm/memory.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/mm/memory.c b/mm/memory.c index 19e0ae9beecb..9aefaae46858 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -999,17 +999,15 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, | |||
999 | goto no_page_table; | 999 | goto no_page_table; |
1000 | 1000 | ||
1001 | ptep = pte_offset_map_lock(mm, pmd, address, &ptl); | 1001 | ptep = pte_offset_map_lock(mm, pmd, address, &ptl); |
1002 | if (!ptep) | ||
1003 | goto out; | ||
1004 | 1002 | ||
1005 | pte = *ptep; | 1003 | pte = *ptep; |
1006 | if (!pte_present(pte)) | 1004 | if (!pte_present(pte)) |
1007 | goto unlock; | 1005 | goto no_page; |
1008 | if ((flags & FOLL_WRITE) && !pte_write(pte)) | 1006 | if ((flags & FOLL_WRITE) && !pte_write(pte)) |
1009 | goto unlock; | 1007 | goto unlock; |
1010 | page = vm_normal_page(vma, address, pte); | 1008 | page = vm_normal_page(vma, address, pte); |
1011 | if (unlikely(!page)) | 1009 | if (unlikely(!page)) |
1012 | goto unlock; | 1010 | goto bad_page; |
1013 | 1011 | ||
1014 | if (flags & FOLL_GET) | 1012 | if (flags & FOLL_GET) |
1015 | get_page(page); | 1013 | get_page(page); |
@@ -1024,6 +1022,15 @@ unlock: | |||
1024 | out: | 1022 | out: |
1025 | return page; | 1023 | return page; |
1026 | 1024 | ||
1025 | bad_page: | ||
1026 | pte_unmap_unlock(ptep, ptl); | ||
1027 | return ERR_PTR(-EFAULT); | ||
1028 | |||
1029 | no_page: | ||
1030 | pte_unmap_unlock(ptep, ptl); | ||
1031 | if (!pte_none(pte)) | ||
1032 | return page; | ||
1033 | /* Fall through to ZERO_PAGE handling */ | ||
1027 | no_page_table: | 1034 | no_page_table: |
1028 | /* | 1035 | /* |
1029 | * When core dumping an enormous anonymous area that nobody | 1036 | * When core dumping an enormous anonymous area that nobody |
@@ -1159,6 +1166,8 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, | |||
1159 | 1166 | ||
1160 | cond_resched(); | 1167 | cond_resched(); |
1161 | } | 1168 | } |
1169 | if (IS_ERR(page)) | ||
1170 | return i ? i : PTR_ERR(page); | ||
1162 | if (pages) { | 1171 | if (pages) { |
1163 | pages[i] = page; | 1172 | pages[i] = page; |
1164 | 1173 | ||