diff options
author | Josef Bacik <josef@redhat.com> | 2010-10-15 15:18:40 -0400 |
---|---|---|
committer | Josef Bacik <josef@redhat.com> | 2010-10-22 15:54:58 -0400 |
commit | 0019f10db6f596f3e14a19f9bd7059a1b85b0853 (patch) | |
tree | 9f295bc2e335a6890ea29bc0830bda43903671d9 /fs/btrfs/extent-tree.c | |
parent | 6d48755d02b150de7f47e7b4753202f2fc9f990f (diff) |
Btrfs: re-work delalloc flushing
Currently we try and flush delalloc, but we only do that in a sort of weak way,
which works fine in most cases but if we're under heavy pressure we need to be
able to wait for flushing to happen. Also instead of checking the bytes
reserved in the block_rsv, check the space info since it is more accurate. The
sync option will be used in a future patch.
Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0f27f7b48804..2846cebc9427 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3111,9 +3111,10 @@ static int maybe_allocate_chunk(struct btrfs_trans_handle *trans, | |||
3111 | * shrink metadata reservation for delalloc | 3111 | * shrink metadata reservation for delalloc |
3112 | */ | 3112 | */ |
3113 | static int shrink_delalloc(struct btrfs_trans_handle *trans, | 3113 | static int shrink_delalloc(struct btrfs_trans_handle *trans, |
3114 | struct btrfs_root *root, u64 to_reclaim) | 3114 | struct btrfs_root *root, u64 to_reclaim, int sync) |
3115 | { | 3115 | { |
3116 | struct btrfs_block_rsv *block_rsv; | 3116 | struct btrfs_block_rsv *block_rsv; |
3117 | struct btrfs_space_info *space_info; | ||
3117 | u64 reserved; | 3118 | u64 reserved; |
3118 | u64 max_reclaim; | 3119 | u64 max_reclaim; |
3119 | u64 reclaimed = 0; | 3120 | u64 reclaimed = 0; |
@@ -3122,9 +3123,10 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans, | |||
3122 | int ret; | 3123 | int ret; |
3123 | 3124 | ||
3124 | block_rsv = &root->fs_info->delalloc_block_rsv; | 3125 | block_rsv = &root->fs_info->delalloc_block_rsv; |
3125 | spin_lock(&block_rsv->lock); | 3126 | space_info = block_rsv->space_info; |
3126 | reserved = block_rsv->reserved; | 3127 | spin_lock(&space_info->lock); |
3127 | spin_unlock(&block_rsv->lock); | 3128 | reserved = space_info->bytes_reserved; |
3129 | spin_unlock(&space_info->lock); | ||
3128 | 3130 | ||
3129 | if (reserved == 0) | 3131 | if (reserved == 0) |
3130 | return 0; | 3132 | return 0; |
@@ -3132,7 +3134,7 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans, | |||
3132 | max_reclaim = min(reserved, to_reclaim); | 3134 | max_reclaim = min(reserved, to_reclaim); |
3133 | 3135 | ||
3134 | while (1) { | 3136 | while (1) { |
3135 | ret = btrfs_start_one_delalloc_inode(root, trans ? 1 : 0); | 3137 | ret = btrfs_start_one_delalloc_inode(root, trans ? 1 : 0, sync); |
3136 | if (!ret) { | 3138 | if (!ret) { |
3137 | if (no_reclaim > 2) | 3139 | if (no_reclaim > 2) |
3138 | break; | 3140 | break; |
@@ -3147,11 +3149,11 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans, | |||
3147 | pause = 1; | 3149 | pause = 1; |
3148 | } | 3150 | } |
3149 | 3151 | ||
3150 | spin_lock(&block_rsv->lock); | 3152 | spin_lock(&space_info->lock); |
3151 | if (reserved > block_rsv->reserved) | 3153 | if (reserved > space_info->bytes_reserved) |
3152 | reclaimed = reserved - block_rsv->reserved; | 3154 | reclaimed += reserved - space_info->bytes_reserved; |
3153 | reserved = block_rsv->reserved; | 3155 | reserved = space_info->bytes_reserved; |
3154 | spin_unlock(&block_rsv->lock); | 3156 | spin_unlock(&space_info->lock); |
3155 | 3157 | ||
3156 | if (reserved == 0 || reclaimed >= max_reclaim) | 3158 | if (reserved == 0 || reclaimed >= max_reclaim) |
3157 | break; | 3159 | break; |
@@ -3180,7 +3182,7 @@ static int should_retry_reserve(struct btrfs_trans_handle *trans, | |||
3180 | if (trans && trans->transaction->in_commit) | 3182 | if (trans && trans->transaction->in_commit) |
3181 | return -ENOSPC; | 3183 | return -ENOSPC; |
3182 | 3184 | ||
3183 | ret = shrink_delalloc(trans, root, num_bytes); | 3185 | ret = shrink_delalloc(trans, root, num_bytes, 0); |
3184 | if (ret) | 3186 | if (ret) |
3185 | return ret; | 3187 | return ret; |
3186 | 3188 | ||
@@ -3729,7 +3731,7 @@ again: | |||
3729 | block_rsv_add_bytes(block_rsv, to_reserve, 1); | 3731 | block_rsv_add_bytes(block_rsv, to_reserve, 1); |
3730 | 3732 | ||
3731 | if (block_rsv->size > 512 * 1024 * 1024) | 3733 | if (block_rsv->size > 512 * 1024 * 1024) |
3732 | shrink_delalloc(NULL, root, to_reserve); | 3734 | shrink_delalloc(NULL, root, to_reserve, 0); |
3733 | 3735 | ||
3734 | return 0; | 3736 | return 0; |
3735 | } | 3737 | } |