From: Nick Piggin <npiggin@suse.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
David Howells <dhowells@redhat.com>,
linux-fsdevel@vger.kernel.org
Subject: [rfc][patch 7/6] mm: merge page_mkwrite
Date: Wed, 7 Mar 2007 11:30:18 +0100 [thread overview]
Message-ID: <20070307103018.GC5555@wotan.suse.de> (raw)
In-Reply-To: <E1HOt96-0008V6-00@dorka.pomaz.szeredi.hu>
Now that I'm making some progress on merging the basic stuff, I'd
like to get opinions about merging page_mkwrite functionality into
->fault().
I still don't see any callers in the tree, but I see no reason why
this won't work (or why it isn't better).
--
Like everything else in life, page_mkwrite()ing is just a primitive,
degenerate form of fault()ing.
Having FAULT_FLAG_WRITE in the fault operation allows us to just get
rid of the page_mkwrite call in do_fault, because filesystems can check
for that flag bit, and do the page_mkwrite thing before returning the
page (this will improve efficiency for everyone).
Then, we introduce another fault flag to signal that the fault is
an event notification for a page, rather than a request for a pgoff.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Index: linux-2.6/include/linux/mm.h
===================================================================
--- linux-2.6.orig/include/linux/mm.h
+++ linux-2.6/include/linux/mm.h
@@ -176,6 +176,7 @@ extern unsigned int kobjsize(const void
* return with the page locked.
*/
#define VM_CAN_NONLINEAR 0x10000000 /* Has ->fault & does nonlinear pages */
+#define VM_NOTIFY_MKWRITE 0x20000000 /* Has ->fault & wants page writable notification */
#ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
#define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
@@ -201,6 +202,7 @@ extern pgprot_t protection_map[16];
#define FAULT_FLAG_WRITE 0x01
#define FAULT_FLAG_NONLINEAR 0x02
+#define FAULT_FLAG_NOTIFY 0x04 /* fault_data.page contains page */
/*
* fault_data is filled in the the pagefault handler and passed to the
@@ -213,7 +215,10 @@ extern pgprot_t protection_map[16];
* nonlinear mapping support.
*/
struct fault_data {
- unsigned long address;
+ union {
+ unsigned long address;
+ struct page *page;
+ };
pgoff_t pgoff;
unsigned int flags;
@@ -230,9 +235,6 @@ struct vm_operations_struct {
void (*close)(struct vm_area_struct * area);
struct page * (*fault)(struct vm_area_struct *vma, struct fault_data * fdata);
struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
- /* notification that a previously read-only page is about to become
- * writable, if an error is returned it will cause a SIGBUS */
- int (*page_mkwrite)(struct vm_area_struct *vma, struct page *page);
#ifdef CONFIG_NUMA
int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
@@ -831,7 +833,7 @@ extern struct shrinker *set_shrinker(int
extern void remove_shrinker(struct shrinker *shrinker);
/*
- * Some shared mappigns will want the pages marked read-only
+ * Some shared mappings will want the pages marked read-only
* to track write events. If so, we'll downgrade vm_page_prot
* to the private version (using protection_map[] without the
* VM_SHARED bit).
@@ -845,7 +847,7 @@ static inline int vma_wants_writenotify(
return 0;
/* The backer wishes to know when pages are first written to? */
- if (vma->vm_ops && vma->vm_ops->page_mkwrite)
+ if (vma->vm_flags & VM_NOTIFY_MKWRITE)
return 1;
/* The open routine did something to the protections already? */
Index: linux-2.6/mm/memory.c
===================================================================
--- linux-2.6.orig/mm/memory.c
+++ linux-2.6/mm/memory.c
@@ -1566,7 +1566,8 @@ static int do_wp_page(struct mm_struct *
* read-only shared pages can get COWed by
* get_user_pages(.write=1, .force=1).
*/
- if (vma->vm_ops && vma->vm_ops->page_mkwrite) {
+ if (unlikely(vma->vm_flags & VM_NOTIFY_MKWRITE)) {
+ struct fault_data fdata;
/*
* Notify the address space that the page is about to
* become writable so that it can prohibit this or wait
@@ -1578,8 +1579,14 @@ static int do_wp_page(struct mm_struct *
page_cache_get(old_page);
pte_unmap_unlock(page_table, ptl);
- if (vma->vm_ops->page_mkwrite(vma, old_page) < 0)
- goto unwritable_page;
+ fdata.flags = FAULT_FLAG_NOTIFY|FAULT_FLAG_WRITE;
+ fdata.page = old_page;
+ fdata.type = -1;
+ old_page = vma->vm_ops->fault(vma, &fdata);
+ WARN_ON(fdata.type == -1);
+ ret = fdata.type;
+ if (!old_page)
+ return ret;
/*
* Since we dropped the lock we need to revalidate
@@ -1677,10 +1684,6 @@ oom:
if (old_page)
page_cache_release(old_page);
return VM_FAULT_OOM;
-
-unwritable_page:
- page_cache_release(old_page);
- return VM_FAULT_SIGBUS;
}
/*
@@ -2254,18 +2257,6 @@ static int __do_fault(struct mm_struct *
goto out;
}
copy_user_highpage(page, faulted_page, address, vma);
- } else {
- /*
- * If the page will be shareable, see if the backing
- * address space wants to know that the page is about
- * to become writable
- */
- if (vma->vm_ops->page_mkwrite &&
- vma->vm_ops->page_mkwrite(vma, page) < 0) {
- fdata.type = VM_FAULT_SIGBUS;
- anon = 1; /* no anon but release faulted_page */
- goto out;
- }
}
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-03-07 10:30 UTC|newest]
Thread overview: 99+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-21 4:49 [patch 0/6] fault vs truncate/invalidate race fix Nick Piggin
2007-02-21 4:49 ` [patch 1/6] mm: debug check for the fault vs invalidate race Nick Piggin
2007-02-21 4:49 ` [patch 2/6] mm: simplify filemap_nopage Nick Piggin
2007-02-21 4:50 ` [patch 3/6] mm: fix fault vs invalidate race for linear mappings Nick Piggin
2007-03-07 6:36 ` Andrew Morton
2007-03-07 6:57 ` Nick Piggin
2007-03-07 7:08 ` Andrew Morton
2007-03-07 7:25 ` Nick Piggin
2007-02-21 4:50 ` [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear) Nick Piggin
2007-03-07 6:51 ` Andrew Morton
2007-03-07 7:08 ` Nick Piggin
2007-03-07 8:19 ` Nick Piggin
2007-03-07 8:27 ` Ingo Molnar
2007-03-07 8:35 ` Andrew Morton
2007-03-07 8:53 ` Ingo Molnar
2007-03-07 9:28 ` Nick Piggin
2007-03-07 9:44 ` Bill Irwin
2007-03-07 9:49 ` Nick Piggin
2007-03-07 10:02 ` Nick Piggin
2007-03-12 23:01 ` Blaisorblade
2007-03-13 1:19 ` Nick Piggin
2007-03-17 12:17 ` Blaisorblade
2007-03-18 2:50 ` Nick Piggin
2007-03-18 13:09 ` Jeff Dike
2007-03-19 12:04 ` Bill Irwin
2007-03-19 20:44 ` Blaisorblade
2007-03-20 6:00 ` Nick Piggin
2007-03-21 19:45 ` Blaisorblade
2007-03-08 12:39 ` Blaisorblade
2007-03-07 9:29 ` Bill Irwin
2007-03-07 9:39 ` Andrew Morton
2007-03-07 10:09 ` Bill Irwin
2007-03-07 8:38 ` Miklos Szeredi
2007-03-07 8:47 ` Andrew Morton
2007-03-07 8:51 ` Miklos Szeredi
2007-03-07 9:07 ` Andrew Morton
2007-03-07 9:18 ` Nick Piggin
2007-03-07 9:26 ` Andrew Morton
2007-03-07 9:28 ` Miklos Szeredi
2007-03-07 9:38 ` Nick Piggin
2007-03-07 9:25 ` Miklos Szeredi
2007-03-07 9:32 ` Peter Zijlstra
2007-03-07 9:45 ` Nick Piggin
2007-03-07 10:04 ` Nick Piggin
2007-03-07 10:06 ` Peter Zijlstra
2007-03-07 10:13 ` Miklos Szeredi
2007-03-07 10:21 ` Nick Piggin
2007-03-07 10:24 ` Peter Zijlstra
2007-03-07 10:38 ` Nick Piggin
2007-03-07 10:47 ` Peter Zijlstra
2007-03-07 11:00 ` Nick Piggin
2007-03-07 11:48 ` Peter Zijlstra
2007-03-07 12:17 ` Nick Piggin
2007-03-07 12:41 ` Peter Zijlstra
2007-03-07 13:08 ` Nick Piggin
2007-03-07 13:19 ` Peter Zijlstra
2007-03-07 13:36 ` Nick Piggin
2007-03-07 13:52 ` Peter Zijlstra
2007-03-07 13:56 ` Miklos Szeredi
2007-03-07 14:34 ` Peter Zijlstra
2007-03-07 15:01 ` Nick Piggin
2007-03-07 16:58 ` [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas Peter Zijlstra
2007-03-07 18:00 ` Linus Torvalds
2007-03-07 18:12 ` Peter Zijlstra
2007-03-07 18:24 ` Peter Zijlstra
2007-03-08 11:21 ` Miklos Szeredi
2007-03-08 11:37 ` Peter Zijlstra
2007-03-08 11:48 ` Miklos Szeredi
2007-03-08 12:11 ` Peter Zijlstra
2007-03-08 12:19 ` Nick Piggin
2007-03-08 12:25 ` Miklos Szeredi
2007-03-08 11:58 ` Nick Piggin
2007-03-08 12:09 ` Miklos Szeredi
2007-03-07 15:10 ` [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear) Jeff Dike
2007-03-07 13:53 ` Miklos Szeredi
2007-03-07 14:50 ` Nick Piggin
2007-03-07 12:22 ` Bill Irwin
2007-03-07 12:36 ` Nick Piggin
2007-03-07 10:30 ` Nick Piggin [this message]
2007-03-07 8:59 ` Nick Piggin
2007-03-07 9:11 ` Nick Piggin
2007-03-07 9:22 ` Ingo Molnar
2007-03-07 9:32 ` Bill Irwin
2007-03-07 9:35 ` Ingo Molnar
2007-03-07 9:50 ` Bill Irwin
2007-03-07 9:52 ` Nick Piggin
2007-03-07 7:19 ` Bill Irwin
2007-03-07 10:05 ` Benjamin Herrenschmidt
2007-03-07 10:17 ` Nick Piggin
2007-03-07 10:46 ` Benjamin Herrenschmidt
2007-02-21 4:50 ` [patch 5/6] mm: merge nopfn into fault Nick Piggin
2007-02-21 5:13 ` Nick Piggin
2007-02-21 4:50 ` [patch 6/6] mm: remove legacy cruft Nick Piggin
2007-02-27 4:36 ` [patch 0/6] fault vs truncate/invalidate race fix Dave Airlie
2007-02-27 5:32 ` Andrew Morton
2007-02-27 6:26 ` Dave Airlie
2007-02-27 6:54 ` Benjamin Herrenschmidt
2007-03-18 23:13 ` Dave Airlie
2007-02-27 8:50 ` Nick Piggin
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=20070307103018.GC5555@wotan.suse.de \
--to=npiggin@suse.de \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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;
as well as URLs for NNTP newsgroup(s).