diff options
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 52c5524896a3..66af5140c8ce 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -124,17 +124,12 @@ static noinline int record_root_in_trans(struct btrfs_root *root) | |||
124 | return 0; | 124 | return 0; |
125 | } | 125 | } |
126 | 126 | ||
127 | struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | 127 | static void wait_current_trans(struct btrfs_root *root) |
128 | int num_blocks, int join) | ||
129 | { | 128 | { |
130 | struct btrfs_trans_handle *h = | ||
131 | kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); | ||
132 | struct btrfs_transaction *cur_trans; | 129 | struct btrfs_transaction *cur_trans; |
133 | int ret; | ||
134 | 130 | ||
135 | mutex_lock(&root->fs_info->trans_mutex); | ||
136 | cur_trans = root->fs_info->running_transaction; | 131 | cur_trans = root->fs_info->running_transaction; |
137 | if (cur_trans && cur_trans->blocked && !join) { | 132 | if (cur_trans && cur_trans->blocked) { |
138 | DEFINE_WAIT(wait); | 133 | DEFINE_WAIT(wait); |
139 | cur_trans->use_count++; | 134 | cur_trans->use_count++; |
140 | while(1) { | 135 | while(1) { |
@@ -154,6 +149,18 @@ struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | |||
154 | } | 149 | } |
155 | put_transaction(cur_trans); | 150 | put_transaction(cur_trans); |
156 | } | 151 | } |
152 | } | ||
153 | |||
154 | struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | ||
155 | int num_blocks, int join) | ||
156 | { | ||
157 | struct btrfs_trans_handle *h = | ||
158 | kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); | ||
159 | int ret; | ||
160 | |||
161 | mutex_lock(&root->fs_info->trans_mutex); | ||
162 | if (!join) | ||
163 | wait_current_trans(root); | ||
157 | ret = join_transaction(root); | 164 | ret = join_transaction(root); |
158 | BUG_ON(ret); | 165 | BUG_ON(ret); |
159 | 166 | ||
@@ -200,7 +207,7 @@ static noinline int wait_for_commit(struct btrfs_root *root, | |||
200 | return 0; | 207 | return 0; |
201 | } | 208 | } |
202 | 209 | ||
203 | void btrfs_throttle(struct btrfs_root *root) | 210 | static void throttle_on_drops(struct btrfs_root *root) |
204 | { | 211 | { |
205 | struct btrfs_fs_info *info = root->fs_info; | 212 | struct btrfs_fs_info *info = root->fs_info; |
206 | 213 | ||
@@ -223,19 +230,28 @@ harder: | |||
223 | } while (thr == atomic_read(&info->throttle_gen)); | 230 | } while (thr == atomic_read(&info->throttle_gen)); |
224 | 231 | ||
225 | if (harder_count < 5 && | 232 | if (harder_count < 5 && |
226 | info->total_ref_cache_size > 5 * 1024 * 1024) { | 233 | info->total_ref_cache_size > 1 * 1024 * 1024) { |
227 | harder_count++; | 234 | harder_count++; |
228 | goto harder; | 235 | goto harder; |
229 | } | 236 | } |
230 | 237 | ||
231 | if (harder_count < 10 && | 238 | if (harder_count < 10 && |
232 | info->total_ref_cache_size > 10 * 1024 * 1024) { | 239 | info->total_ref_cache_size > 5 * 1024 * 1024) { |
233 | harder_count++; | 240 | harder_count++; |
234 | goto harder; | 241 | goto harder; |
235 | } | 242 | } |
236 | } | 243 | } |
237 | } | 244 | } |
238 | 245 | ||
246 | void btrfs_throttle(struct btrfs_root *root) | ||
247 | { | ||
248 | mutex_lock(&root->fs_info->trans_mutex); | ||
249 | wait_current_trans(root); | ||
250 | mutex_unlock(&root->fs_info->trans_mutex); | ||
251 | |||
252 | throttle_on_drops(root); | ||
253 | } | ||
254 | |||
239 | static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, | 255 | static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, |
240 | struct btrfs_root *root, int throttle) | 256 | struct btrfs_root *root, int throttle) |
241 | { | 257 | { |
@@ -256,7 +272,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, | |||
256 | kmem_cache_free(btrfs_trans_handle_cachep, trans); | 272 | kmem_cache_free(btrfs_trans_handle_cachep, trans); |
257 | 273 | ||
258 | if (throttle) | 274 | if (throttle) |
259 | btrfs_throttle(root); | 275 | throttle_on_drops(root); |
260 | 276 | ||
261 | return 0; | 277 | return 0; |
262 | } | 278 | } |