linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Chengguang Xu <cgxu519@mykernel.net>
Cc: jack@suse.com, linux-ext4@vger.kernel.org
Subject: Re: [PATCH 4/5] ext2: code cleanup for ext2_try_to_allocate()
Date: Wed, 6 Nov 2019 16:59:00 +0100	[thread overview]
Message-ID: <20191106155900.GC12685@quack2.suse.cz> (raw)
In-Reply-To: <20191104114036.9893-4-cgxu519@mykernel.net>

[-- Attachment #1: Type: text/plain, Size: 1678 bytes --]

On Mon 04-11-19 19:40:35, Chengguang Xu wrote:
> Code cleanup by removing duplicated code.
> 
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>

Thanks for the patch! I've merged it with a small update to switch the
while() loop into a for() loop which is somewhat more natural in that
situation. Resulting patch attached.

								Honza

> ---
>  fs/ext2/balloc.c | 32 ++++++++++++++------------------
>  1 file changed, 14 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
> index a0c22e166682..9a9bd566243d 100644
> --- a/fs/ext2/balloc.c
> +++ b/fs/ext2/balloc.c
> @@ -710,29 +710,25 @@ ext2_try_to_allocate(struct super_block *sb, int group,
>  				;
>  		}
>  	}
> -	start = grp_goal;
>  
> -repeat:
> -	if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group), grp_goal,
> -			       				bitmap_bh->b_data)) {
> -		/*
> -		 * The block was allocated by another thread, or it was
> -		 * allocated and then freed by another thread
> -		 */
> -		start++;
> -		grp_goal++;
> -		if (start >= end)
> -			goto fail_access;
> -		goto repeat;
> -	}
> -	num++;
> -	grp_goal++;
> -	while (num < *count && grp_goal < end
> -		&& !ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
> +	while (num < *count && grp_goal < end) {
> +		if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
>  					grp_goal, bitmap_bh->b_data)) {
> +			if (num == 0) {
> +				grp_goal++;
> +				continue;
> +			} else {
> +				break;
> +			}
> +		}
> +
>  		num++;
>  		grp_goal++;
>  	}
> +
> +	if (!num)
> +		goto fail_access;
> +
>  	*count = num;
>  	return grp_goal - num;
>  fail_access:
> -- 
> 2.20.1
> 
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

[-- Attachment #2: 0001-ext2-code-cleanup-for-ext2_try_to_allocate.patch --]
[-- Type: text/x-patch, Size: 1572 bytes --]

From d61650c669a6e3c1347cd3b333e4ae8487757f35 Mon Sep 17 00:00:00 2001
From: Chengguang Xu <cgxu519@mykernel.net>
Date: Mon, 4 Nov 2019 19:40:35 +0800
Subject: [PATCH] ext2: code cleanup for ext2_try_to_allocate()

Code cleanup by removing duplicated code.

Link: https://lore.kernel.org/r/20191104114036.9893-4-cgxu519@mykernel.net
Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext2/balloc.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 25bc3a43cd94..d67f7dc1baaa 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -698,29 +698,20 @@ ext2_try_to_allocate(struct super_block *sb, int group,
 				;
 		}
 	}
-	start = grp_goal;
 
-repeat:
-	if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group), grp_goal,
-			       				bitmap_bh->b_data)) {
-		/*
-		 * The block was allocated by another thread, or it was
-		 * allocated and then freed by another thread
-		 */
-		start++;
-		grp_goal++;
-		if (start >= end)
-			goto fail_access;
-		goto repeat;
-	}
-	num++;
-	grp_goal++;
-	while (num < *count && grp_goal < end
-		&& !ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
+	for (; num < *count && grp_goal < end; grp_goal++) {
+		if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
 					grp_goal, bitmap_bh->b_data)) {
+			if (num == 0)
+				continue;
+			break;
+		}
 		num++;
-		grp_goal++;
 	}
+
+	if (num == 0)
+		goto fail_access;
+
 	*count = num;
 	return grp_goal - num;
 fail_access:
-- 
2.16.4


  reply	other threads:[~2019-11-06 15:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04 11:40 [PATCH 1/5] ext2: introduce new helper ext2_group_last_block_no() Chengguang Xu
2019-11-04 11:40 ` [PATCH 2/5] ext2: code cleanup by calling ext2_group_last_block_no() Chengguang Xu
2019-11-06 15:42   ` Jan Kara
2019-11-07  2:54     ` Chengguang Xu
2019-11-07  9:21       ` Jan Kara
2019-11-07  9:44         ` Chengguang Xu
2019-11-07 11:36           ` Jan Kara
2019-11-04 11:40 ` [PATCH 3/5] ext2: skip unnecessary operations in ext2_try_to_allocate() Chengguang Xu
2019-11-04 11:40 ` [PATCH 4/5] ext2: code cleanup for ext2_try_to_allocate() Chengguang Xu
2019-11-06 15:59   ` Jan Kara [this message]
2019-11-07  2:58     ` Chengguang Xu
2019-11-04 11:40 ` [PATCH 5/5] ext2: fix improper function comment Chengguang Xu
2019-11-06 16:01   ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191106155900.GC12685@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=cgxu519@mykernel.net \
    --cc=jack@suse.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).