More commit description fixups
[ext4-patch-queue.git] / JC2-journal_credit_for_extents_fix.patch
blob8ae6cb5cccb43adce9a4e0cdc5bbd24424d36433
1 ext4: journal credits reservation fixes for extent file writepage
3 From: Mingming Cao <cmm@us.ibm.com>
5 This patch modified the writepage/write_begin credit calculation for
6 extent files, to use the credits caculation helper function.
8 The current calculation of how many index/leaf blocks should be
9 accounted is too conservetive, it always considered the worse case,
10 where the tree level is 5, and in the case of multiple chunk
11 allocations, it always assumed no blocks were dirtied in common across
12 the allocations. This path uses the accurate depth of the inode with
13 some extras to calculate the index blocks, and also less conservative in
14 the case of multiple allocation accounting.
16 Signed-off-by: Mingming Cao <cmm@us.ibm.com>
17 Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
18 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
19 ---
20 fs/ext4/ext4_extents.h | 3 +
21 fs/ext4/extents.c | 88 ++++++++++++++++---------------------------------
22 fs/ext4/migrate.c | 3 +
23 3 files changed, 34 insertions(+), 60 deletions(-)
25 Index: linux-2.6.27-rc3/fs/ext4/ext4_extents.h
26 ===================================================================
27 --- linux-2.6.27-rc3.orig/fs/ext4/ext4_extents.h 2008-08-18 12:17:01.000000000 -0700
28 +++ linux-2.6.27-rc3/fs/ext4/ext4_extents.h 2008-08-18 12:17:16.000000000 -0700
29 @@ -216,7 +216,9 @@ extern int ext4_ext_calc_metadata_amount
30 extern ext4_fsblk_t idx_pblock(struct ext4_extent_idx *);
31 extern void ext4_ext_store_pblock(struct ext4_extent *, ext4_fsblk_t);
32 extern int ext4_extent_tree_init(handle_t *, struct inode *);
33 -extern int ext4_ext_calc_credits_for_insert(struct inode *, struct ext4_ext_path *);
34 +extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
35 + int num,
36 + struct ext4_ext_path *path);
37 extern int ext4_ext_try_to_merge(struct inode *inode,
38 struct ext4_ext_path *path,
39 struct ext4_extent *);
40 Index: linux-2.6.27-rc3/fs/ext4/extents.c
41 ===================================================================
42 --- linux-2.6.27-rc3.orig/fs/ext4/extents.c 2008-08-18 12:17:01.000000000 -0700
43 +++ linux-2.6.27-rc3/fs/ext4/extents.c 2008-08-18 12:28:52.000000000 -0700
44 @@ -1747,54 +1747,61 @@ static int ext4_ext_rm_idx(handle_t *han
48 - * ext4_ext_calc_credits_for_insert:
49 - * This routine returns max. credits that the extent tree can consume.
50 - * It should be OK for low-performance paths like ->writepage()
51 - * To allow many writing processes to fit into a single transaction,
52 - * the caller should calculate credits under i_data_sem and
53 - * pass the actual path.
54 + * ext4_ext_calc_credits_for_single_extent:
55 + * This routine returns max. credits that needed to insert an extent
56 + * to the extent tree.
57 + * When pass the actual path, the caller should calculate credits
58 + * under i_data_sem.
60 -int ext4_ext_calc_credits_for_insert(struct inode *inode,
61 +int ext4_ext_calc_credits_for_single_extent(struct inode *inode, int num,
62 struct ext4_ext_path *path)
64 - int depth, needed;
66 if (path) {
67 + int depth = ext_depth(inode);
68 + int ret;
70 /* probably there is space in leaf? */
71 - depth = ext_depth(inode);
72 if (le16_to_cpu(path[depth].p_hdr->eh_entries)
73 - < le16_to_cpu(path[depth].p_hdr->eh_max))
74 - return 1;
75 - }
76 + < le16_to_cpu(path[depth].p_hdr->eh_max)) {
78 - /*
79 - * given 32-bit logical block (4294967296 blocks), max. tree
80 - * can be 4 levels in depth -- 4 * 340^4 == 53453440000.
81 - * Let's also add one more level for imbalance.
82 - */
83 - depth = 5;
85 - /* allocation of new data block(s) */
86 - needed = 2;
87 + /*
88 + * There are some space in the leaf tree, no
89 + * need to account for leaf block credit
90 + *
91 + * bitmaps and block group descriptor blocks
92 + * and other metadat blocks still need to be
93 + * accounted.
94 + */
95 + /* 1 one bitmap, 1 block group descriptor */
96 + ret = 2 + EXT4_META_TRANS_BLOCKS(inode->i_sb);
97 + }
98 + }
100 - /*
101 - * tree can be full, so it would need to grow in depth:
102 - * we need one credit to modify old root, credits for
103 - * new root will be added in split accounting
104 - */
105 - needed += 1;
106 + return ext4_meta_trans_blocks(inode, num, 1);
109 - /*
110 - * Index split can happen, we would need:
111 - * allocate intermediate indexes (bitmap + group)
112 - * + change two blocks at each level, but root (already included)
113 - */
114 - needed += (depth * 2) + (depth * 2);
116 + * How many index/leaf blocks need to change/allocate to modify nrblocks?
118 + * if nrblocks are fit in a single extent (chunk flag is 1), then
119 + * in the worse case, each tree level index/leaf need to be changed
120 + * if the tree split due to insert a new extent, then the old tree
121 + * index/leaf need to be updated too
123 + * If the nrblocks are discontiguous, they could cause
124 + * the whole tree split more than once, but this is really rare.
125 + */
126 +int ext4_ext_index_trans_blocks(struct inode *inode, int num, int chunk)
128 + int index;
129 + int depth = ext_depth(inode);
131 - /* any allocation modifies superblock */
132 - needed += 1;
133 + if (chunk)
134 + index = depth * 2;
135 + else
136 + index = depth * 3;
138 - return needed;
139 + return index;
142 static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
143 @@ -1921,9 +1928,7 @@ ext4_ext_rm_leaf(handle_t *handle, struc
144 correct_index = 1;
145 credits += (ext_depth(inode)) + 1;
147 -#ifdef CONFIG_QUOTA
148 credits += 2 * EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb);
149 -#endif
151 err = ext4_ext_journal_restart(handle, credits);
152 if (err)
153 @@ -2858,27 +2863,6 @@ out_stop:
154 ext4_journal_stop(handle);
158 - * ext4_ext_writepage_trans_blocks:
159 - * calculate max number of blocks we could modify
160 - * in order to allocate new block for an inode
161 - */
162 -int ext4_ext_writepage_trans_blocks(struct inode *inode, int num)
164 - int needed;
166 - needed = ext4_ext_calc_credits_for_insert(inode, NULL);
168 - /* caller wants to allocate num blocks, but note it includes sb */
169 - needed = needed * num - (num - 1);
171 -#ifdef CONFIG_QUOTA
172 - needed += 2 * EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb);
173 -#endif
175 - return needed;
178 static void ext4_falloc_update_inode(struct inode *inode,
179 int mode, loff_t new_size, int update_ctime)
181 Index: linux-2.6.27-rc3/fs/ext4/migrate.c
182 ===================================================================
183 --- linux-2.6.27-rc3.orig/fs/ext4/migrate.c 2008-08-18 12:17:01.000000000 -0700
184 +++ linux-2.6.27-rc3/fs/ext4/migrate.c 2008-08-18 12:17:16.000000000 -0700
185 @@ -53,7 +53,8 @@ static int finish_range(handle_t *handle
186 * credit. But below we try to not accumalate too much
187 * of them by restarting the journal.
189 - needed = ext4_ext_calc_credits_for_insert(inode, path);
190 + needed = ext4_ext_calc_credits_for_single_extent(inode,
191 + lb->last_block - lb->first_block + 1, path);
194 * Make sure the credit we accumalated is not really high