Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp597526rwb; Fri, 18 Nov 2022 05:58:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4u00h+6BidiuORS24twCUJaQZZ3n9c52yJONV51FjhMiNYgNEBvxnimUoahz4hwemLGdC2 X-Received: by 2002:a17:906:5146:b0:7ad:f270:c128 with SMTP id jr6-20020a170906514600b007adf270c128mr6011982ejc.84.1668779896442; Fri, 18 Nov 2022 05:58:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668779896; cv=none; d=google.com; s=arc-20160816; b=VIcnFYJkra/k2VaakiSTR55dV+Clwx/B+okBXEevlDKbaFxlSM6G2kFc0KYie/OSTH AaqVG2q2Je2OXY9AQmG58WHvikBo0MBBtaWNx3ri/dt0r+CjjB+DY2QIv5t8/3fFo1Ef qx7PddpL5EEkFqV4aTYCCLNTOgOwEKxllt9ylYXaKqzKDOOl6wCRTV4/sQtdw1OJ3twQ RB3roj3fX7igDN6L3IjIwL+wdeZVr6ORsC25YGzxB+bky8OBGCaLDnKsvckp13WaGNs6 623zS6kmTLkvXz3kg+m/ZJrgxklOqaMKJy8NenRm5IqkWXr1bF9KfySKupawI/dnazCw rNPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:in-reply-to:cc:references:message-id:date :subject:mime-version:from:content-transfer-encoding:dkim-signature; bh=GBWb7Q2jF9gggScD/vZOvEkx46gLiqyFIEP0hDuxtSw=; b=nl/zfatragKPMINB6/Xy6aoFcAHIfRr+lH089HpTX0UqqVt3gFCvdvc5NjbSfvhG33 0DNQd+wqUaqjmOAskQyZP09ohncgsJ4VNP1X1r9Kxx2GGSFhXYsWi5U/F5TG0c0YWIok mG0kU2WUTfltSL7D1NhXC50fmYDMZD7/e1gpEpIqGmxPAFW4iGMFWjseEvRUzm01rOVB 9A+1GDGlB9Kwg15N7N6HfqFz2Io/NWkSwKISDkj4LMV8FxwnYX9sWXOfscXKbE2zM4bn y0CjMKF5Rwd3SsWRIiRb4H4gjXAQGs6uV3aH6wuQmTPhZ40VacrpkohJHlyCKGHpJu03 p2Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dilger-ca.20210112.gappssmtp.com header.s=20210112 header.b=Ez5nBYN3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020aa7d510000000b0045a11b60c57si2885383edq.121.2022.11.18.05.57.51; Fri, 18 Nov 2022 05:58:16 -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=@dilger-ca.20210112.gappssmtp.com header.s=20210112 header.b=Ez5nBYN3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242224AbiKRNiw (ORCPT + 99 others); Fri, 18 Nov 2022 08:38:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241913AbiKRNia (ORCPT ); Fri, 18 Nov 2022 08:38:30 -0500 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C11291C1A for ; Fri, 18 Nov 2022 05:37:15 -0800 (PST) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-13bd2aea61bso6000096fac.0 for ; Fri, 18 Nov 2022 05:37:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dilger-ca.20210112.gappssmtp.com; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=GBWb7Q2jF9gggScD/vZOvEkx46gLiqyFIEP0hDuxtSw=; b=Ez5nBYN3nxW8Sunr30RV5LuypVN7cxQ/x1sM4PiEb8wfwnyTkUzdTUtEXAzkFqvOV8 NzDkhi1zgcxPlB3nlNfycKJNt5eT5vID9hxn5smcUbNk1MsNisWErXOpw8bDNT1t5r8a 8rBi7FZf4ZJcaq01sGM1GtygZzVMENomCFId1j1Mra+bTx398Tak3ld/1EEcRR2XBI5J 75rLAty+Lv4jG4NbOGWJ/DIYz6f3O9RKoFg7DC83+IzTCvq5JF7VZ8x46Ga3k9uCTKXZ RmgVC5TxZQktX7moJhlX6Vb7IFFLpXjC0nTCLU7fDZD4g0dTYZ38VDSOjdpWp6/Y2wvc Xv0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GBWb7Q2jF9gggScD/vZOvEkx46gLiqyFIEP0hDuxtSw=; b=4VlQRCgVIIJn4ClUPJd1zUqmzqMZbzjo6BpeNu9LoF7ii3XmnHvLyZtG15KhimOXJQ FMbbIbABCodwNdqIu5zjXHGOvhZ7mmXK9epIW8kEuBIBgOhLmDLwFj8hJj5vipFEjVu4 X6e490w7M4KWIKwoDQSu405m2tRcF4mEWG+FISnwYSTw0t8o9hODr6lX2NOGJXuTiWtf GNSSW7/SR3BvnYTsyYMQcPSjsDZQ6qTPT2vDQ2ITjyurYodGpO5zov2MzVItxyW50wc/ mes1oPbdbp9SxcXLURKEFXPBnFWc9+1pFxDgE7ymzRk0OnK90rJWEaE6wAnPTqQjSKVN k83Q== X-Gm-Message-State: ANoB5pmRtQn9+YXAOy0EvpD+c1mULpiF/gw6CtS7oUbShIuzl5Rv69MA +2Do/0kTD2SPcaFHtL440+EOHXJgWukvWT50 X-Received: by 2002:a05:6870:3b06:b0:13b:5d72:d2c6 with SMTP id gh6-20020a0568703b0600b0013b5d72d2c6mr3927424oab.287.1668778634521; Fri, 18 Nov 2022 05:37:14 -0800 (PST) Received: from smtpclient.apple ([205.169.26.81]) by smtp.gmail.com with ESMTPSA id fo16-20020a0568709a1000b0011f00b027bdsm1958978oab.45.2022.11.18.05.37.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 05:37:13 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andreas Dilger Mime-Version: 1.0 (1.0) Subject: Re: [RFCv1 20/72] libext2fs: avoid too much memory allocation in case fs_num_threads Date: Fri, 18 Nov 2022 07:37:13 -0600 Message-Id: References: <5ae4498b906ea4adffcca5546e2c9deba39dd05a.1667822611.git.ritesh.list@gmail.com> Cc: Theodore Ts'o , linux-ext4@vger.kernel.org, Harshad Shirwadkar , Wang Shilong , Andreas Dilger , Li Xi In-Reply-To: <5ae4498b906ea4adffcca5546e2c9deba39dd05a.1667822611.git.ritesh.list@gmail.com> To: "Ritesh Harjani (IBM)" X-Mailer: iPhone Mail (19H12) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 On Nov 7, 2022, at 06:24, Ritesh Harjani (IBM) wrote= : >=20 > =EF=BB=BFFrom: Wang Shilong >=20 > e2fsck init memory according to filesystem inodes/dir numbers > recorded in the superblock, this should be aware of filesystem > number of threads, otherwise, oom can happen. >=20 > So in case of fs->fs_num_threads, this patch controls the amount of > memory consumed for running multiple threads in e2fsck. >=20 > Signed-off-by: Wang Shilong > Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Andreas Dilger > --- > lib/ext2fs/dblist.c | 2 ++ > lib/ext2fs/icount.c | 4 ++++ > 2 files changed, 6 insertions(+) >=20 > diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c > index 5568b8ec..c19e17bc 100644 > --- a/lib/ext2fs/dblist.c > +++ b/lib/ext2fs/dblist.c > @@ -58,6 +58,8 @@ static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t s= ize, > if (retval) > goto cleanup; > dblist->size =3D (num_dirs * 2) + 12; > + if (fs->fs_num_threads) > + dblist->size /=3D fs->fs_num_threads; > } > len =3D (size_t) sizeof(struct ext2_db_entry2) * dblist->size; > dblist->count =3D count; > diff --git a/lib/ext2fs/icount.c b/lib/ext2fs/icount.c > index 766eccca..48665c7e 100644 > --- a/lib/ext2fs/icount.c > +++ b/lib/ext2fs/icount.c > @@ -237,6 +237,8 @@ errcode_t ext2fs_create_icount_tdb(ext2_filsys fs EXT2= FS_NO_TDB_UNUSED, > * value. > */ > num_inodes =3D fs->super->s_inodes_count - fs->super->s_free_inodes_cou= nt; > + if (fs->fs_num_threads) > + num_inodes /=3D fs->fs_num_threads; >=20 > icount->tdb =3D tdb_open(fn, num_inodes, TDB_NOLOCK | TDB_NOSYNC, > O_RDWR | O_CREAT | O_TRUNC, 0600); > @@ -288,6 +290,8 @@ errcode_t ext2fs_create_icount2(ext2_filsys fs, int fl= ags, unsigned int size, > if (retval) > goto errout; > icount->size +=3D fs->super->s_inodes_count / 50; > + if (fs->fs_num_threads) > + icount->size /=3D fs->fs_num_threads; > } >=20 > bytes =3D (size_t) (icount->size * sizeof(struct ext2_icount_el)); > --=20 > 2.37.3 >=20