btrfs: minor block group cleanups
cover btrfs: minor block group cleanups
Minor cleanup patches.
1/3 cleansup the return value of btrfs_return_cluster_to_free_space(). 2/3 and 3/3 together cleanups block group reference count.
2/3 and 3/3 are related. However 1/3 is independent to the rest of the patches in this set.
Anand Jain (3):
btrfs: fix btrfs_return_cluster_to_free_space() return
btrfs: rename btrfs_block_group::count
btrfs: use helper btrfs_get_block_group
fs/btrfs/block-group.c | 8 ++++---- fs/btrfs/block-group.h | 2 +- fs/btrfs/free-space-cache.c | 17 +++++++---------- fs/btrfs/free-space-cache.h | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 btrfs: fix btrfs_return_cluster_to_free_space() return
__btrfs_return_cluster_to_free_space() returns only 0. And all its parent functions don't need the return value either so make this a void function.
Further, as none of the callers of btrfs_return_cluster_to_free_space() is actually using the return from this function, make this function also return void.
--- fs/btrfs/free-space-cache.c | 13 +++++-------- fs/btrfs/free-space-cache.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-)
fs/btrfs/free-space-cache.c +5 -8
@@ -2703,7 +2703,7 @@ void btrfs_init_free_space_ctl(struct btrfs_block_group *block_group)* pointed to by the cluster, someone else raced in and freed the * cluster already. In that case, we just return without changing anything */ -static int +static void __btrfs_return_cluster_to_free_space (struct btrfs_block_group *block_group,struct btrfs_free_cluster *cluster)
@@ -2756,7 +2756,6 @@ __btrfs_return_cluster_to_free_space( out:spin_unlock (&cluster->lock);btrfs_put_block_group (block_group); -return 0 ; } static void __btrfs_remove_free_space_cache_locked(
@@ -2907,12 +2906,11 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group,* Otherwise, it'll get a reference on the block group pointed to by the * cluster and remove the cluster from it. */ -int btrfs_return_cluster_to_free_space ( +void btrfs_return_cluster_to_free_space (struct btrfs_block_group *block_group,struct btrfs_free_cluster *cluster) {struct btrfs_free_space_ctl *ctl; -int ret;/* first, get a safe pointer to the block group */ spin_lock (&cluster->lock);
@@ -2920,12 +2918,12 @@ int btrfs_return_cluster_to_free_space( block_group = cluster->block_group;if (!block_group) {spin_unlock (&cluster->lock); -return 0 ; +return ; } }else if (cluster->block_group != block_group) {/* someone else has already freed it don't redo their work */ spin_unlock (&cluster->lock); -return 0 ; +return ; }atomic_inc (&block_group->count);spin_unlock (&cluster->lock);
@@ -2934,14 +2932,13 @@ int btrfs_return_cluster_to_free_space(/* now return any extents the cluster had on it */ spin_lock (&ctl->tree_lock); - ret =__btrfs_return_cluster_to_free_space (block_group, cluster); +__btrfs_return_cluster_to_free_space (block_group, cluster);spin_unlock (&ctl->tree_lock);btrfs_discard_queue_work (&block_group->fs_info->discard_ctl, block_group);/* finally drop our ref */ btrfs_put_block_group (block_group); -return ret; } static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group *block_group,
fs/btrfs/free-space-cache.h +1 -1
@@ -136,7 +136,7 @@ void btrfs_init_free_cluster(struct btrfs_free_cluster *cluster);u64 btrfs_alloc_from_cluster (struct btrfs_block_group *block_group,struct btrfs_free_cluster *cluster,u64 bytes,u64 min_start,u64 *max_extent_size); -int btrfs_return_cluster_to_free_space ( +void btrfs_return_cluster_to_free_space (struct btrfs_block_group *block_group,struct btrfs_free_cluster *cluster); int btrfs_trim_block_group(struct btrfs_block_group *block_group,
Signature · 1 line
2.25.1
Re: [PATCH 1/3] btrfs: fix btrfs_return_cluster_to_free_space() return
Quoted 8 lines · Anand Jain
__btrfs_return_cluster_to_free_space()returns only 0. And all its parent functions don't need the return value either so make this a void function.Further, as none of the callers of
btrfs_return_cluster_to_free_space()is actually using the return from this function, make this function also return void.Signed-off-by Anand Jain <[email protected]>
Re: [PATCH 1/3] btrfs: fix btrfs_return_cluster_to_free_space() return
In reply to Anand JainLooks good,
PATCH 2/3 btrfs: rename btrfs_block_group::count
In reply to Anand JainThe name 'count' is a very commonly used name. It is often difficult to review the code to check if there is any leak. So rename it to 'bg_count', which is unique enough.
This patch also serves as a preparatory patch to either make sure btrfs_get_block_group() is used instead of open coded the same or just open code every where as btrfs_get_block_group() is a one-liner.
--- fs/btrfs/block-group.c | 8 ++++---- fs/btrfs/block-group.h | 2 +- fs/btrfs/free-space-cache.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
fs/btrfs/block-group.c +4 -4
@@ -118,12 +118,12 @@ u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)void btrfs_get_block_group (struct btrfs_block_group *cache) { -atomic_inc (&cache->count); +atomic_inc (&cache->bg_count); }void btrfs_put_block_group (struct btrfs_block_group *cache) { -if (atomic_dec_and_test (&cache->count)) { +if (atomic_dec_and_test (&cache->bg_count)) {WARN_ON (cache->pinned >0 );WARN_ON (cache->reserved >0 );
@@ -1805,7 +1805,7 @@ static struct btrfs_block_group *btrfs_create_block_group_cache( cache->discard_index =BTRFS_DISCARD_INDEX_UNUSED ; -atomic_set (&cache->count,1 ); +atomic_set (&cache->bg_count,1 );spin_lock_init (&cache->lock);init_rwsem (&cache->data_rwsem);INIT_LIST_HEAD (&cache->list);
@@ -3379,7 +3379,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)ASSERT (list_empty (&block_group->dirty_list));ASSERT (list_empty (&block_group->io_list));ASSERT (list_empty (&block_group->bg_list)); -ASSERT (atomic_read (&block_group->count) ==1 ); +ASSERT (atomic_read (&block_group->bg_count) ==1 );btrfs_put_block_group (block_group);spin_lock (&info->block_group_cache_lock);
fs/btrfs/block-group.h +1 -1
@@ -115,7 +115,7 @@ struct btrfs_block_group {struct list_head list;/* Usage count */ -atomic_t count; +atomic_t bg_count;/* * List of struct btrfs_free_clusters for this block group.
fs/btrfs/free-space-cache.c +2 -2
@@ -2925,7 +2925,7 @@ void btrfs_return_cluster_to_free_space(spin_unlock (&cluster->lock);return ; } -atomic_inc (&block_group->count); +atomic_inc (&block_group->bg_count);spin_unlock (&cluster->lock); ctl = block_group->free_space_ctl;
@@ -3355,7 +3355,7 @@ int btrfs_find_space_cluster(struct btrfs_block_group *block_group,list_del_init (&entry->list);if (!ret) { -atomic_inc (&block_group->count); +atomic_inc (&block_group->bg_count);list_add_tail (&cluster->block_group_list, &block_group->cluster_list); cluster->block_group = block_group;
Signature · 1 line
2.25.1
Re: [PATCH 2/3] btrfs: rename btrfs_block_group::count
Quoted 4 lines · Anand Jain
The name 'count' is a very commonly used name. It is often difficult to review the code to check if there is any leak. So rename it to '
bg_count', which is unique enough.
Hum? Seriously?
count to bg_count?
It's a member of the block group structure, adding a bg_ prefix adds no value at all, we know the count is related to the block group. I could somewhat understand if you named it 'refcount' instead.
Thanks.
Quoted 87 lines
This patch also serves as a preparatory patch to either make sure
btrfs_get_block_group()is used instead of open coded the same or just open code every where asbtrfs_get_block_group()is a one-liner.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/block-group.c | 8 ++++---- fs/btrfs/block-group.h | 2 +- fs/btrfs/free-space-cache.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)fs/btrfs/block-group.c +4
-4@@ -118,12 +118,12 @@ u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)void btrfs_get_block_group (struct btrfs_block_group *cache) { -atomic_inc (&cache->count); +atomic_inc (&cache->bg_count); }void btrfs_put_block_group (struct btrfs_block_group *cache) { -if (atomic_dec_and_test (&cache->count)) { +if (atomic_dec_and_test (&cache->bg_count)) {WARN_ON (cache->pinned >0 );WARN_ON (cache->reserved >0 );@@ -1805,7 +1805,7 @@ static struct btrfs_block_group *btrfs_create_block_group_cache( cache->discard_index =BTRFS_DISCARD_INDEX_UNUSED ; -atomic_set (&cache->count,1 ); +atomic_set (&cache->bg_count,1 );spin_lock_init (&cache->lock);init_rwsem (&cache->data_rwsem);INIT_LIST_HEAD (&cache->list);@@ -3379,7 +3379,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)ASSERT (list_empty (&block_group->dirty_list));ASSERT (list_empty (&block_group->io_list));ASSERT (list_empty (&block_group->bg_list)); -ASSERT (atomic_read (&block_group->count) ==1 ); +ASSERT (atomic_read (&block_group->bg_count) ==1 );btrfs_put_block_group (block_group);spin_lock (&info->block_group_cache_lock);fs/btrfs/block-group.h +1
-1@@ -115,7 +115,7 @@ struct btrfs_block_group {struct list_head list;/* Usage count */ -atomic_t count; +atomic_t bg_count;/* * List of struct btrfs_free_clusters for this block group. fs/btrfs/free-space-cache.c +2
-3@@ -2925,7 +2925,7 @@ void btrfs_return_cluster_to_free_space(spin_unlock (&cluster->lock);return ; } -atomic_inc (&block_group->count); +atomic_inc (&block_group->bg_count);spin_unlock (&cluster->lock); ctl = block_group->free_space_ctl;@@ -3355,7 +3355,7 @@ int btrfs_find_space_cluster(struct btrfs_block_group *block_group,list_del_init (&entry->list);if (!ret) { -atomic_inc (&block_group->count); +atomic_inc (&block_group->bg_count);list_add_tail (&cluster->block_group_list, &block_group->cluster_list); cluster->block_group = block_group; --2.25.1
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 2/3] btrfs: rename btrfs_block_group::count
Quoted 6 lines · Filipe Manana
Quoted 4 lines · Anand Jain
The name 'count' is a very commonly used name. It is often difficult to review the code to check if there is any leak. So rename it to '
bg_count', which is unique enough.
Quoted 6 lines
Hum? Seriously?
count to
bg_count?
It's a member of the block group structure, adding abg_prefix adds no value at all, we know the count is related to the block group. I could somewhat understand if you named it 'refcount' instead.
Oh right. Now, bg_count does not make sense to me as well.
Something like bg_refcount is better so that it is easy to search where all its been used. IMO.
Are we ok with btrfs_block_group::bg_refcount instead ?
Thanks,
Anand
Quoted 1 line
Thanks.
Re: [PATCH 2/3] btrfs: rename btrfs_block_group::count
Quoted 18 lines · Anand Jain
Quoted 6 lines · Filipe Manana
Quoted 4 lines · Anand Jain
The name 'count' is a very commonly used name. It is often difficult to review the code to check if there is any leak. So rename it to '
bg_count', which is unique enough.Quoted 6 lines
Hum? Seriously?
count to
bg_count?
It's a member of the block group structure, adding abg_prefix adds no value at all, we know the count is related to the block group. I could somewhat understand if you named it 'refcount' instead.
Quoted 6 lines
Oh right. Now,
bg_countdoes not make sense to me as well.Something like
bg_refcountis better so that it is easy to search where all its been used. IMO.Are we ok with
btrfs_block_group::bg_refcountinstead ?
Why rename at all?
It's pretty obvious it's a reference count. Count/counter is not an unusual name to use for a reference count, it even has get and put helpers...
Quoted 6 lines
Thanks,
AnandQuoted 1 line
Thanks.
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 2/3] btrfs: rename btrfs_block_group::count
Quoted 6 lines
Why rename at all?
It's pretty obvious it's a reference count. Count/counter is not an unusual name to use for a reference count, it even has get and put helpers...
I understand as the member count is in btrfs_block_group so prefix bg_ looks redundant, but prefix bg_ is still useful. With out the prefix, the grep ">count" *.c didn't help straight away to verify where is block_group count used. At two places we missed using the get helper which the patch 3/3 fixed.
It's ok to drop this rename patch if you find it's not inline with the rest of the codes.
Re: [PATCH 2/3] btrfs: rename btrfs_block_group::count
Quoted 11 lines · Anand Jain
Quoted 7 lines
Why rename at all?
It's pretty obvious it's a reference count. Count/counter is not an unusual name to use for a reference count, it even has get and put helpers...I understand as the member count is in
btrfs_block_groupso prefixbg_looks redundant, but prefixbg_is still useful. With out the prefix, the grep ">count" *.c didn't help straight away to verify where is
Following that logic, we would add the bg_ prefix to most members of block_group...
It has members named 'start', 'length', 'flags', etc. Those are generic too, many other structures have members with exactly those names...
Don't take it wrong, but I don't find it useful at all.
Thanks.
Quoted 5 lines
block_groupcount used. At two places we missed using the get helper which the patch 3/3 fixed.It's ok to drop this rename patch if you find it's not inline with the rest of the codes.
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH 2/3] btrfs: rename btrfs_block_group::count
In reply to Anand JainQuoted 9 lines · Anand Jain
The name 'count' is a very commonly used name. It is often difficult to review the code to check if there is any leak. So rename it to '
bg_count', which is unique enough.This patch also serves as a preparatory patch to either make sure
btrfs_get_block_group()is used instead of open coded the same or just open code every where asbtrfs_get_block_group()is a one-liner.Signed-off-by Anand Jain <[email protected]>
This introduces unnecessary churn, instead if all uses happen through the btrfs_get_block_group/put apis you can simply grep for those. All other uses are RO. Also bg_count is not very descriptive given this is really a refcount. Open-coding probably would be fine if this type is switched to refcount_t rather than an atomic_t.
PATCH 3/3 btrfs: use helper btrfs_get_block_group
In reply to Anand JainUse the helper function where it is open coded to increment the block_group reference count 'bg_count' so that it is less confusing while reviewing the code. As btrfs_get_block_group() is a one-liner we could have open-coded it, but its partner function btrfs_put_block_group() isn't one-liner which does the free part in it.
--- fs/btrfs/free-space-cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/free-space-cache.c +2 -2
@@ -2925,7 +2925,7 @@ void btrfs_return_cluster_to_free_space(spin_unlock (&cluster->lock);return ; } -atomic_inc (&block_group->bg_count); +btrfs_get_block_group (block_group);spin_unlock (&cluster->lock); ctl = block_group->free_space_ctl;
@@ -3355,7 +3355,7 @@ int btrfs_find_space_cluster(struct btrfs_block_group *block_group,list_del_init (&entry->list);if (!ret) { -atomic_inc (&block_group->bg_count); +btrfs_get_block_group (block_group);list_add_tail (&cluster->block_group_list, &block_group->cluster_list); cluster->block_group = block_group;
Signature · 1 line
2.25.1
Re: [PATCH 3/3] btrfs: use helper btrfs_get_block_group
Quoted 7 lines · Anand Jain
Use the helper function where it is open coded to increment the
block_groupreference count 'bg_count' so that it is less confusing while reviewing the code. Asbtrfs_get_block_group()is a one-liner we could have open-coded it, but its partner functionbtrfs_put_block_group()isn't one-liner which does the free part in it.Signed-off-by Anand Jain <[email protected]>
Re: [PATCH 3/3] btrfs: use helper btrfs_get_block_group
In reply to Anand JainLooks good,
Quoted 11 lines · Anand Jain
Minor cleanup patches.
1/3 cleansup the return value ofbtrfs_return_cluster_to_free_space(). 2/3 and 3/3 together cleanups block group reference count.2/3 and 3/3 are related. However 1/3 is independent to the rest of the patches in this set.
Anand Jain (3):
btrfs: fixbtrfs_return_cluster_to_free_space()return
btrfs: renamebtrfs_block_group::count
btrfs: use helperbtrfs_get_block_group
1 and 3 applied but I don't recommend to spend time on cleaning up free-space-cache.[ch] as it's going to be phased out.