From: Hans Reiser This patch adds new operation to struct super_operations - sync_inodes, generic implementaion and changes fs-writeback.c:sync_sb_inodes() to call filesystem's sync_inodes if it is defined or generic implementaion otherwise. This new operation allows filesystem to decide itself what to flush. Reiser4 flushes dirty pages on basic of atoms, not of inodes. sync_sb_inodes used to call address space flushing method (writepages) for every dirty inode. For reiser4 it caused having to commit atoms unnecessarily often. This turned into substantial slowdown. Having this method helped to fix that problem. Also, make generic_sync_sb_inodes spin lock itself. It helps reiser4 to get rid of some oddities. sync_sb_inodes is always called like: spin_lock(&inode_lock); sync_sb_inodes(sb, wbc); spin_unlock(&inode_lock); This patch moves spin_lock/spin_unlock down to sync_sb_inodes. Signed-off-by: Andrew Morton --- fs/fs-writeback.c | 26 ++++++++++++++++---------- include/linux/fs.h | 3 +++ 2 files changed, 19 insertions(+), 10 deletions(-) diff -puN fs/fs-writeback.c~reiser4-sb_sync_inodes fs/fs-writeback.c --- a/fs/fs-writeback.c~reiser4-sb_sync_inodes +++ a/fs/fs-writeback.c @@ -285,8 +285,6 @@ __writeback_single_inode(struct inode *i * WB_SYNC_HOLD is a hack for sys_sync(): reattach the inode to sb->s_dirty so * that it can be located for waiting on in __writeback_single_inode(). * - * Called under inode_lock. - * * If `bdi' is non-zero then we're being asked to writeback a specific queue. * This function assumes that the blockdev superblock's inodes are backed by * a variety of queues, so all inodes are searched. For other superblocks, @@ -302,11 +300,13 @@ __writeback_single_inode(struct inode *i * on the writer throttling path, and we get decent balancing between many * throttled threads: we don't want them all piling up on __wait_on_inode. */ -static void -sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc) +void +generic_sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc) { const unsigned long start = jiffies; /* livelock avoidance */ + spin_lock(&inode_lock); + if (!wbc->for_kupdate || list_empty(&sb->s_io)) list_splice_init(&sb->s_dirty, &sb->s_io); @@ -386,8 +386,19 @@ sync_sb_inodes(struct super_block *sb, s if (wbc->nr_to_write <= 0) break; } + spin_unlock(&inode_lock); return; /* Leave any unwritten inodes on s_io */ } +EXPORT_SYMBOL(generic_sync_sb_inodes); + +static void +sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc) +{ + if (sb->s_op->sync_inodes) + sb->s_op->sync_inodes(sb, wbc); + else + generic_sync_sb_inodes(sb, wbc); +} /* * Start writeback of dirty pagecache data against all unlocked inodes. @@ -428,11 +439,8 @@ restart: * be unmounted by the time it is released. */ if (down_read_trylock(&sb->s_umount)) { - if (sb->s_root) { - spin_lock(&inode_lock); + if (sb->s_root) sync_sb_inodes(sb, wbc); - spin_unlock(&inode_lock); - } up_read(&sb->s_umount); } spin_lock(&sb_lock); @@ -470,9 +478,7 @@ void sync_inodes_sb(struct super_block * (inodes_stat.nr_inodes - inodes_stat.nr_unused) + nr_dirty + nr_unstable; wbc.nr_to_write += wbc.nr_to_write / 2; /* Bit more for luck */ - spin_lock(&inode_lock); sync_sb_inodes(sb, &wbc); - spin_unlock(&inode_lock); } /* diff -puN include/linux/fs.h~reiser4-sb_sync_inodes include/linux/fs.h --- a/include/linux/fs.h~reiser4-sb_sync_inodes +++ a/include/linux/fs.h @@ -1257,6 +1257,8 @@ struct super_operations { void (*clear_inode) (struct inode *); void (*umount_begin) (struct vfsmount *, int); + void (*sync_inodes) (struct super_block *sb, + struct writeback_control *wbc); int (*show_options)(struct seq_file *, struct vfsmount *); int (*show_stats)(struct seq_file *, struct vfsmount *); #ifdef CONFIG_QUOTA @@ -1670,6 +1672,7 @@ extern int invalidate_inode_pages2(struc extern int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); extern int write_inode_now(struct inode *, int); +extern void generic_sync_sb_inodes(struct super_block *, struct writeback_control *); extern int filemap_fdatawrite(struct address_space *); extern int filemap_flush(struct address_space *); extern int filemap_fdatawait(struct address_space *); _