Unionfs: mmap fixes
authorHugh Dickins <hugh@veritas.com>
Tue, 25 Dec 2007 20:31:13 +0000 (15:31 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Fri, 12 Aug 2011 02:37:13 +0000 (22:37 -0400)
Remove !mapping_cap_writeback_dirty shortcircuit from unionfs_writepages.

It was introduced to avoid the stray AOP_WRITEPAGE_ACTIVATE coming from
shmem_writepage; but that has since been fixed in shmem_writepage and in
write_cache_pages.  It stayed because it looked like a good optimization,
not to waste time calling down to tmpfs when that would serve no purpose.

But in fact this optimization causes hangs when running LTP with unionfs
over tmpfs.  The problem is that the test comes at the wrong level: unionfs
has already declared in its default_backing_dev_info that it's playing by
cap_writeback_dirty rules.  If it does nothing here in its writepages, its
dirty pages accumulate and choke the system.  What's needed is to carry on
down and let its pages be cleaned while in turn they dirty the lower level.

And this now has an additional benefit for tmpfs, that a sync or pdflush
pushes these pages down to shmem_writepage, letting it match the filepage
coming from unionfs with the swap which may have been allocated earlier,
so it can free the duplication sooner than waiting for further pressure.

Remove unnecessary locking/code from prepare_write.  Handle if no lower
inodes in writepage.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/mmap.c

index 4d05352ed516811d20dc5c7bede56791586ff0c5..aad2137e18f37978bc01d4d0bec3e1e79509343c 100644 (file)
@@ -30,6 +30,11 @@ static int unionfs_writepage(struct page *page, struct writeback_control *wbc)
 
        BUG_ON(!PageUptodate(page));
        inode = page->mapping->host;
+       /* if no lower inode, nothing to do */
+       if (!inode || !UNIONFS_I(inode) || UNIONFS_I(inode)->lower_inodes) {
+               err = 0;
+               goto out;
+       }
        lower_inode = unionfs_lower_inode(inode);
        lower_mapping = lower_inode->i_mapping;
 
@@ -130,9 +135,6 @@ static int unionfs_writepages(struct address_space *mapping,
        if (!lower_inode)
                goto out;
 
-       if (!mapping_cap_writeback_dirty(lower_inode->i_mapping))
-               goto out;
-
        err = generic_writepages(mapping, wbc);
        if (!err)
                unionfs_copy_attr_times(inode);
@@ -222,26 +224,13 @@ out:
 static int unionfs_prepare_write(struct file *file, struct page *page,
                                 unsigned from, unsigned to)
 {
-       int err;
-
-       unionfs_read_lock(file->f_path.dentry->d_sb);
        /*
-        * This is the only place where we unconditionally copy the lower
-        * attribute times before calling unionfs_file_revalidate.  The
-        * reason is that our ->write calls do_sync_write which in turn will
-        * call our ->prepare_write and then ->commit_write.  Before our
-        * ->write is called, the lower mtimes are in sync, but by the time
-        * the VFS calls our ->commit_write, the lower mtimes have changed.
-        * Therefore, the only reasonable time for us to sync up from the
-        * changed lower mtimes, and avoid an invariant violation warning,
-        * is here, in ->prepare_write.
+        * Just copy lower inode attributes and return success.  Not much
+        * else to do here.  No need to lock either (lockdep won't like it).
+        * Let commit_write do all the hard work instead.
         */
        unionfs_copy_attr_times(file->f_path.dentry->d_inode);
-       err = unionfs_file_revalidate(file, true);
-       unionfs_check_file(file);
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
-
-       return err;
+       return 0;
 }
 
 static int unionfs_commit_write(struct file *file, struct page *page,