]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/buffer.c
vfs: Move mark_inode_dirty() from under page lock in generic_write_end()
[net-next-2.6.git] / fs / buffer.c
index 0f51c0f7c266ee7ebf940d94f869081a4d80b084..f4b033237a02eb73cc9128c1ac3eaf5008593526 100644 (file)
@@ -2061,6 +2061,7 @@ int generic_write_end(struct file *file, struct address_space *mapping,
                        struct page *page, void *fsdata)
 {
        struct inode *inode = mapping->host;
+       int i_size_changed = 0;
 
        copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
 
@@ -2073,12 +2074,21 @@ int generic_write_end(struct file *file, struct address_space *mapping,
         */
        if (pos+copied > inode->i_size) {
                i_size_write(inode, pos+copied);
-               mark_inode_dirty(inode);
+               i_size_changed = 1;
        }
 
        unlock_page(page);
        page_cache_release(page);
 
+       /*
+        * Don't mark the inode dirty under page lock. First, it unnecessarily
+        * makes the holding time of page lock longer. Second, it forces lock
+        * ordering of page lock and transaction start for journaling
+        * filesystems.
+        */
+       if (i_size_changed)
+               mark_inode_dirty(inode);
+
        return copied;
 }
 EXPORT_SYMBOL(generic_write_end);