From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>, linux-kernel@vger.kernel.org
Subject: [PATCH 07/11] unpaged: COW on VM_UNPAGED
Date: Thu, 17 Nov 2005 19:37:23 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.61.0511171936440.4563@goblin.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0511171925290.4563@goblin.wat.veritas.com>
Remove the BUG_ON(vma->vm_flags & VM_UNPAGED) from do_wp_page, and let
it do Copy-On-Write without touching the VM_UNPAGED's page counts - but
this is incomplete, because the anonymous page it inserts will itself
need to be handled, here and in other functions - next patch.
We still don't copy the page if the pfn is invalid, because the
copy_user_highpage interface does not allow it. But that's not been
a problem in the past: can be added in later if the need arises.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
mm/memory.c | 37 +++++++++++++++++++++++++------------
1 files changed, 25 insertions(+), 12 deletions(-)
--- unpaged06/mm/memory.c 2005-11-17 15:11:02.000000000 +0000
+++ unpaged07/mm/memory.c 2005-11-17 15:11:30.000000000 +0000
@@ -1277,22 +1277,28 @@ static int do_wp_page(struct mm_struct *
unsigned long address, pte_t *page_table, pmd_t *pmd,
spinlock_t *ptl, pte_t orig_pte)
{
- struct page *old_page, *new_page;
+ struct page *old_page, *src_page, *new_page;
unsigned long pfn = pte_pfn(orig_pte);
pte_t entry;
int ret = VM_FAULT_MINOR;
- BUG_ON(vma->vm_flags & VM_UNPAGED);
-
if (unlikely(!pfn_valid(pfn))) {
/*
* Page table corrupted: show pte and kill process.
+ * Or it's an attempt to COW an out-of-map VM_UNPAGED
+ * entry, which copy_user_highpage does not support.
*/
print_bad_pte(vma, orig_pte, address);
ret = VM_FAULT_OOM;
goto unlock;
}
old_page = pfn_to_page(pfn);
+ src_page = old_page;
+
+ if (unlikely(vma->vm_flags & VM_UNPAGED)) {
+ old_page = NULL;
+ goto gotten;
+ }
if (PageAnon(old_page) && !TestSetPageLocked(old_page)) {
int reuse = can_share_swap_page(old_page);
@@ -1313,11 +1319,12 @@ static int do_wp_page(struct mm_struct *
* Ok, we need to copy. Oh, well..
*/
page_cache_get(old_page);
+gotten:
pte_unmap_unlock(page_table, ptl);
if (unlikely(anon_vma_prepare(vma)))
goto oom;
- if (old_page == ZERO_PAGE(address)) {
+ if (src_page == ZERO_PAGE(address)) {
new_page = alloc_zeroed_user_highpage(vma, address);
if (!new_page)
goto oom;
@@ -1325,7 +1332,7 @@ static int do_wp_page(struct mm_struct *
new_page = alloc_page_vma(GFP_HIGHUSER, vma, address);
if (!new_page)
goto oom;
- copy_user_highpage(new_page, old_page, address);
+ copy_user_highpage(new_page, src_page, address);
}
/*
@@ -1333,11 +1340,14 @@ static int do_wp_page(struct mm_struct *
*/
page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
if (likely(pte_same(*page_table, orig_pte))) {
- page_remove_rmap(old_page);
- if (!PageAnon(old_page)) {
+ if (old_page) {
+ page_remove_rmap(old_page);
+ if (!PageAnon(old_page)) {
+ dec_mm_counter(mm, file_rss);
+ inc_mm_counter(mm, anon_rss);
+ }
+ } else
inc_mm_counter(mm, anon_rss);
- dec_mm_counter(mm, file_rss);
- }
flush_cache_page(vma, address, pfn);
entry = mk_pte(new_page, vma->vm_page_prot);
entry = maybe_mkwrite(pte_mkdirty(entry), vma);
@@ -1351,13 +1361,16 @@ static int do_wp_page(struct mm_struct *
new_page = old_page;
ret |= VM_FAULT_WRITE;
}
- page_cache_release(new_page);
- page_cache_release(old_page);
+ if (new_page)
+ page_cache_release(new_page);
+ if (old_page)
+ page_cache_release(old_page);
unlock:
pte_unmap_unlock(page_table, ptl);
return ret;
oom:
- page_cache_release(old_page);
+ if (old_page)
+ page_cache_release(old_page);
return VM_FAULT_OOM;
}
next prev parent reply other threads:[~2005-11-17 19:38 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-17 19:28 [PATCH 00/11] unpaged: PageReserved VM fixups Hugh Dickins
2005-11-17 19:29 ` [PATCH 01/11] unpaged: get_user_pages VM_RESERVED Hugh Dickins
2005-11-17 23:29 ` David S. Miller
2005-11-17 19:30 ` [PATCH 02/11] unpaged: private write VM_RESERVED Hugh Dickins
2005-11-17 19:41 ` Dave Jones
2005-11-17 20:46 ` Dominik Brodowski
2005-11-17 20:51 ` Dave Jones
2005-11-17 23:58 ` David S. Miller
2005-11-18 7:12 ` Dominik Brodowski
2005-11-18 7:59 ` David S. Miller
2005-11-17 20:59 ` Dominik Brodowski
2005-11-17 23:36 ` David S. Miller
2005-11-17 19:31 ` [PATCH 03/11] unpaged: sound nopage get_page Hugh Dickins
2005-11-17 23:41 ` David S. Miller
2005-11-17 19:32 ` [PATCH 04/11] unpaged: unifdefed PageCompound Hugh Dickins
2005-11-17 23:43 ` David S. Miller
2005-11-19 20:15 ` Hugh Dickins
2005-11-19 20:55 ` William Lee Irwin III
2005-11-19 21:41 ` David S. Miller
2005-11-19 21:58 ` William Lee Irwin III
2005-11-17 19:34 ` [PATCH 05/11] unpaged: VM_UNPAGED Hugh Dickins
2005-11-17 20:59 ` William Lee Irwin III
2005-11-17 23:46 ` David S. Miller
2005-11-17 19:36 ` [PATCH 06/11] unpaged: VM_NONLINEAR VM_RESERVED Hugh Dickins
2005-11-17 19:37 ` Hugh Dickins [this message]
2005-11-17 23:52 ` [PATCH 07/11] unpaged: COW on VM_UNPAGED David S. Miller
2005-11-18 5:46 ` Nick Piggin
2005-11-18 6:45 ` David S. Miller
2005-11-18 7:27 ` Hugh Dickins
2005-11-18 7:46 ` Andrew Morton
2005-11-18 8:04 ` David S. Miller
2005-11-18 8:12 ` Hugh Dickins
2005-11-18 8:02 ` Hugh Dickins
2005-11-18 8:08 ` David S. Miller
2005-11-18 8:13 ` Hugh Dickins
2005-11-18 8:36 ` David S. Miller
2005-11-18 9:33 ` Hugh Dickins
2005-11-18 21:08 ` Dave Jones
2005-11-18 19:12 ` Alan Cox
2005-11-17 19:38 ` [PATCH 08/11] unpaged: anon in VM_UNPAGED Hugh Dickins
2005-11-17 19:38 ` [PATCH 09/11] unpaged: ZERO_PAGE " Hugh Dickins
2005-11-17 21:25 ` Ingo Oeser
2005-11-18 19:58 ` Hugh Dickins
2005-11-17 19:39 ` [PATCH 10/11] unpaged: PG_reserved bad_page Hugh Dickins
2005-11-17 19:40 ` [PATCH 11/11] unpaged: copy_page_range vma Hugh Dickins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.61.0511171936440.4563@goblin.wat.veritas.com \
--to=hugh@veritas.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nickpiggin@yahoo.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®