Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1663335rwb; Mon, 7 Nov 2022 04:29:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM65mxVRpqcVd6ecMMZWUcZV8btb1iZL/SgRXY1Wb6AZeItZpuEZXELsy+QTyN++jo8EW3t7 X-Received: by 2002:a17:90b:4b46:b0:213:f97a:ccd8 with SMTP id mi6-20020a17090b4b4600b00213f97accd8mr37544695pjb.55.1667824149926; Mon, 07 Nov 2022 04:29:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667824149; cv=none; d=google.com; s=arc-20160816; b=D2EJFHE5nrdaZtMQ4comyFlNUrOdbhTsSRoK+V+KicXCOA7PnVCU79gh9OJ8OTXInq 5b36XnGa0osv3zu4OF/4aiiqsdEzWMmHWRwm4Tatcn62mImbVeOu5xzAQeq/UlkZw7Bf UaSc4ZG7MiU+WSJHsdBx6bd4jxtvBYuHLwSN3syy+aArkw4HR6cnp0S5J5rJ30Nd4acm 9y1DpSU5+iGpD5kRaLuSvJ+m+9TsJxH56f4SZEE5GUFWy0HQuYlEEwV3ZVjN6sQ05rQD FTOmcc1RHKjJG6AY03T/vI9LZx/drP+igDNV/Jw5MtJek0201JMLNpgk71CfO1lgPi5W dDCQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U3+ch67cgLBbn0L6V94LJXJr3S/uxJxECMuGxF8cj5o=; b=tpocFeP1whsRDd/3LAYlVhCtDhAmlgmta5hDCfbZeDe74Z56G+agrJVUYLcwzDS19r 6L1ES/DyN3V4NBNo1AQS8cR7cyl6AypJ6PqPtUj5nxLzKe2z5IsCJ/8Q3DeE9lfg8Ieg /qeMUC7fXYIEtj8Q8fejcamoHnvt0ZVCLVP/F4Y7unDva6uhgadyqzgX21Y5iSxEOuYg EawXtsg2OAVkPT9XscLHvVVE9kEsJFsKIsGlrmEDCS8OwJ1GjHdAGXvdo1szf22cC4dA YPzF9tqiDWYtzJRUwjHKr5WvTPcAF1UXlKJXteoyqjcTTYll+E5XpeSD53DW9TRyDzh/ MTmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BR1hUebD; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x30-20020a056a00189e00b005638baac87csi11230318pfh.64.2022.11.07.04.28.57; Mon, 07 Nov 2022 04:29:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@gmail.com header.s=20210112 header.b=BR1hUebD; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232295AbiKGM2h (ORCPT + 99 others); Mon, 7 Nov 2022 07:28:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232256AbiKGM2b (ORCPT ); Mon, 7 Nov 2022 07:28:31 -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 E40691B9F6 for ; Mon, 7 Nov 2022 04:28:21 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so10169204pji.0 for ; Mon, 07 Nov 2022 04:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U3+ch67cgLBbn0L6V94LJXJr3S/uxJxECMuGxF8cj5o=; b=BR1hUebDNKgjB1qq+Nzbo6U/Z67vJ78KT3DXNcHZ04c9ShwQ1NU212ueAoMYIc5tHX 4FYBGCOZscEXARSdBHn75N8CsaVb69tGYj3UmyiEuwjSDdaa6u8hdQwpQWrnwQXef+EW Zqb9h0a1wfbHywGRH9xWVGxh17yHojwDJnXXqd0a8FlwmxBtz+lZHmbHfENcx73xocQ9 sd6ezF4xVRG+AKWapDOvJCpRl5EHpJvYPdkfhj/LHf1z64x64rFdsoVqfeDwjV+0wpQg hzECqBNcTQQnqC265Rw6JH8y5Vm4LIDhv1XL3oUObd8msJ+uJ9VEoI/7GuSKv3+40iuf NGig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U3+ch67cgLBbn0L6V94LJXJr3S/uxJxECMuGxF8cj5o=; b=W7bOw0SNqPGRrKjHipVmPjpsKvC5RxgOXzxuXQNLssoXO9lNFcFI5xEyC5X5c4vZh/ w8q91fqrRsElkkJE85HHjVM/7qjeEjVYrSbRDnS/Fh7kANWGV+vB9W27EE9qEz91Fvap TW/kGYbOX1dei3upuBJBlG3e+d/kVGlZjKl7ewY9FpIrOkzKgh5k/goE3hnQVRyENiPh 6wbnB8SDEEjKCUlEujPSZ9zioFk+UmHfnb0se9muZCnN0QO2tyASe1tDQ4u02IfuR+6w RscWLWQ4t8TOOGEFFTQepLpv32brrzioAHLOY85b1ilveE+dCqFTr6e5ISa/ApTNaUNu R2WA== X-Gm-Message-State: ACrzQf0u1jVHkB6AzWEzWT7Erd9uZa9jYcyMok0nuKUrCEhsGP+QSU0o CQBQSK4DZKzIdejfuUx5n8s= X-Received: by 2002:a17:90b:19d1:b0:213:7030:6bd9 with SMTP id nm17-20020a17090b19d100b0021370306bd9mr51816168pjb.43.1667824101353; Mon, 07 Nov 2022 04:28:21 -0800 (PST) Received: from localhost ([2406:7400:63:f20b:312d:45b2:85c1:c486]) by smtp.gmail.com with ESMTPSA id y13-20020a170902b48d00b001869f2120a5sm4854904plr.34.2022.11.07.04.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 04:28:20 -0800 (PST) From: "Ritesh Harjani (IBM)" To: Theodore Ts'o Cc: linux-ext4@vger.kernel.org, Harshad Shirwadkar , Wang Shilong , Andreas Dilger , Li Xi , Ritesh Harjani Subject: [RFCv1 59/72] e2fsck: update mmp block in one thread Date: Mon, 7 Nov 2022 17:51:47 +0530 Message-Id: <48d152d713a9af21eefbfa69b26a7dd417f0897c.1667822611.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-ext4@vger.kernel.org From: Wang Shilong For multiple threads, different threads will try to update mmp block at the same time, only allow one thread to update it. Signed-off-by: Wang Shilong Signed-off-by: Ritesh Harjani (IBM) --- e2fsck/e2fsck.h | 1 + e2fsck/pass1.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index 01bd9d01..2dd7ba27 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -488,6 +488,7 @@ struct e2fsck_struct { #ifdef HAVE_PTHREAD __u32 fs_num_threads; + __u32 mmp_update_thread; int fs_need_locking; /* serialize fix operation for multiple threads */ pthread_rwlock_t fs_fix_rwlock; diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 93cff80e..ed4275c3 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -1509,7 +1509,8 @@ void e2fsck_pass1_run(e2fsck_t ctx) dgrp_t ra_group = 0; struct ea_quota ea_ibody_quota; struct process_inode_block *inodes_to_process; - int process_inode_count; + int process_inode_count, check_mmp; + e2fsck_t global_ctx = ctx->global_ctx ? ctx->global_ctx : ctx; init_resource_track(&rtrack, ctx->fs->io); clear_problem_context(&pctx); @@ -1672,8 +1673,30 @@ void e2fsck_pass1_run(e2fsck_t ctx) #endif while (1) { + check_mmp = 0; e2fsck_pass1_check_lock(ctx); - if (ino % (fs->super->s_inodes_per_group * 4) == 1) { +#ifdef HAVE_PTHREAD + if (!global_ctx->mmp_update_thread) { + e2fsck_pass1_block_map_w_lock(ctx); + if (!global_ctx->mmp_update_thread) { + global_ctx->mmp_update_thread = + ctx->thread_info.et_thread_index + 1; + check_mmp = 1; + } + e2fsck_pass1_block_map_w_unlock(ctx); + } + + /* only one active thread could update mmp block. */ + e2fsck_pass1_block_map_r_lock(ctx); + if (global_ctx->mmp_update_thread == + ctx->thread_info.et_thread_index + 1) + check_mmp = 1; + e2fsck_pass1_block_map_r_unlock(ctx); +#else + check_mmp = 1; +#endif + + if (check_mmp && (ino % (fs->super->s_inodes_per_group * 4) == 1)) { if (e2fsck_mmp_update(fs)) fatal_error(ctx, 0); } @@ -2437,6 +2460,13 @@ endit: print_resource_track(ctx, _("Pass 1"), &rtrack, ctx->fs->io); else ctx->invalid_bitmaps++; +#ifdef HAVE_PTHREAD + /* reset update_thread after this thread exit */ + e2fsck_pass1_block_map_w_lock(ctx); + if (check_mmp) + global_ctx->mmp_update_thread = 0; + e2fsck_pass1_block_map_w_unlock(ctx); +#endif } #ifdef HAVE_PTHREAD -- 2.37.3