From nobody Tue Jun 30 20:10:38 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 801E6C433FE for ; Mon, 10 Jan 2022 03:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238432AbiAJDwO (ORCPT ); Sun, 9 Jan 2022 22:52:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238414AbiAJDwI (ORCPT ); Sun, 9 Jan 2022 22:52:08 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4B7BC061748 for ; Sun, 9 Jan 2022 19:52:07 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id l10-20020a17090a384a00b001b22190e075so20791630pjf.3 for ; Sun, 09 Jan 2022 19:52:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7te4fBQgwRS2Iw5emYEKUEH67E4Lg1hDqrgyyrBzcMA=; b=3mRoslvnjf/54OKUc1rIZ35RScGfEtoKuqW6f94mpsSk42iDIA7elb2eqdvXqTqSDl gLx49Wwx7Gabq+toavSghkIvR5J/mE54PVtsWS1TuQptsB+VLF5u+ozv/VUlqZr7VbWv OpYT0Epaow/ZGvGIx6CX1pHpckBUhzQNnKyE9h/RFRW2XfxKAbo48DLzAwW8psl224tN PS96+e5mjXrGpnXYYwuQ9ncmzMtGhyOry9U1LAx3BawFZbzcyfQGQ7aT0JlTPZA/nkz3 tCn6ZcuwfIOvXmv0Y5BtmhD9BYdswDWI49NJ01ylJyyRZHjeQU4MYpp6Xyhs6BdUNUnj szeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7te4fBQgwRS2Iw5emYEKUEH67E4Lg1hDqrgyyrBzcMA=; b=RHjhAgMtENz1/v12sAk/a44stCdj+HymqC7P6K6d/cF8dOgK6b2z8bmmKhWP6K27DC XQoILNGLGQK5pt34w40C7y3sODu0B8rzVuA/1kotb1h52WCyIZjmew+t2yEYJi1MHryf 0kYNAqi3k6H31deYE029+MVaI3cFKZTgA3jNLbBQ2rCIsXnK7lFvIMOk1QFA6XAligxQ foGE6LdhuNIKIoI9cjshwuVxYUf7/X8bxuy3kavRqwtj7v8993kpdN0HlqC8737ZtsXb /aTGK/eabN3F5NxjWH7LPEaZTtWf4fmpK13I+YljDmlVaHKFodj6Juv7xez6g9+uOUoh JbSw== X-Gm-Message-State: AOAM531C7bnDw/sj+6OyGidRHqUGg5KOoIBMu2sy91MiCEm+YQk6rewt qeluSXl2QqspgSCBjSa1M2I7EQ== X-Google-Smtp-Source: ABdhPJxCme/Hhfy90yO06PBqyoQoQGTgOgxEY3e/rDP2CF2kz/hnaG2Mo1J9IBACQ6/mLdKaTcFCOA== X-Received: by 2002:a17:90b:3e87:: with SMTP id rj7mr28312761pjb.88.1641786727295; Sun, 09 Jan 2022 19:52:07 -0800 (PST) Received: from yinxin.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id h3sm6772748pjk.48.2022.01.09.19.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 19:52:07 -0800 (PST) From: Xin Yin To: harshadshirwadkar@gmail.com, tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Xin Yin Subject: [PATCH v2 1/2] ext4: prevent used blocks from being allocated during fast commit replay Date: Mon, 10 Jan 2022 11:51:40 +0800 Message-Id: <20220110035141.1980-2-yinxin.x@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220110035141.1980-1-yinxin.x@bytedance.com> References: <20220110035141.1980-1-yinxin.x@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" during fast commit replay procedure, we clear inode blocks bitmap in ext4_ext_clear_bb(), this may cause ext4_mb_new_blocks_simple() allocate blocks still in use. make ext4_fc_record_regions() also record physical disk regions used by inodes during replay procedure. Then ext4_mb_new_blocks_simple() can excludes these blocks in use. Signed-off-by: Xin Yin --- v2: add comments for behavior change of ext4_fc_record_regions(). --- fs/ext4/ext4.h | 2 ++ fs/ext4/extents.c | 4 ++++ fs/ext4/fast_commit.c | 20 +++++++++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 82fa51d6f145..7b0686758691 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2932,6 +2932,8 @@ bool ext4_fc_replay_check_excluded(struct super_block= *sb, ext4_fsblk_t block); void ext4_fc_replay_cleanup(struct super_block *sb); int ext4_fc_commit(journal_t *journal, tid_t commit_tid); int __init ext4_fc_init_dentry_cache(void); +int ext4_fc_record_regions(struct super_block *sb, int ino, + ext4_lblk_t lblk, ext4_fsblk_t pblk, int len, int replay); =20 /* mballoc.c */ extern const struct seq_operations ext4_mb_seq_groups_ops; diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index c3e76a5de661..9b6c76629c93 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -6096,11 +6096,15 @@ int ext4_ext_clear_bb(struct inode *inode) =20 ext4_mb_mark_bb(inode->i_sb, path[j].p_block, 1, 0); + ext4_fc_record_regions(inode->i_sb, inode->i_ino, + 0, path[j].p_block, 1, 1); } ext4_ext_drop_refs(path); kfree(path); } ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, 0); + ext4_fc_record_regions(inode->i_sb, inode->i_ino, + map.m_lblk, map.m_pblk, map.m_len, 1); } cur =3D cur + map.m_len; } diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 23d13983a281..0812438d10cc 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1564,16 +1564,23 @@ static int ext4_fc_replay_create(struct super_block= *sb, struct ext4_fc_tl *tl, } =20 /* - * Record physical disk regions which are in use as per fast commit area. = Our - * simple replay phase allocator excludes these regions from allocation. + * Record physical disk regions which are in use as per fast commit area, + * and used by inodes during replay phase. Our simple replay phase + * allocator excludes these regions from allocation. */ -static int ext4_fc_record_regions(struct super_block *sb, int ino, - ext4_lblk_t lblk, ext4_fsblk_t pblk, int len) +int ext4_fc_record_regions(struct super_block *sb, int ino, + ext4_lblk_t lblk, ext4_fsblk_t pblk, int len, int replay) { struct ext4_fc_replay_state *state; struct ext4_fc_alloc_region *region; =20 state =3D &EXT4_SB(sb)->s_fc_replay_state; + /* + * during replay phase, the fc_regions_valid may not same as + * fc_regions_used, update it when do new additions. + */ + if (replay && state->fc_regions_used !=3D state->fc_regions_valid) + state->fc_regions_used =3D state->fc_regions_valid; if (state->fc_regions_used =3D=3D state->fc_regions_size) { state->fc_regions_size +=3D EXT4_FC_REPLAY_REALLOC_INCREMENT; @@ -1591,6 +1598,9 @@ static int ext4_fc_record_regions(struct super_block = *sb, int ino, region->pblk =3D pblk; region->len =3D len; =20 + if (replay) + state->fc_regions_valid++; + return 0; } =20 @@ -1938,7 +1948,7 @@ static int ext4_fc_replay_scan(journal_t *journal, ret =3D ext4_fc_record_regions(sb, le32_to_cpu(ext.fc_ino), le32_to_cpu(ex->ee_block), ext4_ext_pblock(ex), - ext4_ext_get_actual_len(ex)); + ext4_ext_get_actual_len(ex), 0); if (ret < 0) break; ret =3D JBD2_FC_REPLAY_CONTINUE; --=20 2.20.1 From nobody Tue Jun 30 20:10:38 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 06F7EC433F5 for ; Mon, 10 Jan 2022 03:52:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238453AbiAJDwT (ORCPT ); Sun, 9 Jan 2022 22:52:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238425AbiAJDwM (ORCPT ); Sun, 9 Jan 2022 22:52:12 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0FFC061748 for ; Sun, 9 Jan 2022 19:52:12 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id i6so10853646pla.0 for ; Sun, 09 Jan 2022 19:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pB9ixd309jdajttTHm9n2WuXxz/2zgca6PMdCtbA1H8=; b=JiSVlDh8pZAweLjogrN0kItEt37c3PSlPokmWmgOa3LUMXXdshgqk0qCC/hNfEmxkl JLGCmQlnoZvE7ID8Ud4iUHoVwGtEqQqNjCl+IzHxZ52ph7lYy4+2CmWEYc1PGy62fgFu HmaZSoyNxBFbCaageCC0uoto2M0BDXf4ZadWJwe3iG9uRxm9V0X2gzASl07sKTLk7rWK 1me5a25xnZQKtBwmEBsorWdlp1rHcWjWvTa6jgkLm4VxNFkBjgIMS8dfjaKMgRHn255Y V89ZP4+vE44EQ1AY0dcZNURpc4mrErmw61/Hrc9JtSlayB7I6lNT7eW6D8zLKRTcpNFX tVqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pB9ixd309jdajttTHm9n2WuXxz/2zgca6PMdCtbA1H8=; b=Da7AqFN8iij6WZx02g8cnWoco1FzUKtrQ+U8JwUGw4a1GPiSAMp2cmvz2qGrUST4MO /3hdauaFL1nqTb4e5Ds2QO053ERIx12d7riQB+R4oBrFL9MLxVsljdZstYKlN4wn0OXz lZrnSSt+p3o5m1ivrRu5jhfJgenQRVi620xfIWpmpMMG+56G2eHYIZeQh76fc+2P1w83 fgAxd3FDVaU2+yV+KYXQVymBTsi6p2ndiZyU4pSCIz2xhcbDYBqlMASjgpcuuSqdYaav wq00lhzNaUNxmxLx0CIwrPfC5SWlxzHSV5UUqGbHSOM9cGingHRlY3AunP45ZYO/Is/p 9CNg== X-Gm-Message-State: AOAM530iIXajkIhwaGEz0EWDFFpm89cuSklSo4hg6AIzm2r4P/ZDisvO W/GBPNu9JIdKPfpE4YfX2hnENw== X-Google-Smtp-Source: ABdhPJyMSTHmHtRjgnnOsrjOHTZlabUIYWfszTl11z8L0Kp1Yi8K9dWOOyzv03+lx04yv/iSFCSe9Q== X-Received: by 2002:a17:902:c406:b0:14a:4178:af93 with SMTP id k6-20020a170902c40600b0014a4178af93mr1195818plk.154.1641786731979; Sun, 09 Jan 2022 19:52:11 -0800 (PST) Received: from yinxin.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id h3sm6772748pjk.48.2022.01.09.19.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 19:52:11 -0800 (PST) From: Xin Yin To: harshadshirwadkar@gmail.com, tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Xin Yin Subject: [PATCH v2 2/2] ext4: modify the logic of ext4_mb_new_blocks_simple Date: Mon, 10 Jan 2022 11:51:41 +0800 Message-Id: <20220110035141.1980-3-yinxin.x@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220110035141.1980-1-yinxin.x@bytedance.com> References: <20220110035141.1980-1-yinxin.x@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" for now in ext4_mb_new_blocks_simple, if we found a block which should be excluded then will switch to next group, this may probably cause 'group' run out of range. change to check next block in the same group when get a block should be excluded. Also change the searche range to EXT4_CLUSTERS_PER_GROUP and add error checking. Signed-off-by: Xin Yin --- fs/ext4/mballoc.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 215b7068f548..31a00b473f3e 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5757,7 +5757,8 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_= t *handle, struct super_block *sb =3D ar->inode->i_sb; ext4_group_t group; ext4_grpblk_t blkoff; - int i =3D sb->s_blocksize; + ext4_grpblk_t max =3D EXT4_CLUSTERS_PER_GROUP(sb); + ext4_grpblk_t i =3D 0; ext4_fsblk_t goal, block; struct ext4_super_block *es =3D EXT4_SB(sb)->s_es; =20 @@ -5779,19 +5780,26 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handl= e_t *handle, ext4_get_group_no_and_offset(sb, max(ext4_group_first_block_no(sb, group), goal), NULL, &blkoff); - i =3D mb_find_next_zero_bit(bitmap_bh->b_data, sb->s_blocksize, + while (1) { + i =3D mb_find_next_zero_bit(bitmap_bh->b_data, max, blkoff); + if (i >=3D max) + break; + if (ext4_fc_replay_check_excluded(sb, + ext4_group_first_block_no(sb, group) + i)) { + blkoff =3D i + 1; + } else + break; + } brelse(bitmap_bh); - if (i >=3D sb->s_blocksize) - continue; - if (ext4_fc_replay_check_excluded(sb, - ext4_group_first_block_no(sb, group) + i)) - continue; - break; + if (i < max) + break; } =20 - if (group >=3D ext4_get_groups_count(sb) && i >=3D sb->s_blocksize) + if (group >=3D ext4_get_groups_count(sb) || i >=3D max) { + *errp =3D -ENOSPC; return 0; + } =20 block =3D ext4_group_first_block_no(sb, group) + i; ext4_mb_mark_bb(sb, block, 1, 1); --=20 2.20.1