aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/relocation.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2010-10-15 16:52:49 -0400
committerJosef Bacik <josef@redhat.com>2010-10-22 15:55:01 -0400
commit8bb8ab2e93f9c3c9453e13be0f37d344a32a3a6d (patch)
tree619600c7458a3af18555f189d53efc4c092b9280 /fs/btrfs/relocation.c
parent14ed0ca6e8236f2d264c4a8faec9e3a2b3d04377 (diff)
Btrfs: rework how we reserve metadata bytes
With multi-threaded writes we were getting ENOSPC early because somebody would come in, start flushing delalloc because they couldn't make their reservation, and in the meantime other threads would come in and use the space that was getting freed up, so when the original thread went to check to see if they had space they didn't and they'd return ENOSPC. So instead if we have some free space but not enough for our reservation, take the reservation and then start doing the flushing. The only time we don't take reservations is when we've already overcommitted our space, that way we don't have people who come late to the party way overcommitting ourselves. This also moves all of the retrying and flushing code into reserve_metdata_bytes so it's all uniform. This keeps my fs_mark test from returning -ENOSPC as soon as it starts and actually lets me fill up the disk. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs/relocation.c')
-rw-r--r--fs/btrfs/relocation.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b37d723b9d4a..39adb68a653f 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -178,8 +178,6 @@ struct reloc_control {
178 u64 search_start; 178 u64 search_start;
179 u64 extents_found; 179 u64 extents_found;
180 180
181 int block_rsv_retries;
182
183 unsigned int stage:8; 181 unsigned int stage:8;
184 unsigned int create_reloc_tree:1; 182 unsigned int create_reloc_tree:1;
185 unsigned int merge_reloc_tree:1; 183 unsigned int merge_reloc_tree:1;
@@ -2133,7 +2131,6 @@ int prepare_to_merge(struct reloc_control *rc, int err)
2133 LIST_HEAD(reloc_roots); 2131 LIST_HEAD(reloc_roots);
2134 u64 num_bytes = 0; 2132 u64 num_bytes = 0;
2135 int ret; 2133 int ret;
2136 int retries = 0;
2137 2134
2138 mutex_lock(&root->fs_info->trans_mutex); 2135 mutex_lock(&root->fs_info->trans_mutex);
2139 rc->merging_rsv_size += root->nodesize * (BTRFS_MAX_LEVEL - 1) * 2; 2136 rc->merging_rsv_size += root->nodesize * (BTRFS_MAX_LEVEL - 1) * 2;
@@ -2143,7 +2140,7 @@ again:
2143 if (!err) { 2140 if (!err) {
2144 num_bytes = rc->merging_rsv_size; 2141 num_bytes = rc->merging_rsv_size;
2145 ret = btrfs_block_rsv_add(NULL, root, rc->block_rsv, 2142 ret = btrfs_block_rsv_add(NULL, root, rc->block_rsv,
2146 num_bytes, &retries); 2143 num_bytes);
2147 if (ret) 2144 if (ret)
2148 err = ret; 2145 err = ret;
2149 } 2146 }
@@ -2155,7 +2152,6 @@ again:
2155 btrfs_end_transaction(trans, rc->extent_root); 2152 btrfs_end_transaction(trans, rc->extent_root);
2156 btrfs_block_rsv_release(rc->extent_root, 2153 btrfs_block_rsv_release(rc->extent_root,
2157 rc->block_rsv, num_bytes); 2154 rc->block_rsv, num_bytes);
2158 retries = 0;
2159 goto again; 2155 goto again;
2160 } 2156 }
2161 } 2157 }
@@ -2405,15 +2401,13 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans,
2405 num_bytes = calcu_metadata_size(rc, node, 1) * 2; 2401 num_bytes = calcu_metadata_size(rc, node, 1) * 2;
2406 2402
2407 trans->block_rsv = rc->block_rsv; 2403 trans->block_rsv = rc->block_rsv;
2408 ret = btrfs_block_rsv_add(trans, root, rc->block_rsv, num_bytes, 2404 ret = btrfs_block_rsv_add(trans, root, rc->block_rsv, num_bytes);
2409 &rc->block_rsv_retries);
2410 if (ret) { 2405 if (ret) {
2411 if (ret == -EAGAIN) 2406 if (ret == -EAGAIN)
2412 rc->commit_transaction = 1; 2407 rc->commit_transaction = 1;
2413 return ret; 2408 return ret;
2414 } 2409 }
2415 2410
2416 rc->block_rsv_retries = 0;
2417 return 0; 2411 return 0;
2418} 2412}
2419 2413
@@ -3554,8 +3548,7 @@ int prepare_to_relocate(struct reloc_control *rc)
3554 * is no reservation in transaction handle. 3548 * is no reservation in transaction handle.
3555 */ 3549 */
3556 ret = btrfs_block_rsv_add(NULL, rc->extent_root, rc->block_rsv, 3550 ret = btrfs_block_rsv_add(NULL, rc->extent_root, rc->block_rsv,
3557 rc->extent_root->nodesize * 256, 3551 rc->extent_root->nodesize * 256);
3558 &rc->block_rsv_retries);
3559 if (ret) 3552 if (ret)
3560 return ret; 3553 return ret;
3561 3554
@@ -3567,7 +3560,6 @@ int prepare_to_relocate(struct reloc_control *rc)
3567 rc->extents_found = 0; 3560 rc->extents_found = 0;
3568 rc->nodes_relocated = 0; 3561 rc->nodes_relocated = 0;
3569 rc->merging_rsv_size = 0; 3562 rc->merging_rsv_size = 0;
3570 rc->block_rsv_retries = 0;
3571 3563
3572 rc->create_reloc_tree = 1; 3564 rc->create_reloc_tree = 1;
3573 set_reloc_control(rc); 3565 set_reloc_control(rc);