From nobody Mon Feb 9 15:26:32 2026 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 BDD86C433EF for ; Sat, 28 May 2022 10:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353774AbiE1KrR (ORCPT ); Sat, 28 May 2022 06:47:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350071AbiE1Kq7 (ORCPT ); Sat, 28 May 2022 06:46:59 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65BAB13D66; Sat, 28 May 2022 03:46:57 -0700 (PDT) Received: from dggpeml500020.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L9JHM3v4MzjWyv; Sat, 28 May 2022 18:45:51 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500020.china.huawei.com (7.185.36.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 28 May 2022 18:46:55 +0800 From: Baokun Li To: CC: , , , , , , , , , Subject: [PATCH v3 3/3] ext4: support flex_bg in ext4_mb_normalize_request Date: Sat, 28 May 2022 19:00:17 +0800 Message-ID: <20220528110017.354175-4-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220528110017.354175-1-libaokun1@huawei.com> References: <20220528110017.354175-1-libaokun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500020.china.huawei.com (7.185.36.88) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In ext4_mb_normalize_request, the size of the allocation request is limited to no more than EXT4_BLOCKS_PER_GROUP. Ritesh mentions that this does not take into account the case of flex_bg groups. So we should add support for flex_bg to make the physical blocks of large files contiguous. Signed-off-by: Baokun Li --- fs/ext4/mballoc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 9e06334771a3..253fc250e9a0 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4028,6 +4028,7 @@ ext4_mb_normalize_request(struct ext4_allocation_cont= ext *ac, loff_t size, start_off; loff_t orig_size __maybe_unused; ext4_lblk_t start; + ext4_lblk_t bpg; struct ext4_inode_info *ei =3D EXT4_I(ac->ac_inode); struct ext4_prealloc_space *pa; =20 @@ -4051,6 +4052,11 @@ ext4_mb_normalize_request(struct ext4_allocation_con= text *ac, } =20 bsbits =3D ac->ac_sb->s_blocksize_bits; + bpg =3D EXT4_BLOCKS_PER_GROUP(ac->ac_sb); + if (ext4_has_feature_flex_bg(ac->ac_sb) && sbi->s_log_groups_per_flex) { + if (check_shl_overflow(bpg, sbi->s_log_groups_per_flex, &bpg)) + bpg =3D EXT_MAX_BLOCKS; + } =20 /* first, let's learn actual file size * given current request is allocated */ @@ -4110,8 +4116,7 @@ ext4_mb_normalize_request(struct ext4_allocation_cont= ext *ac, * alignment does not move allocation to a different group which * makes mballoc fail assertions later. */ - start =3D max(start, rounddown(ac->ac_o_ex.fe_logical, - (ext4_lblk_t)EXT4_BLOCKS_PER_GROUP(ac->ac_sb))); + start =3D max(start, rounddown(ac->ac_o_ex.fe_logical, bpg)); =20 /* don't cover already allocated blocks in selected range */ if (ar->pleft && start <=3D ar->lleft) { @@ -4125,8 +4130,8 @@ ext4_mb_normalize_request(struct ext4_allocation_cont= ext *ac, * Trim allocation request for filesystems with artificially small * groups. */ - if (size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb)) - size =3D EXT4_BLOCKS_PER_GROUP(ac->ac_sb); + if (size > bpg) + size =3D bpg; =20 end =3D start + size; =20 @@ -4208,7 +4213,7 @@ ext4_mb_normalize_request(struct ext4_allocation_cont= ext *ac, (unsigned long) ac->ac_o_ex.fe_logical); BUG(); } - BUG_ON(size <=3D 0 || size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb)); + BUG_ON(size <=3D 0 || size > bpg); =20 /* now prepare goal request */ =20 --=20 2.31.1