linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Simplify update space_info in __reserve_metadata_bytes()
@ 2019-06-19 14:12 Goldwyn Rodrigues
  2019-06-19 14:15 ` Nikolay Borisov
  2019-06-25 18:13 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Goldwyn Rodrigues @ 2019-06-19 14:12 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Goldwyn Rodrigues

From: Goldwyn Rodrigues <rgoldwyn@suse.com>

Simplification.
We don't need an if-else-if structure where we can use a
simple OR since both conditions are performing the
same action. The short-circuit for OR will ensure that if
the first condition is true, can_overcommit() is not
called.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/extent-tree.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index c7adff343ba9..84a33cbb1e68 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5158,17 +5158,13 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
 	used = btrfs_space_info_used(space_info, true);
 
 	/*
-	 * If we have enough space then hooray, make our reservation and carry
-	 * on.  If not see if we can overcommit, and if we can, hooray carry on.
+	 * Carry on if we have enough space (short-circuit) OR call
+	 * can_overcommit() to ensure we can overcommit to carry on.
 	 * If not things get more complicated.
 	 */
-	if (used + orig_bytes <= space_info->total_bytes) {
-		update_bytes_may_use(space_info, orig_bytes);
-		trace_btrfs_space_reservation(fs_info, "space_info",
-					      space_info->flags, orig_bytes, 1);
-		ret = 0;
-	} else if (can_overcommit(fs_info, space_info, orig_bytes, flush,
-				  system_chunk)) {
+	if ((used + orig_bytes <= space_info->total_bytes) ||
+	    can_overcommit(fs_info, space_info, orig_bytes, flush,
+			    system_chunk)) {
 		update_bytes_may_use(space_info, orig_bytes);
 		trace_btrfs_space_reservation(fs_info, "space_info",
 					      space_info->flags, orig_bytes, 1);
-- 
2.16.4


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

* Re: [PATCH] btrfs: Simplify update space_info in __reserve_metadata_bytes()
  2019-06-19 14:12 [PATCH] btrfs: Simplify update space_info in __reserve_metadata_bytes() Goldwyn Rodrigues
@ 2019-06-19 14:15 ` Nikolay Borisov
  2019-06-25 18:13 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2019-06-19 14:15 UTC (permalink / raw)
  To: Goldwyn Rodrigues, linux-btrfs; +Cc: Goldwyn Rodrigues



On 19.06.19 г. 17:12 ч., Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> Simplification.
> We don't need an if-else-if structure where we can use a
> simple OR since both conditions are performing the
> same action. The short-circuit for OR will ensure that if
> the first condition is true, can_overcommit() is not
> called.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/extent-tree.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index c7adff343ba9..84a33cbb1e68 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -5158,17 +5158,13 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
>  	used = btrfs_space_info_used(space_info, true);
>  
>  	/*
> -	 * If we have enough space then hooray, make our reservation and carry
> -	 * on.  If not see if we can overcommit, and if we can, hooray carry on.
> +	 * Carry on if we have enough space (short-circuit) OR call
> +	 * can_overcommit() to ensure we can overcommit to carry on.
>  	 * If not things get more complicated.
>  	 */
> -	if (used + orig_bytes <= space_info->total_bytes) {
> -		update_bytes_may_use(space_info, orig_bytes);
> -		trace_btrfs_space_reservation(fs_info, "space_info",
> -					      space_info->flags, orig_bytes, 1);
> -		ret = 0;
> -	} else if (can_overcommit(fs_info, space_info, orig_bytes, flush,
> -				  system_chunk)) {
> +	if ((used + orig_bytes <= space_info->total_bytes) ||
> +	    can_overcommit(fs_info, space_info, orig_bytes, flush,
> +			    system_chunk)) {
>  		update_bytes_may_use(space_info, orig_bytes);
>  		trace_btrfs_space_reservation(fs_info, "space_info",
>  					      space_info->flags, orig_bytes, 1);
> 

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

* Re: [PATCH] btrfs: Simplify update space_info in __reserve_metadata_bytes()
  2019-06-19 14:12 [PATCH] btrfs: Simplify update space_info in __reserve_metadata_bytes() Goldwyn Rodrigues
  2019-06-19 14:15 ` Nikolay Borisov
@ 2019-06-25 18:13 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2019-06-25 18:13 UTC (permalink / raw)
  To: Goldwyn Rodrigues; +Cc: linux-btrfs, Goldwyn Rodrigues

On Wed, Jun 19, 2019 at 09:12:49AM -0500, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> Simplification.
> We don't need an if-else-if structure where we can use a
> simple OR since both conditions are performing the
> same action. The short-circuit for OR will ensure that if
> the first condition is true, can_overcommit() is not
> called.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

Added to misc-next, thanks.

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

end of thread, other threads:[~2019-06-25 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-19 14:12 [PATCH] btrfs: Simplify update space_info in __reserve_metadata_bytes() Goldwyn Rodrigues
2019-06-19 14:15 ` Nikolay Borisov
2019-06-25 18:13 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).