btrfs: Minor improvements to should_alloc_chunk
PATCH 1/1 btrfs: Minor improvements to should_alloc_chunk
Since it's a predicate function make it explicitly return boolean. Also the 'thresh' variable is only used when force is CHUNK_ALLOC_LIMITED so reduce the scope of the variable as necessary. Finally, remove the + 2m used in the final check. Given the granularity of btrfs' allocation I doubt that the + 2m made a difference when making a decision whether to allocate a chunk or not.
--- fs/btrfs/block-group.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/btrfs/block-group.c +7 -8
@@ -3312,30 +3312,29 @@ static void force_metadata_allocation(struct btrfs_fs_info *info) } } -static int should_alloc_chunk (struct btrfs_fs_info *fs_info, +static bool should_alloc_chunk (struct btrfs_fs_info *fs_info,struct btrfs_space_info *sinfo,int force) {u64 bytes_used =btrfs_space_info_used (sinfo, false); -u64 thresh;if (force ==CHUNK_ALLOC_FORCE ) -return 1 ; +return true;/* * in limited mode, we want to have some free space up to * about 1% of the FS size. */ if (force ==CHUNK_ALLOC_LIMITED ) { - thresh =btrfs_super_total_bytes (fs_info->super_copy); +u64 thresh =btrfs_super_total_bytes (fs_info->super_copy); thresh =max_t (u64,SZ_64M ,div_factor_fine (thresh,1 ));if (sinfo->total_bytes - bytes_used < thresh) -return 1 ; +return true; } -if (bytes_used +SZ_2M <div_factor (sinfo->total_bytes,8 )) -return 0 ; -return 1 ; +if (bytes_used <div_factor (sinfo->total_bytes,8 )) +return false; +return true; }int btrfs_force_chunk_alloc (struct btrfs_trans_handle *trans,u64 type)
Signature · 1 line
2.17.1
Quoted 6 lines · Nikolay Borisov
Since it's a predicate function make it explicitly return boolean. Also the 'thresh' variable is only used when force is
CHUNK_ALLOC_LIMITEDso reduce the scope of the variable as necessary. Finally, remove the + 2m used in the final check. Given the granularity of btrfs' allocation I doubt that the + 2m made a difference when making a decision whether to allocate a chunk or not.
This is mixing 2 cleanups and potentially a functional change in one patch, "I doubt it made a difference" does not sound like a good reasoning, I can say that I doubt you're right so what now? :)
Doing the cleanups (return value and moving the scope) in one is probably fine, but the +2M change needs some explanation and should go to a separate patch.