Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp755007ybx; Wed, 6 Nov 2019 07:59:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyU3AFTMSDE5TIfhbqaPweoupW2N1KKPvLRjUw2X9R/sh8lF7TsrnYPFAvT5RQnmro/vqv3 X-Received: by 2002:a17:906:3e41:: with SMTP id t1mr35375268eji.103.1573055978581; Wed, 06 Nov 2019 07:59:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573055978; cv=none; d=google.com; s=arc-20160816; b=cerVBO3IO3K+2jbhNmyaFHKmaQdk3pcHJFRoGTUPbjR5sk9Ib8mHIOenAPh1EO6Awc OFYTsYR/xjAw2vNaPObLASkXax4Q8ek0ZRlP9MXDyZL0zq6WSSfexheVqC+xgz+UCwAm cVk7+8OPURD3984Hh4SZeyvTrgkE0Dih55U6C7TCAaB+7wxJNoAlKirwnuaX328+afTt aOwnu72Bo5r1z5FRbkIwEgQ7xyqrxngJ9xL4t/uxzSmngebXKhrizcJaW3vl6giTtp1D FNZVQpQJD+owRfnFJNHpBbNvF9fJHo/1LgVxh36mH8UbrgPaTmnWRPsV6ha4vl7NCAHL oarQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fxYC5qscAQy9XmB2cweKMoVqmLjtSG8TCj99x342ves=; b=tFvwVRvHZ1/XF8QAK4cJE2TPC+02ElJcP3Rrr8x4PFu8pSg0EzbrU7//ZNJITXDnwz bo6ndba5HYYYJmo2vCdvqHBIw0wf31UR1pj5ANQhYyHxmJ4akqVzBap/ecwMxaS86jzT xxWiTLUZqJkaXNESl6Rklkbcdp8/Ab/N3OXLiu50VHfjx94UG9hb4nTAEN01ZY6ZLZnt vA9mRLwInkw1oF+xPakT4bZR4yVtNr+JO2R0MH0VhCIp+wvC6tiIUZ/yjqHyQDslEp42 yxZIB9ugv/eoeGgvhcXdlv6t4xG3c0m06CJmQsgFUOKhEcsCUiQo9KjNFMKMAL4CoPPq Tifg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21si13797506edi.123.2019.11.06.07.59.09; Wed, 06 Nov 2019 07:59:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728917AbfKFP7D (ORCPT + 99 others); Wed, 6 Nov 2019 10:59:03 -0500 Received: from mx2.suse.de ([195.135.220.15]:40408 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726926AbfKFP7D (ORCPT ); Wed, 6 Nov 2019 10:59:03 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4C6FFB195; Wed, 6 Nov 2019 15:59:01 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id C796D1E4353; Wed, 6 Nov 2019 16:59:00 +0100 (CET) Date: Wed, 6 Nov 2019 16:59:00 +0100 From: Jan Kara To: Chengguang Xu Cc: jack@suse.com, linux-ext4@vger.kernel.org Subject: Re: [PATCH 4/5] ext2: code cleanup for ext2_try_to_allocate() Message-ID: <20191106155900.GC12685@quack2.suse.cz> References: <20191104114036.9893-1-cgxu519@mykernel.net> <20191104114036.9893-4-cgxu519@mykernel.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="DKU6Jbt7q3WqK7+M" Content-Disposition: inline In-Reply-To: <20191104114036.9893-4-cgxu519@mykernel.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org --DKU6Jbt7q3WqK7+M Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon 04-11-19 19:40:35, Chengguang Xu wrote: > Code cleanup by removing duplicated code. > > Signed-off-by: Chengguang Xu 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 SUSE Labs, CR --DKU6Jbt7q3WqK7+M Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-ext2-code-cleanup-for-ext2_try_to_allocate.patch" From d61650c669a6e3c1347cd3b333e4ae8487757f35 Mon Sep 17 00:00:00 2001 From: Chengguang Xu 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 Signed-off-by: Jan Kara --- 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 --DKU6Jbt7q3WqK7+M--