Skip to content

Commit c84053d

Browse files
adam900710kdave
authored andcommitted
btrfs: update per-profile available estimation
This involves the following timing: - Chunk allocation - Chunk removal - After Mount - New device - Device removal - Device shrink - Device enlarge And since the function btrfs_update_per_profile_avail() will not return an error, this won't cause new error handling path. Although when btrfs_update_per_profile_avail() failed (only ENOSPC possible) it will mark the per-profile available estimation as unreliable, so later btrfs_get_per_profile_avail() will return false and require the caller to have a fallback solution. The function btrfs_update_per_profile_avail() will be executed with chunk_mutex hold, thus it will slightly slow down those involved functions, but not a lot. As all the core workload is just various u64 calculations inside a loop, without any tree search, the overhead should be acceptable even for all supported 9 profiles. For 4 disks (which exercises all 9 profiles), the execution time of that function will still be less than 10 us. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 52fead5 commit c84053d

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

fs/btrfs/volumes.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
23402340
mutex_lock(&fs_info->chunk_mutex);
23412341
list_del_init(&device->dev_alloc_list);
23422342
device->fs_devices->rw_devices--;
2343+
btrfs_update_per_profile_avail(fs_info);
23432344
mutex_unlock(&fs_info->chunk_mutex);
23442345
}
23452346

@@ -2451,6 +2452,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
24512452
list_add(&device->dev_alloc_list,
24522453
&fs_devices->alloc_list);
24532454
device->fs_devices->rw_devices++;
2455+
btrfs_update_per_profile_avail(fs_info);
24542456
mutex_unlock(&fs_info->chunk_mutex);
24552457
}
24562458
return ret;
@@ -2938,6 +2940,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
29382940
*/
29392941
btrfs_clear_space_info_full(fs_info);
29402942

2943+
btrfs_update_per_profile_avail(fs_info);
29412944
mutex_unlock(&fs_info->chunk_mutex);
29422945

29432946
/* Add sysfs device entry */
@@ -2948,6 +2951,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
29482951
if (seeding_dev) {
29492952
mutex_lock(&fs_info->chunk_mutex);
29502953
ret = init_first_rw_device(trans);
2954+
btrfs_update_per_profile_avail(fs_info);
29512955
mutex_unlock(&fs_info->chunk_mutex);
29522956
if (unlikely(ret)) {
29532957
btrfs_abort_transaction(trans, ret);
@@ -3030,6 +3034,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
30303034
orig_super_total_bytes);
30313035
btrfs_set_super_num_devices(fs_info->super_copy,
30323036
orig_super_num_devices);
3037+
btrfs_update_per_profile_avail(fs_info);
30333038
mutex_unlock(&fs_info->chunk_mutex);
30343039
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
30353040
error_trans:
@@ -3122,6 +3127,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
31223127
if (list_empty(&device->post_commit_list))
31233128
list_add_tail(&device->post_commit_list,
31243129
&trans->transaction->dev_update_list);
3130+
btrfs_update_per_profile_avail(fs_info);
31253131
mutex_unlock(&fs_info->chunk_mutex);
31263132

31273133
btrfs_reserve_chunk_metadata(trans, false);
@@ -3498,6 +3504,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
34983504
}
34993505
}
35003506

3507+
btrfs_update_per_profile_avail(fs_info);
35013508
mutex_unlock(&fs_info->chunk_mutex);
35023509
trans->removing_chunk = false;
35033510

@@ -5201,6 +5208,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
52015208
atomic64_sub(free_diff, &fs_info->free_chunk_space);
52025209
}
52035210

5211+
btrfs_update_per_profile_avail(fs_info);
52045212
/*
52055213
* Once the device's size has been set to the new size, ensure all
52065214
* in-memory chunks are synced to disk so that the loop below sees them
@@ -5316,6 +5324,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
53165324
WARN_ON(diff > old_total);
53175325
btrfs_set_super_total_bytes(super_copy,
53185326
round_down(old_total - diff, fs_info->sectorsize));
5327+
btrfs_update_per_profile_avail(fs_info);
53195328
mutex_unlock(&fs_info->chunk_mutex);
53205329

53215330
btrfs_reserve_chunk_metadata(trans, false);
@@ -6028,6 +6037,8 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
60286037
check_raid56_incompat_flag(info, type);
60296038
check_raid1c34_incompat_flag(info, type);
60306039

6040+
btrfs_update_per_profile_avail(info);
6041+
60316042
return block_group;
60326043
}
60336044

@@ -8603,7 +8614,14 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
86038614
}
86048615

86058616
/* Ensure all chunks have corresponding dev extents */
8606-
return verify_chunk_dev_extent_mapping(fs_info);
8617+
ret = verify_chunk_dev_extent_mapping(fs_info);
8618+
if (ret < 0)
8619+
return ret;
8620+
8621+
mutex_lock(&fs_info->chunk_mutex);
8622+
btrfs_update_per_profile_avail(fs_info);
8623+
mutex_unlock(&fs_info->chunk_mutex);
8624+
return 0;
86078625
}
86088626

86098627
/*

0 commit comments

Comments
 (0)