[2/3] btrfs: rename btrfs_block_group::count
diff mbox series

Message ID 20200603101020.143372-3-anand.jain@oracle.com
State New
Headers show
Series
  • btrfs: minor block group cleanups
Related show

Commit Message

Anand Jain June 3, 2020, 10:10 a.m. UTC
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 as btrfs_get_block_group() is a one-liner.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 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(-)

Comments

Filipe Manana June 3, 2020, 10:19 a.m. UTC | #1
On Wed, Jun 3, 2020 at 11:13 AM Anand Jain <anand.jain@oracle.com> wrote:
>
> 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.

>
> 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.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  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(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 31ca2cfb7e3e..8111f6750063 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -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);
> diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h
> index b6ee70a039c7..f0ef8be08747 100644
> --- a/fs/btrfs/block-group.h
> +++ b/fs/btrfs/block-group.h
> @@ -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.
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 1bf08c855edb..169b1117c1a3 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -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
>
Nikolay Borisov June 3, 2020, 10:23 a.m. UTC | #2
On 3.06.20 г. 13:10 ч., Anand Jain wrote:
> 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 as btrfs_get_block_group() is a one-liner.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

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.
Anand Jain June 3, 2020, 10:43 a.m. UTC | #3
On 3/6/20 6:19 pm, Filipe Manana wrote:
> On Wed, Jun 3, 2020 at 11:13 AM Anand Jain <anand.jain@oracle.com> wrote:
>>
>> 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.


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


> Thanks.
Filipe Manana June 3, 2020, 10:49 a.m. UTC | #4
On Wed, Jun 3, 2020 at 11:43 AM Anand Jain <anand.jain@oracle.com> wrote:
>
>
>
> On 3/6/20 6:19 pm, Filipe Manana wrote:
> > On Wed, Jun 3, 2020 at 11:13 AM Anand Jain <anand.jain@oracle.com> wrote:
> >>
> >> 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.
>
>
> 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 ?

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...

>
> Thanks,
> Anand
>
>
> > Thanks.
Anand Jain June 3, 2020, 11:38 a.m. UTC | #5
> 
> 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.
Filipe Manana June 3, 2020, 11:54 a.m. UTC | #6
On Wed, Jun 3, 2020 at 12:38 PM Anand Jain <anandsuveer@gmail.com> wrote:
>
>
> >
> > 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

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.

> 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.

Patch
diff mbox series

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 31ca2cfb7e3e..8111f6750063 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -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);
diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h
index b6ee70a039c7..f0ef8be08747 100644
--- a/fs/btrfs/block-group.h
+++ b/fs/btrfs/block-group.h
@@ -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.
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 1bf08c855edb..169b1117c1a3 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -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;