From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B257C0650E for ; Thu, 4 Jul 2019 06:11:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4929D20881 for ; Thu, 4 Jul 2019 06:11:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726800AbfGDGLP (ORCPT ); Thu, 4 Jul 2019 02:11:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:54380 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725861AbfGDGLP (ORCPT ); Thu, 4 Jul 2019 02:11:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0FC35AF55 for ; Thu, 4 Jul 2019 06:11:14 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2.1 03/10] btrfs-progs: image: Don't waste memory when we're just extracting super block Date: Thu, 4 Jul 2019 14:10:56 +0800 Message-Id: <20190704061103.20096-4-wqu@suse.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190704061103.20096-1-wqu@suse.com> References: <20190704061103.20096-1-wqu@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There is no need to allocate 2 * max_pending_size (which can be 256M) if we're just extracting super block. We only need to prepare BTRFS_SUPER_INFO_SIZE as buffer size. Signed-off-by: Qu Wenruo --- image/main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/image/main.c b/image/main.c index 7c499c0853d0..162a578a3ff8 100644 --- a/image/main.c +++ b/image/main.c @@ -1522,9 +1522,14 @@ static int fill_mdres_info(struct mdrestore_struct *mdres, return 0; if (mdres->compress_method == COMPRESS_ZLIB) { - size_t size = MAX_PENDING_SIZE * 2; + /* + * We know this item is superblock, its should only be 4K. + * Don't need to waste memory following max_pending_size as it + * can be as large as 256M. + */ + size_t size = BTRFS_SUPER_INFO_SIZE; - buffer = malloc(MAX_PENDING_SIZE * 2); + buffer = malloc(size); if (!buffer) return -ENOMEM; ret = uncompress(buffer, (unsigned long *)&size, @@ -1963,10 +1968,10 @@ static int build_chunk_tree(struct mdrestore_struct *mdres, } if (mdres->compress_method == COMPRESS_ZLIB) { - size_t size = MAX_PENDING_SIZE * 2; + size_t size = BTRFS_SUPER_INFO_SIZE; u8 *tmp; - tmp = malloc(MAX_PENDING_SIZE * 2); + tmp = malloc(size); if (!tmp) { free(buffer); return -ENOMEM; -- 2.22.0