Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1537945pxb; Tue, 8 Feb 2022 21:32:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzEFu59i5ujI+QBPe3lDgkq1bwHCn4WplEyuNjtfojLHrxoW2J+THDXvn+rAsF+73cz/HFp X-Received: by 2002:a62:1c8b:: with SMTP id c133mr599206pfc.33.1644384751905; Tue, 08 Feb 2022 21:32:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644384751; cv=none; d=google.com; s=arc-20160816; b=WmjkbhQvBdVqomh+pkZo8ZCeds7ZtKBh+V0dKhoTA26f2X2iQvluKDQxJDSkqElS5w JMTgpWn/xqWoclTbJqdolg3KfxowD72U7viApz62NJpLqNAGE8C1jqtqNNxshRUBlHt3 GvOsRElwbdFlcGIaXW1GK7CNQOcYdXvJTsJ731VBhebgeQ+2V9YWTngnlK8dcCRHgR0f neAmYcxJyUnIiyhIVn7LOPhKS4/Z1dPeE/VHQzI7C5WSzyX0DxUeodx2nPJNKHRRzD7B RluysUc4/RBhPlyRYyIz+J2egDXADOYV2EudI0LrEm8abYzS6Rt0OoK4ahiVwy4ZUcjE hezQ== 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=Ly56TP20nYI7Kzm+FRV5AG1gkXPTglCI0W39EyTGOPM=; b=A4TZlmBXzgfH4OscQYwXWJimR9YVkT5EjL44hUYlpy14fMNfSgHA0xlT06rG2zS08r LOPa9xe8sPEB3YrOx5UWCEVhX1J8AEt0V6FUs/O9WKBC6KTVBOQZal4PHZtEag6NPT4l GoVTK0Ap+8nzpHLnquxFu1plVmx2MfP5iBm6uyUs7x/wHBhdnd1liSw+AlUibdOfpfav d/zTD+IbyvsitraQl1K8FRUdW3Y8m5IM+mT5Xt7aXlXoup/rsMVLTEHusC5J1/dHA0Yv 41YU0IMPTBpaWMvq+tHVUbB+CRVdOmNUNhuU2x4nZ8oa18UAzzm6uwUdt8W9ipHl3f22 pJtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wmGWbHw2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 1si4070636pjh.77.2022.02.08.21.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 21:32:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wmGWbHw2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E2A6EC02B5D3; Tue, 8 Feb 2022 21:31:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386432AbiBGLeh (ORCPT + 99 others); Mon, 7 Feb 2022 06:34:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383871AbiBGLXu (ORCPT ); Mon, 7 Feb 2022 06:23:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1170FC0401C4; Mon, 7 Feb 2022 03:23:47 -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 AAA01B8111C; Mon, 7 Feb 2022 11:23:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40B5CC004E1; Mon, 7 Feb 2022 11:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233025; bh=+0N3nRukO1GQN2mvogj92JZma4Oi/VLjvAT+GztctPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wmGWbHw20WH2Khw9EPB//I847mxUuO+VcSWAdQvxZNv6Ix99M1hGiUji3aY6nMxTZ WIEGLbVo6TJcjchGIpnTsh3/hHpc/0VS9akKzsCfnqwAamtXVSWo+gor41TuVnrex+ m83D9WMYlbFR10uvu7KmiSQmiq+9ADM0wlmlbDCo= 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.10 67/74] ext4: prevent used blocks from being allocated during fast commit replay Date: Mon, 7 Feb 2022 12:07:05 +0100 Message-Id: <20220207103759.426782898@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.232676988@linuxfoundation.org> References: <20220207103757.232676988@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.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 @@ -2779,6 +2779,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 @@ -6088,11 +6088,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 @@ -1558,16 +1558,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; @@ -1585,6 +1592,9 @@ static int ext4_fc_record_regions(struct region->pblk = pblk; region->len = len; + if (replay) + state->fc_regions_valid++; + return 0; } @@ -1954,7 +1964,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;