Commit ae801aa1 authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

[PATCH] shmem: rework majmin and ZERO_PAGE

Very minor adjustments to shmem_getpage return path: I now prefer it to return
NULL and let do_shmem_file_read use ZERO_PAGE(0) in that case; and we don't
need a local majmin variable, do_no_page initializes *type to VM_FAULT_MINOR
already.
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 669d88ec
...@@ -885,7 +885,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, ...@@ -885,7 +885,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
struct page *swappage; struct page *swappage;
swp_entry_t *entry; swp_entry_t *entry;
swp_entry_t swap; swp_entry_t swap;
int error, majmin = VM_FAULT_MINOR; int error;
if (idx >= SHMEM_MAX_INDEX) if (idx >= SHMEM_MAX_INDEX)
return -EFBIG; return -EFBIG;
...@@ -923,9 +923,10 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, ...@@ -923,9 +923,10 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
shmem_swp_unmap(entry); shmem_swp_unmap(entry);
spin_unlock(&info->lock); spin_unlock(&info->lock);
/* here we actually do the io */ /* here we actually do the io */
if (majmin == VM_FAULT_MINOR && type) if (type && *type == VM_FAULT_MINOR) {
inc_page_state(pgmajfault); inc_page_state(pgmajfault);
majmin = VM_FAULT_MAJOR; *type = VM_FAULT_MAJOR;
}
swappage = shmem_swapin(info, swap, idx); swappage = shmem_swapin(info, swap, idx);
if (!swappage) { if (!swappage) {
spin_lock(&info->lock); spin_lock(&info->lock);
...@@ -1077,15 +1078,10 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, ...@@ -1077,15 +1078,10 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
SetPageUptodate(filepage); SetPageUptodate(filepage);
} }
done: done:
if (!*pagep) { if (*pagep != filepage) {
if (filepage) {
unlock_page(filepage); unlock_page(filepage);
*pagep = filepage; *pagep = filepage;
} else
*pagep = ZERO_PAGE(0);
} }
if (type)
*type = majmin;
return 0; return 0;
failed: failed:
...@@ -1442,13 +1438,14 @@ static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_ ...@@ -1442,13 +1438,14 @@ static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_
if (index == end_index) { if (index == end_index) {
nr = i_size & ~PAGE_CACHE_MASK; nr = i_size & ~PAGE_CACHE_MASK;
if (nr <= offset) { if (nr <= offset) {
if (page)
page_cache_release(page); page_cache_release(page);
break; break;
} }
} }
nr -= offset; nr -= offset;
if (page != ZERO_PAGE(0)) { if (page) {
/* /*
* If users can be writing to this page using arbitrary * If users can be writing to this page using arbitrary
* virtual addresses, take care about potential aliasing * virtual addresses, take care about potential aliasing
...@@ -1461,7 +1458,8 @@ static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_ ...@@ -1461,7 +1458,8 @@ static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_
*/ */
if (!offset) if (!offset)
mark_page_accessed(page); mark_page_accessed(page);
} } else
page = ZERO_PAGE(0);
/* /*
* Ok, we have the page, and it's up-to-date, so * Ok, we have the page, and it's up-to-date, so
......
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