Skip to content

Commit 15c8276

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Remove 1st shrink/grow phase from balance
The first step of the rebalance process ensures there is 1MiB free on each device. This number seems rather small. And in fact when talking to the original authors their opinions were: "man that's a little bonkers" "i don't think we even need that code anymore" "I think it was there to make sure we had room for the blank 1M at the beginning. I bet it goes all the way back to v0" "we just don't need any of that tho, i say we just delete it" Clearly, this piece of code has lost its original intent throughout the years. It doesn't really bring any real practical benefits to the relocation process. Additionally, this patch makes the balance process more lightweight by removing a pair of shrink/grow operations which are rather expensive for heavily populated filesystems. This is mainly due to shrink requiring relocating block groups, involving heavy use of the btree. The intermediate shrink/grow can fail and leave the filesystem in a middle state that would need to be changed back by the user. Suggested-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> [ update changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent be6821f commit 15c8276

File tree

1 file changed

+0
-53
lines changed

1 file changed

+0
-53
lines changed

fs/btrfs/volumes.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,17 +3700,11 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
37003700
{
37013701
struct btrfs_balance_control *bctl = fs_info->balance_ctl;
37023702
struct btrfs_root *chunk_root = fs_info->chunk_root;
3703-
struct btrfs_root *dev_root = fs_info->dev_root;
3704-
struct list_head *devices;
3705-
struct btrfs_device *device;
3706-
u64 old_size;
3707-
u64 size_to_free;
37083703
u64 chunk_type;
37093704
struct btrfs_chunk *chunk;
37103705
struct btrfs_path *path = NULL;
37113706
struct btrfs_key key;
37123707
struct btrfs_key found_key;
3713-
struct btrfs_trans_handle *trans;
37143708
struct extent_buffer *leaf;
37153709
int slot;
37163710
int ret;
@@ -3725,53 +3719,6 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
37253719
u32 count_sys = 0;
37263720
int chunk_reserved = 0;
37273721

3728-
/* step one make some room on all the devices */
3729-
devices = &fs_info->fs_devices->devices;
3730-
list_for_each_entry(device, devices, dev_list) {
3731-
old_size = btrfs_device_get_total_bytes(device);
3732-
size_to_free = div_factor(old_size, 1);
3733-
size_to_free = min_t(u64, size_to_free, SZ_1M);
3734-
if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) ||
3735-
btrfs_device_get_total_bytes(device) -
3736-
btrfs_device_get_bytes_used(device) > size_to_free ||
3737-
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
3738-
continue;
3739-
3740-
ret = btrfs_shrink_device(device, old_size - size_to_free);
3741-
if (ret == -ENOSPC)
3742-
break;
3743-
if (ret) {
3744-
/* btrfs_shrink_device never returns ret > 0 */
3745-
WARN_ON(ret > 0);
3746-
goto error;
3747-
}
3748-
3749-
trans = btrfs_start_transaction(dev_root, 0);
3750-
if (IS_ERR(trans)) {
3751-
ret = PTR_ERR(trans);
3752-
btrfs_info_in_rcu(fs_info,
3753-
"resize: unable to start transaction after shrinking device %s (error %d), old size %llu, new size %llu",
3754-
rcu_str_deref(device->name), ret,
3755-
old_size, old_size - size_to_free);
3756-
goto error;
3757-
}
3758-
3759-
ret = btrfs_grow_device(trans, device, old_size);
3760-
if (ret) {
3761-
btrfs_end_transaction(trans);
3762-
/* btrfs_grow_device never returns ret > 0 */
3763-
WARN_ON(ret > 0);
3764-
btrfs_info_in_rcu(fs_info,
3765-
"resize: unable to grow device after shrinking device %s (error %d), old size %llu, new size %llu",
3766-
rcu_str_deref(device->name), ret,
3767-
old_size, old_size - size_to_free);
3768-
goto error;
3769-
}
3770-
3771-
btrfs_end_transaction(trans);
3772-
}
3773-
3774-
/* step two, relocate all the chunks */
37753722
path = btrfs_alloc_path();
37763723
if (!path) {
37773724
ret = -ENOMEM;

0 commit comments

Comments
 (0)