add jbd2 speedup patches
[ext4-patch-queue.git] / speedup-WB_SYNC_ALL-pass
blob7f3a5ad7c3727a81cb4acad9bd81bc149862a459
1 ext4: Speedup WB_SYNC_ALL pass called from sync(2)
3 From: Jan Kara <jack@suse.cz>
5 When doing filesystem wide sync, there's no need to force transaction
6 commit (or synchronously write inode buffer) separately for each inode
7 because ext4_sync_fs() takes care of forcing commit at the end (VFS
8 takes care of flushing buffer cache, respectively). Most of the time
9 this slowness doesn't manifest because previous WB_SYNC_NONE writeback
10 doesn't leave much to write but when there are processes aggressively
11 creating new files and several filesystems to sync, the sync slowness
12 can be noticeable. In the following test script sync(1) takes around 6
13 minutes when there are two ext4 filesystems mounted on a standard SATA
14 drive. After this patch sync takes a couple of seconds so we have about
15 two orders of magnitude improvement.
17       function run_writers
18       {
19         for (( i = 0; i < 10; i++ )); do
20           mkdir $1/dir$i
21           for (( j = 0; j < 40000; j++ )); do
22             dd if=/dev/zero of=$1/dir$i/$j bs=4k count=4 &>/dev/null
23           done &
24         done
25       }
27       for dir in "$@"; do
28         run_writers $dir
29       done
31       sleep 40
32       time sync
34 Signed-off-by: Jan Kara <jack@suse.cz>
35 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
36 ---
37  fs/ext4/inode.c | 13 +++++++++++--
38  1 file changed, 11 insertions(+), 2 deletions(-)
40 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
41 index 6e39895a91b8..7850584b0679 100644
42 --- a/fs/ext4/inode.c
43 +++ b/fs/ext4/inode.c
44 @@ -4443,7 +4443,12 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
45                         return -EIO;
46                 }
48 -               if (wbc->sync_mode != WB_SYNC_ALL)
49 +               /*
50 +                * No need to force transaction in WB_SYNC_NONE mode. Also
51 +                * ext4_sync_fs() will force the commit after everything is
52 +                * written.
53 +                */
54 +               if (wbc->sync_mode != WB_SYNC_ALL || wbc->for_sync)
55                         return 0;
57                 err = ext4_force_commit(inode->i_sb);
58 @@ -4453,7 +4458,11 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
59                 err = __ext4_get_inode_loc(inode, &iloc, 0);
60                 if (err)
61                         return err;
62 -               if (wbc->sync_mode == WB_SYNC_ALL)
63 +               /*
64 +                * sync(2) will flush the whole buffer cache. No need to do
65 +                * it here separately for each inode.
66 +                */
67 +               if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync)
68                         sync_dirty_buffer(iloc.bh);
69                 if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
70                         EXT4_ERROR_INODE_BLOCK(inode, iloc.bh->b_blocknr,
71 -- 
72 1.8.1.4
75 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
76 the body of a message to majordomo@vger.kernel.org
77 More majordomo info at  http://vger.kernel.org/majordomo-info.html