summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugh Dickins <hugh@veritas.com>2005-01-07 21:58:02 -0800
committerLinus Torvalds <torvalds@evo.osdl.org>2005-01-07 21:58:02 -0800
commitb37e39b03bcd49397cac7b937d9b180157705e08 (patch)
treebff70e85ba5286bb0c150b260eb1ace00242a6da
parentde146a08f93f5c4ab71503a79a7c5e300065b39a (diff)
[PATCH] vmtrunc: truncate_count not atomic
Why is mapping->truncate_count atomic? It's incremented inside i_mmap_lock (and i_sem), and the reads don't need it to be atomic. And why smp_rmb() before call to ->nopage? The compiler cannot reorder the initial assignment of sequence after the call to ->nopage, and no cpu (yet!) can read from the future, which is all that matters there. And delete totally bogus reset of truncate_count from blkmtd add_device. truncate_count is all about detecting i_size changes: i_size does not change there; and if it did, the count should be incremented not reset. Signed-off-by: Hugh Dickins <hugh@veritas.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/mtd/devices/blkmtd.c1
-rw-r--r--fs/inode.c1
-rw-r--r--include/linux/fs.h2
-rw-r--r--mm/memory.c12
4 files changed, 6 insertions, 10 deletions
diff --git a/drivers/mtd/devices/blkmtd.c b/drivers/mtd/devices/blkmtd.c
index 80d3393ee817..199824a6c3de 100644
--- a/drivers/mtd/devices/blkmtd.c
+++ b/drivers/mtd/devices/blkmtd.c
@@ -661,7 +661,6 @@ static struct blkmtd_dev *add_device(char *devname, int readonly, int erase_size
memset(dev, 0, sizeof(struct blkmtd_dev));
dev->blkdev = bdev;
- atomic_set(&(dev->blkdev->bd_inode->i_mapping->truncate_count), 0);
if(!readonly) {
init_MUTEX(&dev->wrbuf_mutex);
}
diff --git a/fs/inode.c b/fs/inode.c
index b6066773ad82..0beebc00a645 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -198,7 +198,6 @@ void inode_init_once(struct inode *inode)
INIT_RADIX_TREE(&inode->i_data.page_tree, GFP_ATOMIC);
spin_lock_init(&inode->i_data.tree_lock);
spin_lock_init(&inode->i_data.i_mmap_lock);
- atomic_set(&inode->i_data.truncate_count, 0);
INIT_LIST_HEAD(&inode->i_data.private_list);
spin_lock_init(&inode->i_data.private_lock);
INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2d9885aa2626..cd0b31b4afba 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -341,7 +341,7 @@ struct address_space {
struct prio_tree_root i_mmap; /* tree of private and shared mappings */
struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
spinlock_t i_mmap_lock; /* protect tree, count, list */
- atomic_t truncate_count; /* Cover race condition with truncate */
+ unsigned int truncate_count; /* Cover race condition with truncate */
unsigned long nrpages; /* number of total pages */
pgoff_t writeback_index;/* writeback starts here */
struct address_space_operations *a_ops; /* methods */
diff --git a/mm/memory.c b/mm/memory.c
index 6224cb1933c1..5c6a4db990ac 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1424,7 +1424,7 @@ void unmap_mapping_range(struct address_space *mapping,
spin_lock(&mapping->i_mmap_lock);
/* Protect against page fault */
- atomic_inc(&mapping->truncate_count);
+ mapping->truncate_count++;
if (unlikely(!prio_tree_empty(&mapping->i_mmap)))
unmap_mapping_range_list(&mapping->i_mmap, &details);
@@ -1726,7 +1726,7 @@ do_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
struct page * new_page;
struct address_space *mapping = NULL;
pte_t entry;
- int sequence = 0;
+ unsigned int sequence = 0;
int ret = VM_FAULT_MINOR;
int anon = 0;
@@ -1738,9 +1738,8 @@ do_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
if (vma->vm_file) {
mapping = vma->vm_file->f_mapping;
- sequence = atomic_read(&mapping->truncate_count);
+ sequence = mapping->truncate_count;
}
- smp_rmb(); /* Prevent CPU from reordering lock-free ->nopage() */
retry:
cond_resched();
new_page = vma->vm_ops->nopage(vma, address & PAGE_MASK, &ret);
@@ -1774,9 +1773,8 @@ retry:
* invalidated this page. If unmap_mapping_range got called,
* retry getting the page.
*/
- if (mapping &&
- (unlikely(sequence != atomic_read(&mapping->truncate_count)))) {
- sequence = atomic_read(&mapping->truncate_count);
+ if (mapping && unlikely(sequence != mapping->truncate_count)) {
+ sequence = mapping->truncate_count;
spin_unlock(&mm->page_table_lock);
page_cache_release(new_page);
goto retry;