Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp414693pxb; Wed, 18 Nov 2020 07:43:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5zZnkUODeKH4dzmSkB6zt2t2eZhn/VepUy+yn9BxpuNHJvL01E0SPLWH0ULMhQKbnt7As X-Received: by 2002:a17:906:757:: with SMTP id z23mr1693428ejb.259.1605714219022; Wed, 18 Nov 2020 07:43:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605714219; cv=none; d=google.com; s=arc-20160816; b=lfrqeVeWaFFFIEFzmQz9XQAVaJBCMP6rWSjZ5AtCQ3CL9uN057L7VRPNruPbWPvm2+ CgJ3eXXyIIrtacmOsuDugxR6zLxvgMMtlB/TbozHyOvbB1Zcpgb+3wR02nmpy3JpraMM memWBr2aDBJ6EQcrgPVy8QvTgveYQF9bzoGsBviIiVtP+e7aTP0LQyRuz05ZlUCAVTdH YDSWObwOWrk937eeRrd8p4JTN5xntk+xEKJiH9NKJVaBcKf2YwyV1W1dEvN7LpG84Ctb wJ9kps6bXlyiN6OFGtnzYFmX9dVvTYp3X9WL/+nXV8THVd01AgVDVdE4cUt4Twr1TbL6 eZtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=daegGDDQsSr9sVYzcaRO/85KlGjSfsbj2sAdl0WiLTY=; b=nMhLVptyD9VjfI8IrBWlhlVeHE66YEP2jdEaq3QiyBo80W2fNDW5e/EV9xEkl9VG+H xJhJrNbIhVCqKAmGuzj0ZcxnRU7JNARbrG/tzkO94WI/iiGBnGRIugQYkxBhq/a50rur qWsT83eOwMHpw5Nxs8hb9EtTltID9A+jSsXhstvwWVp/rei1UVyyIyte81JhvDjMePAr RGlfpJv9n11qYseeaKA/PHOcHRnPKXxtBXPMkMdDS9L6J27e1m7R1iJUl0w6y993wGtM xI45YfDtmxIEQPe2QCjiwUevAUUCeiGH7VDGfSxtrPJMl6tP2w2w3h7wLOqE2FH3Iqtu UcrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tBWtD8N5; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz9si706654edb.289.2020.11.18.07.43.14; Wed, 18 Nov 2020 07:43:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tBWtD8N5; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727560AbgKRPlt (ORCPT + 99 others); Wed, 18 Nov 2020 10:41:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbgKRPls (ORCPT ); Wed, 18 Nov 2020 10:41:48 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A45C0613D4 for ; Wed, 18 Nov 2020 07:41:48 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id u37so2942613ybi.15 for ; Wed, 18 Nov 2020 07:41:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=daegGDDQsSr9sVYzcaRO/85KlGjSfsbj2sAdl0WiLTY=; b=tBWtD8N5li5rsBCylTS2dSvTQ+lGC48YGbh8WFYT8v02IUfRKgDvGYwHDUKBOb9vs/ n+v8v7I/GqYbdPMEabzP7bpSg7We1ypuGNKT58BzOYwxOyQVSBMTnJu10wlBevmmXk+y 1SMlzpbASL26LA92XImA/9JETytzCEzSpJPJuybUMSAifAyk+qnybr+H4mRXTt2mXgI0 KLoHYslz4aMF+Gp5DaQ3Zo6y4KEHQDqiYbpw9bq/tmN+wHFgaGtjVOx0tfEMmrVuYGtk gSuJfkrK8hD/Q7dzWrgjRvSO7nMdPed1gpl1GY/XEFLTraZzAl3W67pZ3rHrbMxCBngf 3oUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=daegGDDQsSr9sVYzcaRO/85KlGjSfsbj2sAdl0WiLTY=; b=rw5bujHxau1Tvub47Fxy/u4derITxSsQ2u+f1skbRT23S7jjUh3WQmJ88G6daAcgCF ZzwgrVKIMp8eYHHM9D3vW0l3kewHPIRjB6nxL6K/n75y6+PupKJMc1x3IpkLmxepwBe8 wrqxXwR/1JdTKREWsReWDzP4eaycL3B2Iof/GJCqu5ST50xSlqI/DUt/4bVb9oXG0ebn p7x1S23NkteEr/FlpP/jO7jskwB3EAvejM3EZa98spFwUIg5LQMKor7d2BY6hjOgG+F8 mSOWOAuLBLosNIyMhU4UH4JBu0BgfKNV2Dd9SU1D8fZQSgpkxUNCIkLeKxViP2DduFKT kdAw== X-Gm-Message-State: AOAM531ryfu9iEp+5RHOVv7Ju539T9crQg46il59SDKHLD6wELmbcq40 QoYuteH+FkErAKWE3MuUl1IZOUKYwQgVBDJ7nG2leKyy2fgHCL8cQ8Ozss2HOWYm8C25yeMiu6R /nyxZj43kQ+foUESJTnUXyja2Fc47y9erpi9Dh3ug+k+VpNMJUvKUFyDUWd0NlQQ8vSPrmCKw5H whu8ny0Mg= Sender: "saranyamohan via sendgmr" X-Received: from saranyamohan.svl.corp.google.com ([100.116.76.178]) (user=saranyamohan job=sendgmr) by 2002:a25:2605:: with SMTP id m5mr6624866ybm.98.1605714107888; Wed, 18 Nov 2020 07:41:47 -0800 (PST) Date: Wed, 18 Nov 2020 07:39:30 -0800 In-Reply-To: <20201118153947.3394530-1-saranyamohan@google.com> Message-Id: <20201118153947.3394530-45-saranyamohan@google.com> Mime-Version: 1.0 References: <20201118153947.3394530-1-saranyamohan@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [RFC PATCH v3 44/61] e2fsck: avoid too much memory allocation for pfsck From: Saranya Muruganandam To: linux-ext4@vger.kernel.org, tytso@mit.edu Cc: adilger.kernel@dilger.ca, Wang Shilong , Saranya Muruganandam Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Wang Shilong e2fsck init memory according to filesystem inodes/dir numbers recorded in the superblock, this should be aware of filesystem number of threads, otherwise, oom happen. Signed-off-by: Wang Shilong Signed-off-by: Saranya Muruganandam --- lib/ext2fs/dblist.c | 2 ++ lib/ext2fs/icount.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c index 1fdd8f43..c4e712fd 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 size, if (retval) goto cleanup; dblist->size = (num_dirs * 2) + 12; + if (fs->fs_num_threads) + dblist->size /= fs->fs_num_threads; } len = (size_t) sizeof(struct ext2_db_entry2) * dblist->size; dblist->count = 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 EXT2FS_NO_TDB_UNUSED, * value. */ num_inodes = fs->super->s_inodes_count - fs->super->s_free_inodes_count; + if (fs->fs_num_threads) + num_inodes /= fs->fs_num_threads; icount->tdb = 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 flags, unsigned int size, if (retval) goto errout; icount->size += fs->super->s_inodes_count / 50; + if (fs->fs_num_threads) + icount->size /= fs->fs_num_threads; } bytes = (size_t) (icount->size * sizeof(struct ext2_icount_el)); -- 2.29.2.299.gdc1121823c-goog