writeback: move inodes from one super_block together
authorShaohua Li <shaohua.li@intel.com>
Thu, 24 Sep 2009 12:42:33 +0000 (14:42 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 25 Sep 2009 16:08:25 +0000 (18:08 +0200)
__mark_inode_dirty adds inode to wb dirty list in random order. If a disk has
several partitions, writeback might keep spindle moving between partitions.
To reduce the move, better write big chunk of one partition and then move to
another. Inodes from one fs usually are in one partion, so idealy move indoes
from one fs together should reduce spindle move. This patch tries to address
this. Before per-bdi writeback is added, the behavior is write indoes
from one fs first and then another, so the patch restores previous behavior.
The loop in the patch is a bit ugly, should we add a dirty list for each
superblock in bdi_writeback?

Test in a two partition disk with attached fio script shows about 3% ~ 6%
improvement.

Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Reviewed-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fs/fs-writeback.c

index 15944f754e1512a21e614d0e47fe6756584f10ea..b27406d51bc74c6df25037f415107ce1f3b5a8b6 100644 (file)
@@ -334,13 +334,28 @@ static void move_expired_inodes(struct list_head *delaying_queue,
                               struct list_head *dispatch_queue,
                                unsigned long *older_than_this)
 {
+       LIST_HEAD(tmp);
+       struct list_head *pos, *node;
+       struct super_block *sb;
+       struct inode *inode;
+
        while (!list_empty(delaying_queue)) {
-               struct inode *inode = list_entry(delaying_queue->prev,
-                                               struct inode, i_list);
+               inode = list_entry(delaying_queue->prev, struct inode, i_list);
                if (older_than_this &&
                    inode_dirtied_after(inode, *older_than_this))
                        break;
-               list_move(&inode->i_list, dispatch_queue);
+               list_move(&inode->i_list, &tmp);
+       }
+
+       /* Move inodes from one superblock together */
+       while (!list_empty(&tmp)) {
+               inode = list_entry(tmp.prev, struct inode, i_list);
+               sb = inode->i_sb;
+               list_for_each_prev_safe(pos, node, &tmp) {
+                       inode = list_entry(pos, struct inode, i_list);
+                       if (inode->i_sb == sb)
+                               list_move(&inode->i_list, dispatch_queue);
+               }
        }
 }