Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E61DC64EC7 for ; Tue, 28 Feb 2023 03:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbjB1DmB (ORCPT ); Mon, 27 Feb 2023 22:42:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjB1Dll (ORCPT ); Mon, 27 Feb 2023 22:41:41 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FB7325E22; Mon, 27 Feb 2023 19:41:40 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4PQjpR6LJxz4f41Tm; Tue, 28 Feb 2023 11:41:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP2 (Coremail) with SMTP id Syh0CgDnjOrod_1jpDeZEQ--.58449S22; Tue, 28 Feb 2023 11:41:37 +0800 (CST) From: Kemeng Shi To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ojaswin@linux.ibm.com, ritesh.list@gmail.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, shikemeng@huaweicloud.com Subject: [PATCH v2 20/20] ext4: simplify calculation of blkoff in ext4_mb_new_blocks_simple Date: Tue, 28 Feb 2023 19:43:06 +0800 Message-Id: <20230228114306.3328235-21-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230228114306.3328235-1-shikemeng@huaweicloud.com> References: <20230228114306.3328235-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-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VAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRv JPtUUUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org We calculate blkoff for groups as following: ext4_get_group_no_and_offset(sb, max(ext4_group_first_block_no(sb, group), goal), NULL, &blkoff); For first group, the blkoff is already calculated before loop, so this is redundant. For groups after first group which contains goal, the result of max(...) above is always ext4_group_first_block_no(sb, group). The blkoff of first block in group is always 0, so blkoff of groups after the first group which contains goal is always 0. So we can clean blkoff calculation as following: 1. Remove blkoff calculation above to remove repeat calculation of first group. 2. Set blkoff to 0 to set blkoff for groups after first group. Signed-off-by: Kemeng Shi --- fs/ext4/mballoc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index f65894bfaff2..2cc655de1853 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5769,9 +5769,6 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle, return 0; } - ext4_get_group_no_and_offset(sb, - max(ext4_group_first_block_no(sb, group), goal), - NULL, &blkoff); while (1) { i = mb_find_next_zero_bit(bitmap_bh->b_data, max, blkoff); @@ -5786,6 +5783,8 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle, brelse(bitmap_bh); if (i < max) break; + + blkoff = 0; } if (group >= ext4_get_groups_count(sb) || i >= max) { -- 2.30.0