1 From 8c48f7e88e293b9dd422bd8884842aea85d30b22
2 Subject: [PATCH] ext4: optimize ext4_find_delalloc_range() in nodelalloc mode
4 We found performance regression when using bigalloc with "nodelalloc"
7 1. mke2fs -C 1048576 -O ^has_journal,bigalloc /dev/sda
8 2. mount -o nodelalloc /dev/sda /test/
9 3. time dd if=/dev/zero of=/test/io bs=1048576 count=1024
11 The "dd" will cost about 2 seconds to finish, but if we mke2fs without
12 "bigalloc", "dd" will only cost less than 1 second.
14 The reason is: when using ext4 with "nodelalloc", it will call
15 ext4_find_delalloc_cluster() nearly everytime it call
16 ext4_ext_map_blocks(), and ext4_find_delalloc_range() will also scan
17 all pages in cluster because no buffer is "delayed". A cluster has
18 256 pages (1MB cluster), so it will scan 256 * 256k pags when creating
19 a 1G file. That severely hurts the performance.
21 Therefore, we return immediately from ext4_find_delalloc_range() in
22 nodelalloc mode, since by definition there can't be any delalloc
25 Signed-off-by: Robin Dong <sanbai@taobao.com>
26 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
28 fs/ext4/extents.c | 3 +++
29 1 file changed, 3 insertions(+)
31 Index: linux-stage/fs/ext4/extents.c
32 ===================================================================
33 --- linux-stage.orig/fs/ext4/extents.c
34 +++ linux-stage/fs/ext4/extents.c
35 @@ -3909,6 +3909,9 @@ int ext4_find_delalloc_range(struct inod
37 struct extent_status es;
39 + if (!test_opt(inode->i_sb, DELALLOC))
42 ext4_es_find_delayed_extent_range(inode, lblk_start, lblk_end, &es);
44 return 0; /* there is no delay extent in this tree */
45 @@ -5115,6 +5118,9 @@ static int ext4_find_delayed_extent(stru
46 struct extent_status es;
47 ext4_lblk_t block, next_del;
49 + if (!test_opt(inode->i_sb, DELALLOC))
52 if (newes->es_pblk == 0) {
53 ext4_es_find_delayed_extent_range(inode, newes->es_lblk,
54 newes->es_lblk + newes->es_len - 1, &es);