Commit 42ec8004 authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

[PATCH] shmem: misc changes and cleanups

If PAGE_CACHE_SIZE were to differ from PAGE_SIZE, the VM_ACCT macro,
and shmem_nopage's vm_pgoff manipulation, were still not quite right.

Slip a cond_resched_lock into shmem_truncate's long loop; but not into
shmem_unuse_inode's, since other locks held, and swapoff awful anyway.

Move SetPageUptodate to where it's not already set.  Replace
copy_from_user by __copy_from_user since access already verified.

Replace BUG()s by BUG_ON()s.  Remove an uninteresting PAGE_BUG().
parent 62fe4120
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#define SHMEM_MAX_INDEX (SHMEM_NR_DIRECT + (ENTRIES_PER_PAGEPAGE/2) * (ENTRIES_PER_PAGE+1)) #define SHMEM_MAX_INDEX (SHMEM_NR_DIRECT + (ENTRIES_PER_PAGEPAGE/2) * (ENTRIES_PER_PAGE+1))
#define SHMEM_MAX_BYTES ((unsigned long long)SHMEM_MAX_INDEX << PAGE_CACHE_SHIFT) #define SHMEM_MAX_BYTES ((unsigned long long)SHMEM_MAX_INDEX << PAGE_CACHE_SHIFT)
#define VM_ACCT(size) (((size) + PAGE_CACHE_SIZE - 1) >> PAGE_SHIFT) #define VM_ACCT(size) (PAGE_CACHE_ALIGN(size) >> PAGE_SHIFT)
/* Pretend that each entry is of this size in directory's i_size */ /* Pretend that each entry is of this size in directory's i_size */
#define BOGO_DIRENT_SIZE 20 #define BOGO_DIRENT_SIZE 20
...@@ -428,6 +428,7 @@ static void shmem_truncate(struct inode *inode) ...@@ -428,6 +428,7 @@ static void shmem_truncate(struct inode *inode)
info->alloced++; info->alloced++;
} }
empty = subdir; empty = subdir;
cond_resched_lock(&info->lock);
dir = shmem_dir_map(subdir); dir = shmem_dir_map(subdir);
} }
subdir = *dir; subdir = *dir;
...@@ -657,10 +658,8 @@ static int shmem_writepage(struct page * page) ...@@ -657,10 +658,8 @@ static int shmem_writepage(struct page * page)
unsigned long index; unsigned long index;
struct inode *inode; struct inode *inode;
if (!PageLocked(page)) BUG_ON(!PageLocked(page));
BUG(); BUG_ON(page_mapped(page));
if (page_mapped(page))
BUG();
mapping = page->mapping; mapping = page->mapping;
index = page->index; index = page->index;
...@@ -675,10 +674,8 @@ static int shmem_writepage(struct page * page) ...@@ -675,10 +674,8 @@ static int shmem_writepage(struct page * page)
spin_lock(&info->lock); spin_lock(&info->lock);
shmem_recalc_inode(inode); shmem_recalc_inode(inode);
entry = shmem_swp_entry(info, index, NULL); entry = shmem_swp_entry(info, index, NULL);
if (!entry) BUG_ON(!entry);
BUG(); BUG_ON(entry->val);
if (entry->val)
BUG();
if (move_to_swap_cache(page, swap) == 0) { if (move_to_swap_cache(page, swap) == 0) {
shmem_swp_set(info, entry, swap.val); shmem_swp_set(info, entry, swap.val);
...@@ -852,10 +849,10 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, struct page **p ...@@ -852,10 +849,10 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, struct page **p
info->alloced++; info->alloced++;
spin_unlock(&info->lock); spin_unlock(&info->lock);
clear_highpage(page); clear_highpage(page);
SetPageUptodate(page);
} }
/* We have the page */ /* We have the page */
SetPageUptodate(page);
*pagep = page; *pagep = page;
return 0; return 0;
} }
...@@ -896,8 +893,9 @@ struct page *shmem_nopage(struct vm_area_struct *vma, unsigned long address, int ...@@ -896,8 +893,9 @@ struct page *shmem_nopage(struct vm_area_struct *vma, unsigned long address, int
unsigned long idx; unsigned long idx;
int error; int error;
idx = (address - vma->vm_start) >> PAGE_CACHE_SHIFT; idx = (address - vma->vm_start) >> PAGE_SHIFT;
idx += vma->vm_pgoff; idx += vma->vm_pgoff;
idx >>= PAGE_CACHE_SHIFT - PAGE_SHIFT;
if (((loff_t) idx << PAGE_CACHE_SHIFT) >= inode->i_size) if (((loff_t) idx << PAGE_CACHE_SHIFT) >= inode->i_size)
return NOPAGE_SIGBUS; return NOPAGE_SIGBUS;
...@@ -1118,13 +1116,8 @@ shmem_file_write(struct file *file,const char *buf,size_t count,loff_t *ppos) ...@@ -1118,13 +1116,8 @@ shmem_file_write(struct file *file,const char *buf,size_t count,loff_t *ppos)
if (status) if (status)
break; break;
/* We have exclusive IO access to the page.. */
if (!PageLocked(page)) {
PAGE_BUG(page);
}
kaddr = kmap(page); kaddr = kmap(page);
status = copy_from_user(kaddr+offset, buf, bytes); status = __copy_from_user(kaddr+offset, buf, bytes);
kunmap(page); kunmap(page);
if (status) if (status)
goto fail_write; goto fail_write;
......
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