Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1313921pxb; Tue, 8 Feb 2022 14:26:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwdjxgdvg2RzL2J4uMopeZJfaGekCHf/mEBPMUnUXB+peCeuFf09xwhsJPgns8l9T0dg5T X-Received: by 2002:a17:902:7595:: with SMTP id j21mr6616848pll.79.1644359210184; Tue, 08 Feb 2022 14:26:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644359210; cv=none; d=google.com; s=arc-20160816; b=hpgh1ep31dQwWT9WFtQTCm3dSGrelRQKe1E+czgUDw1BWVSii+lIuJpWiJKBv7/2AP 2LxulWjtv2V4pkUupGAl+p05oO2BQmXc/Kv5dcbr6E8ftVr7S9A9zpKb1B89aiVg9aMq 21WnAnWhyBQrmd9dS+xk8D4Ggm4lslAQbqWuz49AbqgfZZr8keieqvmloxHRSX4Sl7MA Xh3YIxoTMj4WO5cOZfwAyby+pJXx3QhVKzP/HU2rj7huTpgqvl2+zS8b5iWkycGIFO0H Byofwl+CZr7t6k1Ln0yEUsr9cmvB3CDEfj0VavApMA78NElrhkKElyWZKs0Xj9VoIKNh 42/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Qym7ICq1f/lNyUm4WZnwuJ1pby5ZNcEoM1GJ1g0I6Eo=; b=b89ZAhqlzCfw60paxRvaQhCDrpb5BhlirsMWY+RtNBbbEw65dBXXkYahkj7dKslPFn HQWNdraI41/AeMnElGLuq5Wgh7mzJvBAL9u2/pfs23j7h7hmtFje31gKfS2viH4VpvhR bdWzmJxP14MtoCwF+hjvaLZFCVyHxaKUdMVdb4h/6y02lcr1f7MWjoOZPmlC+fjx0sN5 wA5V3a/dYmndEJK2UeTmgYXV2yVUZIHc2Qn4OVe+QVrAmz30ve+XWn4Jap4sRPDTn7CM XRDSCzTWNKUhsJm1HxHr7x6syhQizaAx0VApUuAmbY6+eD3V8YSCVEqX8y8qea8fyjDP iljw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2reOLNQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e67si7419579pgc.208.2022.02.08.14.26.36; Tue, 08 Feb 2022 14:26:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2reOLNQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382214AbiBGMBC (ORCPT + 99 others); Mon, 7 Feb 2022 07:01:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386710AbiBGLgR (ORCPT ); Mon, 7 Feb 2022 06:36:17 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3D70C0401E6; Mon, 7 Feb 2022 03:36:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6EBC1B8112C; Mon, 7 Feb 2022 11:36:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67C04C004E1; Mon, 7 Feb 2022 11:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233774; bh=TU7dy6IjSz60N6jVr/tfuxaZIh8qCIsBtKViXY1Pn5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2reOLNQvyw2VZddMSPDm1sjlVLb8GQwjzEOXbcceXUCwla6f7USxsIKwZ0PC/X4s/ lFPmSoVKI572gG5DAfef9EBH2M7cBA5ykeyHYxmJKlE+L8FV4sa4esCBKpI66Y6Voq DbXv8zY6owXfzJcGHwQrWj7ZIYVZRFkYAzsvFrlQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Yin , Theodore Tso , stable@kernel.org Subject: [PATCH 5.16 115/126] ext4: prevent used blocks from being allocated during fast commit replay Date: Mon, 7 Feb 2022 12:07:26 +0100 Message-Id: <20220207103808.033200848@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Yin commit 599ea31d13617c5484c40cdf50d88301dc351cfc upstream. 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 Link: https://lore.kernel.org/r/20220110035141.1980-2-yinxin.x@bytedance.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/ext4.h | 3 +++ fs/ext4/extents.c | 4 ++++ fs/ext4/fast_commit.c | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2936,6 +2936,9 @@ void ext4_fc_replay_cleanup(struct super int ext4_fc_commit(journal_t *journal, tid_t commit_tid); int __init ext4_fc_init_dentry_cache(void); void ext4_fc_destroy_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); /* mballoc.c */ extern const struct seq_operations ext4_mb_seq_groups_ops; --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -6101,11 +6101,15 @@ int ext4_ext_clear_bb(struct inode *inod 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 = cur + map.m_len; } --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1606,16 +1606,23 @@ out: } /* - * 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; state = &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 != state->fc_regions_valid) + state->fc_regions_used = state->fc_regions_valid; if (state->fc_regions_used == state->fc_regions_size) { state->fc_regions_size += EXT4_FC_REPLAY_REALLOC_INCREMENT; @@ -1633,6 +1640,9 @@ static int ext4_fc_record_regions(struct region->pblk = pblk; region->len = len; + if (replay) + state->fc_regions_valid++; + return 0; } @@ -1980,7 +1990,7 @@ static int ext4_fc_replay_scan(journal_t ret = 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 = JBD2_FC_REPLAY_CONTINUE;