Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1657431rwb; Mon, 7 Nov 2022 04:24:50 -0800 (PST) X-Google-Smtp-Source: AMsMyM4L0+LQN95g/J6l+Zus+KnIzuCMK/UsPWklut2J44D2QAK29hv8EKnNrLRzoZ+4Qjj0QEAQ X-Received: by 2002:a17:907:7f2a:b0:7ae:3c2c:942d with SMTP id qf42-20020a1709077f2a00b007ae3c2c942dmr15029491ejc.714.1667823890414; Mon, 07 Nov 2022 04:24:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667823890; cv=none; d=google.com; s=arc-20160816; b=gOltdOVnMl2hn3FpPLgHwjeMmwnOefFYtjlwMHA37u0uZdmlpFnbwUKCLyp+hObqDm Yl0d+Igx0yCNSKL5xefbBPfzTr9EYx7CFsvVeTvqSi0NoE7DTcDEyLVuuTdikIGgM6jy H8zpGrflIdCv+CR9L818LT24QSZ0QnEKIq0IYSfIHvFaFxAGKhTG0duM/CgMOeXIChTT AQfvO62H7y8cvzRhrA3ED392Uq/sXl+ySokHvioqsJpCPRGZKamB61Z+JXMuYrVYhyeB AotFupS2/HAXXOGtbU8a2zD/vXllg2Bk8X/yf7DNI28F5HFVatnILjY23mcje07xjtqJ /9JA== 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=/wJhWS2aGvLD1Rzy6m9shGLETN6RBjRGDzQAAEc0ebw=; b=KTg9VoTCIotmdmGBXZeXyvhxHNxyZBLk5VqF+taslguoNxTQFKJ2t95EgXgVT7UGP2 +//WICdV8dLeirB3DygWV8kqqGdyyLTJYbDY0yNFCKhpeA2Urd5ta20/beFFnGxXpoKH NpulwKcluKMjNqS5GNemNPRRCSdaH4Aflry7MYE94Jfz7kyLaZ71OyXen9Q/6Aqu1XB7 l6q6ukjGKeFkYQWJaEkoGmlA+K2QzitjztCK6Zk5UEa3oWk6VxZ0uCAGgu9bMir/u4jB hvEW2Qv7Eywd5JKU673Xb1bxIZjGrk1zMapMeyYb5QL45YX7RBZhVeN6jWEZNcr7qDXK tKeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=L9zXQk7s; 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 u2-20020a1709063b8200b007429f0c69ccsi7349727ejf.579.2022.11.07.04.24.26; Mon, 07 Nov 2022 04:24:50 -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=L9zXQk7s; 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 S232173AbiKGMYP (ORCPT + 99 others); Mon, 7 Nov 2022 07:24:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232169AbiKGMYN (ORCPT ); Mon, 7 Nov 2022 07:24:13 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 428806247 for ; Mon, 7 Nov 2022 04:24:13 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id k22so10448240pfd.3 for ; Mon, 07 Nov 2022 04:24:13 -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=/wJhWS2aGvLD1Rzy6m9shGLETN6RBjRGDzQAAEc0ebw=; b=L9zXQk7s1hKr7oC1W6uzkSPg+65h4hWVhusIgbbV3utkHI7OGzUUibHE2tm6yZjxm6 K1q/fsDBZxA+xUQxIIGrEFJ/ULylIVupMqvrqkX6seOQ8CQ5G0lAODPThekk7giV+ult kjs0cCcUNpimNfL1pEH1iYNNKHqHS52zeSMm5d50wuxT0zG8JwJLLVb9Dobi9byBmxh3 ovhOHqoiB3FEcAD7MiZNvyx/UebBP+0Ar11OD3krGfRyjJNGGNaedZ/aCNtuXk26C/vT FdSLzXz1c4GJio0iQdtM3cuIkahC+0poJZJ+rWw0xB1GR68LDbDTcrkbjHSFBuOkYuUR +zqA== 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=/wJhWS2aGvLD1Rzy6m9shGLETN6RBjRGDzQAAEc0ebw=; b=CAeJzfgBxUfhd7zJu0Me87he4/C9GcGhXUXY68+3GddBFW45qLpMlQUcIypGraw7PB o8pQwtovnFF/EdpbNcObuR7S1QtjS6KLEEUYOlwsH+hBBqr3Bn2215KmoV2oUPy90TBN f0csjjijG/d8hDokt0L12oAB+F8aZmoCX1lJ5cNLKDVC/IqcLZzpQbsacAKbODvhoZCX 8rOfc0IO7wMvmCRiDmvt2PERMLSMbgYlnwkAxZ65/n4C9R9mYTGVu06RFkeEUYDqtQ1J 3rGcjVBW2H7alIWvbk0Uk2TRdC+bMtD+C/Td3G5GkACAbORdi/cu4NBoKUsjz/xyx7d2 RyFw== X-Gm-Message-State: ACrzQf1tx4iTUsnKmKQn6ExYBAyN824NMLOcFTB042Qw23emBaOaJaHR nW+uaYyMmqz/PzUirxbTucQ= X-Received: by 2002:a65:4d07:0:b0:46f:ed91:a50d with SMTP id i7-20020a654d07000000b0046fed91a50dmr27395440pgt.343.1667823852789; Mon, 07 Nov 2022 04:24:12 -0800 (PST) Received: from localhost ([2406:7400:63:f20b:312d:45b2:85c1:c486]) by smtp.gmail.com with ESMTPSA id q66-20020a17090a17c800b0021282014066sm6103510pja.9.2022.11.07.04.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 04:24:12 -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 18/72] libext2fs: Add support to get average group count Date: Mon, 7 Nov 2022 17:51:06 +0530 Message-Id: <7e4f563719aee1970dd1058ca45b0609ae4c7c5f.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 number of threads in pfsck should not exceed flex bg numbers. This patch adds the support in libext2fs to calculate ext2fs_get_avg_group() which returns an average group count which each thread has to scan. fs->fs_num_threads will be set by the client, in this case e2fsck. No. of threads will be passed along with -m option while running e2fsck. That will also set fs->fs_num_threads, which will help in controlling the amount of memory consumed to maintain in memory data structures (per thread) in case of multiple parallel threads (pfsck) to avoid oom. Signed-off-by: Wang Shilong Signed-off-by: Ritesh Harjani (IBM) --- lib/ext2fs/ext2fs.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index b1505f95..6b4926ce 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -279,10 +279,11 @@ struct struct_ext2_filsys { int cluster_ratio_bits; __u16 default_bitmap_type; __u16 pad; + __u32 fs_num_threads; /* * Reserved for future expansion */ - __u32 reserved[5]; + __u32 reserved[4]; /* * Reserved for the use of the calling application. @@ -2231,6 +2232,35 @@ ext2fs_orphan_block_tail(ext2_filsys fs, char *buf) sizeof(struct ext4_orphan_block_tail)); } +static dgrp_t ext2fs_get_avg_group(ext2_filsys fs) +{ +#ifdef HAVE_PTHREAD + dgrp_t average_group; + unsigned flexbg_size; + + if (fs->fs_num_threads <= 1) + return fs->group_desc_count; + + average_group = fs->group_desc_count / fs->fs_num_threads; + if (average_group <= 1) + return 1; + + if (ext2fs_has_feature_flex_bg(fs->super)) { + int times = 1; + + flexbg_size = 1 << fs->super->s_log_groups_per_flex; + if (average_group % flexbg_size) { + times = average_group / flexbg_size; + average_group = times * flexbg_size; + } + } + + return average_group; +#else + return fs->group_desc_count; +#endif +} + #undef _INLINE_ #endif -- 2.37.3