All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Cleanup short int types in block group reserve
@ 2022-07-07 19:02 David Sterba
  2022-07-07 19:02 ` [PATCH v2 1/3] btrfs: switch btrfs_block_rsv::full to bool David Sterba
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: David Sterba @ 2022-07-07 19:02 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Using the short type in btrfs_block_rsv is not needed for bool
indicators and we can make the structure smaller.

v2:
- fix true/false typo in first patch
- use named enum for block group type

David Sterba (3):
  btrfs: switch btrfs_block_rsv::full to bool
  btrfs: switch btrfs_block_rsv::failfast to bool
  btrfs: use enum for btrfs_block_rsv::type

 fs/btrfs/block-rsv.c   | 21 +++++++++------------
 fs/btrfs/block-rsv.h   | 15 ++++++++-------
 fs/btrfs/delayed-ref.c |  4 ++--
 fs/btrfs/file.c        |  2 +-
 fs/btrfs/inode.c       |  4 ++--
 5 files changed, 22 insertions(+), 24 deletions(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] btrfs: switch btrfs_block_rsv::full to bool
  2022-07-07 19:02 [PATCH v2 0/3] Cleanup short int types in block group reserve David Sterba
@ 2022-07-07 19:02 ` David Sterba
  2022-07-07 19:02 ` [PATCH v2 2/3] btrfs: switch btrfs_block_rsv::failfast " David Sterba
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-07-07 19:02 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Use simple bool type for the block reserve full status, there's short to
save space as there used to be int but there's no reason for that.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/block-rsv.c   | 15 ++++++---------
 fs/btrfs/block-rsv.h   |  2 +-
 fs/btrfs/delayed-ref.c |  4 ++--
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c
index b3ee49b0b1e8..26c43a6ef5d2 100644
--- a/fs/btrfs/block-rsv.c
+++ b/fs/btrfs/block-rsv.c
@@ -118,7 +118,7 @@ static u64 block_rsv_release_bytes(struct btrfs_fs_info *fs_info,
 	if (block_rsv->reserved >= block_rsv->size) {
 		num_bytes = block_rsv->reserved - block_rsv->size;
 		block_rsv->reserved = block_rsv->size;
-		block_rsv->full = 1;
+		block_rsv->full = true;
 	} else {
 		num_bytes = 0;
 	}
@@ -142,7 +142,7 @@ static u64 block_rsv_release_bytes(struct btrfs_fs_info *fs_info,
 				bytes_to_add = min(num_bytes, bytes_to_add);
 				dest->reserved += bytes_to_add;
 				if (dest->reserved >= dest->size)
-					dest->full = 1;
+					dest->full = true;
 				num_bytes -= bytes_to_add;
 			}
 			spin_unlock(&dest->lock);
@@ -304,7 +304,7 @@ int btrfs_block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv, u64 num_bytes)
 	if (block_rsv->reserved >= num_bytes) {
 		block_rsv->reserved -= num_bytes;
 		if (block_rsv->reserved < block_rsv->size)
-			block_rsv->full = 0;
+			block_rsv->full = false;
 		ret = 0;
 	}
 	spin_unlock(&block_rsv->lock);
@@ -319,7 +319,7 @@ void btrfs_block_rsv_add_bytes(struct btrfs_block_rsv *block_rsv,
 	if (update_size)
 		block_rsv->size += num_bytes;
 	else if (block_rsv->reserved >= block_rsv->size)
-		block_rsv->full = 1;
+		block_rsv->full = true;
 	spin_unlock(&block_rsv->lock);
 }
 
@@ -341,7 +341,7 @@ int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info,
 	}
 	global_rsv->reserved -= num_bytes;
 	if (global_rsv->reserved < global_rsv->size)
-		global_rsv->full = 0;
+		global_rsv->full = false;
 	spin_unlock(&global_rsv->lock);
 
 	btrfs_block_rsv_add_bytes(dest, num_bytes, true);
@@ -408,10 +408,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
 		btrfs_try_granting_tickets(fs_info, sinfo);
 	}
 
-	if (block_rsv->reserved == block_rsv->size)
-		block_rsv->full = 1;
-	else
-		block_rsv->full = 0;
+	block_rsv->full = (block_rsv->reserved == block_rsv->size);
 
 	if (block_rsv->size >= sinfo->total_bytes)
 		sinfo->force_alloc = CHUNK_ALLOC_FORCE;
diff --git a/fs/btrfs/block-rsv.h b/fs/btrfs/block-rsv.h
index 3b67ff08d434..99c491ef128e 100644
--- a/fs/btrfs/block-rsv.h
+++ b/fs/btrfs/block-rsv.h
@@ -25,7 +25,7 @@ struct btrfs_block_rsv {
 	u64 reserved;
 	struct btrfs_space_info *space_info;
 	spinlock_t lock;
-	unsigned short full;
+	bool full;
 	unsigned short type;
 	unsigned short failfast;
 
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 99f37fca2e96..36a3debe9493 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -132,7 +132,7 @@ void btrfs_update_delayed_refs_rsv(struct btrfs_trans_handle *trans)
 
 	spin_lock(&delayed_rsv->lock);
 	delayed_rsv->size += num_bytes;
-	delayed_rsv->full = 0;
+	delayed_rsv->full = false;
 	spin_unlock(&delayed_rsv->lock);
 	trans->delayed_ref_updates = 0;
 }
@@ -175,7 +175,7 @@ void btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info,
 	if (num_bytes)
 		delayed_refs_rsv->reserved += num_bytes;
 	if (delayed_refs_rsv->reserved >= delayed_refs_rsv->size)
-		delayed_refs_rsv->full = 1;
+		delayed_refs_rsv->full = true;
 	spin_unlock(&delayed_refs_rsv->lock);
 
 	if (num_bytes)
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] btrfs: switch btrfs_block_rsv::failfast to bool
  2022-07-07 19:02 [PATCH v2 0/3] Cleanup short int types in block group reserve David Sterba
  2022-07-07 19:02 ` [PATCH v2 1/3] btrfs: switch btrfs_block_rsv::full to bool David Sterba
@ 2022-07-07 19:02 ` David Sterba
  2022-07-07 19:02 ` [PATCH v2 3/3] btrfs: use enum for btrfs_block_rsv::type David Sterba
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-07-07 19:02 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Use simple bool type for the block reserve failfast status, there's
short to save space as there used to be int but there's no reason for
that.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/block-rsv.h | 2 +-
 fs/btrfs/file.c      | 2 +-
 fs/btrfs/inode.c     | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/block-rsv.h b/fs/btrfs/block-rsv.h
index 99c491ef128e..0702d4087ff6 100644
--- a/fs/btrfs/block-rsv.h
+++ b/fs/btrfs/block-rsv.h
@@ -26,8 +26,8 @@ struct btrfs_block_rsv {
 	struct btrfs_space_info *space_info;
 	spinlock_t lock;
 	bool full;
+	bool failfast;
 	unsigned short type;
-	unsigned short failfast;
 
 	/*
 	 * Qgroup equivalent for @size @reserved
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 734baa729cd3..f406a662e942 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2736,7 +2736,7 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode,
 		goto out;
 	}
 	rsv->size = btrfs_calc_insert_metadata_size(fs_info, 1);
-	rsv->failfast = 1;
+	rsv->failfast = true;
 
 	/*
 	 * 1 - update the inode
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 7790e307bf54..b9485e19b696 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5433,7 +5433,7 @@ void btrfs_evict_inode(struct inode *inode)
 	if (!rsv)
 		goto no_delete;
 	rsv->size = btrfs_calc_metadata_size(fs_info, 1);
-	rsv->failfast = 1;
+	rsv->failfast = true;
 
 	btrfs_i_size_write(BTRFS_I(inode), 0);
 
@@ -8687,7 +8687,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback)
 	if (!rsv)
 		return -ENOMEM;
 	rsv->size = min_size;
-	rsv->failfast = 1;
+	rsv->failfast = true;
 
 	/*
 	 * 1 for the truncate slack space
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] btrfs: use enum for btrfs_block_rsv::type
  2022-07-07 19:02 [PATCH v2 0/3] Cleanup short int types in block group reserve David Sterba
  2022-07-07 19:02 ` [PATCH v2 1/3] btrfs: switch btrfs_block_rsv::full to bool David Sterba
  2022-07-07 19:02 ` [PATCH v2 2/3] btrfs: switch btrfs_block_rsv::failfast " David Sterba
@ 2022-07-07 19:02 ` David Sterba
  2022-07-08 13:21 ` [PATCH v2 0/3] Cleanup short int types in block group reserve Anand Jain
  2022-07-09 11:40 ` Johannes Thumshirn
  4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-07-07 19:02 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The number of block group reserve types BTRFS_BLOCK_RSV_* is small and
fits to u8 and there's enough left in case we want to add more.
For type safety use the enum but make it 8 bits in the structure to save
space.

The structure size is now 48 on release build, making a slight
improvement in structures where it's embedded, like btrfs_fs_info or
btrfs_inode.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/block-rsv.c |  6 +++---
 fs/btrfs/block-rsv.h | 11 ++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c
index 26c43a6ef5d2..06be0644dd37 100644
--- a/fs/btrfs/block-rsv.c
+++ b/fs/btrfs/block-rsv.c
@@ -171,7 +171,7 @@ int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src,
 	return 0;
 }
 
-void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type)
+void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, enum btrfs_rsv_type type)
 {
 	memset(rsv, 0, sizeof(*rsv));
 	spin_lock_init(&rsv->lock);
@@ -180,7 +180,7 @@ void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type)
 
 void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info,
 				   struct btrfs_block_rsv *rsv,
-				   unsigned short type)
+				   enum btrfs_rsv_type type)
 {
 	btrfs_init_block_rsv(rsv, type);
 	rsv->space_info = btrfs_find_space_info(fs_info,
@@ -188,7 +188,7 @@ void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info,
 }
 
 struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info,
-					      unsigned short type)
+					      enum btrfs_rsv_type type)
 {
 	struct btrfs_block_rsv *block_rsv;
 
diff --git a/fs/btrfs/block-rsv.h b/fs/btrfs/block-rsv.h
index 0702d4087ff6..0c183709be00 100644
--- a/fs/btrfs/block-rsv.h
+++ b/fs/btrfs/block-rsv.h
@@ -9,7 +9,7 @@ enum btrfs_reserve_flush_enum;
 /*
  * Types of block reserves
  */
-enum {
+enum btrfs_rsv_type {
 	BTRFS_BLOCK_RSV_GLOBAL,
 	BTRFS_BLOCK_RSV_DELALLOC,
 	BTRFS_BLOCK_RSV_TRANS,
@@ -27,7 +27,8 @@ struct btrfs_block_rsv {
 	spinlock_t lock;
 	bool full;
 	bool failfast;
-	unsigned short type;
+	/* Block reserve type, one of BTRFS_BLOCK_RSV_* */
+	enum btrfs_rsv_type type:8;
 
 	/*
 	 * Qgroup equivalent for @size @reserved
@@ -49,13 +50,13 @@ struct btrfs_block_rsv {
 	u64 qgroup_rsv_reserved;
 };
 
-void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type);
+void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, enum btrfs_rsv_type type);
 void btrfs_init_root_block_rsv(struct btrfs_root *root);
 struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info,
-					      unsigned short type);
+					      enum btrfs_rsv_type type);
 void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info,
 				   struct btrfs_block_rsv *rsv,
-				   unsigned short type);
+				   enum btrfs_rsv_type type);
 void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info,
 			  struct btrfs_block_rsv *rsv);
 int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] Cleanup short int types in block group reserve
  2022-07-07 19:02 [PATCH v2 0/3] Cleanup short int types in block group reserve David Sterba
                   ` (2 preceding siblings ...)
  2022-07-07 19:02 ` [PATCH v2 3/3] btrfs: use enum for btrfs_block_rsv::type David Sterba
@ 2022-07-08 13:21 ` Anand Jain
  2022-07-09 11:40 ` Johannes Thumshirn
  4 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2022-07-08 13:21 UTC (permalink / raw)
  To: David Sterba, linux-btrfs



On 08/07/2022 03:02, David Sterba wrote:
> Using the short type in btrfs_block_rsv is not needed for bool
> indicators and we can make the structure smaller.
> 
> v2:
> - fix true/false typo in first patch
> - use named enum for block group type
> 
> David Sterba (3):
>    btrfs: switch btrfs_block_rsv::full to bool
>    btrfs: switch btrfs_block_rsv::failfast to bool
>    btrfs: use enum for btrfs_block_rsv::type
> 
>   fs/btrfs/block-rsv.c   | 21 +++++++++------------
>   fs/btrfs/block-rsv.h   | 15 ++++++++-------
>   fs/btrfs/delayed-ref.c |  4 ++--
>   fs/btrfs/file.c        |  2 +-
>   fs/btrfs/inode.c       |  4 ++--
>   5 files changed, 22 insertions(+), 24 deletions(-)
> 

For the whole series

Reviewed-by: Anand Jain <anand.jain@oracle.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] Cleanup short int types in block group reserve
  2022-07-07 19:02 [PATCH v2 0/3] Cleanup short int types in block group reserve David Sterba
                   ` (3 preceding siblings ...)
  2022-07-08 13:21 ` [PATCH v2 0/3] Cleanup short int types in block group reserve Anand Jain
@ 2022-07-09 11:40 ` Johannes Thumshirn
  4 siblings, 0 replies; 6+ messages in thread
From: Johannes Thumshirn @ 2022-07-09 11:40 UTC (permalink / raw)
  To: David Sterba, linux-btrfs

On 07.07.22 21:08, David Sterba wrote:
> Using the short type in btrfs_block_rsv is not needed for bool
> indicators and we can make the structure smaller.
> 
> v2:
> - fix true/false typo in first patch
> - use named enum for block group type
> 
> David Sterba (3):
>   btrfs: switch btrfs_block_rsv::full to bool
>   btrfs: switch btrfs_block_rsv::failfast to bool
>   btrfs: use enum for btrfs_block_rsv::type
> 
>  fs/btrfs/block-rsv.c   | 21 +++++++++------------
>  fs/btrfs/block-rsv.h   | 15 ++++++++-------
>  fs/btrfs/delayed-ref.c |  4 ++--
>  fs/btrfs/file.c        |  2 +-
>  fs/btrfs/inode.c       |  4 ++--
>  5 files changed, 22 insertions(+), 24 deletions(-)
> 

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-09 11:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 19:02 [PATCH v2 0/3] Cleanup short int types in block group reserve David Sterba
2022-07-07 19:02 ` [PATCH v2 1/3] btrfs: switch btrfs_block_rsv::full to bool David Sterba
2022-07-07 19:02 ` [PATCH v2 2/3] btrfs: switch btrfs_block_rsv::failfast " David Sterba
2022-07-07 19:02 ` [PATCH v2 3/3] btrfs: use enum for btrfs_block_rsv::type David Sterba
2022-07-08 13:21 ` [PATCH v2 0/3] Cleanup short int types in block group reserve Anand Jain
2022-07-09 11:40 ` Johannes Thumshirn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.