[patch 14/18] remap_file_pages protection support: avoid lookup and I/O of pages for PROT_NONE remapping

From: blaisorblade
Date: Fri Aug 26 2005 - 12:02:57 EST



From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@xxxxxxxx>, Ingo Molnar <mingo@xxxxxxx>

This optimization avoid looking up pages for PROT_NONE mappings, and instead
simply clear the page tables. This code was taken straight from Ingo's patch.

However, this code is only correct if we disallow having VMA with protections
!= PROT_NONE; on a VM_READ vma, for instance, the cleared PTE would be faulted
in again, which is wrong.

We could (in order of preference)
*) use the subsequent patch; you may feel it's a bit intrusive, but it's not
too much, and may further be simplified.
*) drop this optimization
*) additionally check that the VMA is PROT_NONE in this optimization (but we
would have to disallow mprotect() on the VMA or specify the mappings get in an
"unspecified" state)

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@xxxxxxxx>
---

linux-2.6.git-paolo/mm/filemap.c | 14 ++++++++++++++
linux-2.6.git-paolo/mm/shmem.c | 9 +++++++++
2 files changed, 23 insertions(+)

diff -puN mm/filemap.c~rfp-avoid-lookup-miss-mapping-base mm/filemap.c
--- linux-2.6.git/mm/filemap.c~rfp-avoid-lookup-miss-mapping-base 2005-08-25 13:01:32.000000000 +0200
+++ linux-2.6.git-paolo/mm/filemap.c 2005-08-25 13:01:32.000000000 +0200
@@ -1495,6 +1495,20 @@ int filemap_populate(struct vm_area_stru
struct page *page;
int err;

+ /*
+ * mapping-removal fastpath:
+ */
+ if ((vma->vm_flags & VM_SHARED) &&
+ (pgprot_val(prot) == pgprot_val(__S000))) {
+ /* Still do error-checking! */
+ size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+ if (pgoff + (len >> PAGE_CACHE_SHIFT) > size)
+ return -EINVAL;
+
+ zap_page_range(vma, addr, len, NULL);
+ return 0;
+ }
+
if (!nonblock)
force_page_cache_readahead(mapping, vma->vm_file,
pgoff, len >> PAGE_CACHE_SHIFT);
diff -puN mm/shmem.c~rfp-avoid-lookup-miss-mapping-base mm/shmem.c
--- linux-2.6.git/mm/shmem.c~rfp-avoid-lookup-miss-mapping-base 2005-08-25 13:01:32.000000000 +0200
+++ linux-2.6.git-paolo/mm/shmem.c 2005-08-25 13:01:32.000000000 +0200
@@ -1186,6 +1186,15 @@ static int shmem_populate(struct vm_area
if (pgoff >= size || pgoff + (len >> PAGE_SHIFT) > size)
return -EINVAL;

+ /*
+ * mapping-removal fastpath:
+ */
+ if ((vma->vm_flags & VM_SHARED) &&
+ (pgprot_val(prot) == pgprot_val(__S000))) {
+ zap_page_range(vma, addr, len, NULL);
+ return 0;
+ }
+
while ((long) len > 0) {
struct page *page = NULL;
int err;
_
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/