public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
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	[thread overview]
Message-ID: <20190704061103.20096-4-wqu@suse.com> (raw)
In-Reply-To: <20190704061103.20096-1-wqu@suse.com>

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 <wqu@suse.com>
---
 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


  parent reply	other threads:[~2019-07-04  6:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04  6:10 [PATCH v2.1 00/10] btrfs-progs: image: Enhancement with new data dump feature Qu Wenruo
2019-07-04  6:10 ` [PATCH v2.1 01/10] btrfs-progs: image: Output error message for chunk tree build error Qu Wenruo
2019-07-04  6:10 ` [PATCH v2.1 02/10] btrfs-progs: image: Fix error output to show correct return value Qu Wenruo
2019-07-04  6:10 ` Qu Wenruo [this message]
2019-07-04  6:10 ` [PATCH v2.1 04/10] btrfs-progs: image: Allow restore to record system chunk ranges for later usage Qu Wenruo
2019-07-04  6:10 ` [PATCH v2.1 05/10] btrfs-progs: image: Introduce helper to determine if a tree block is in the range of system chunks Qu Wenruo
2019-07-04  6:10 ` [PATCH v2.1 06/10] btrfs-progs: image: Rework how we search chunk tree blocks Qu Wenruo
2019-07-04  6:11 ` [PATCH v2.1 07/10] btrfs-progs: image: Introduce framework for more dump versions Qu Wenruo
2019-07-04  6:11 ` [PATCH v2.1 08/10] btrfs-progs: image: Introduce -d option to dump data Qu Wenruo
2019-07-15  3:57   ` Anand Jain
2019-07-15  4:09   ` Anand Jain
2019-07-04  6:11 ` [PATCH v2.1 09/10] btrfs-progs: image: Reduce memory requirement for decompression Qu Wenruo
2019-07-04  6:11 ` [PATCH v2.1 10/10] btrfs-progs: image: Reduce memory usage for chunk tree search Qu Wenruo
2019-09-19  7:19 ` [PATCH v2.1 00/10] btrfs-progs: image: Enhancement with new data dump feature WenRuo Qu
2019-09-24 11:31   ` Anand Jain
2019-09-24 11:40     ` Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190704061103.20096-4-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox