mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-30 17:31:43 +00:00
btrfs-progs: image: Don't waste memory when we're just extracting super block
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> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
d216266340
commit
52ad6dcbcd
13
image/main.c
13
image/main.c
@ -1523,9 +1523,14 @@ static int fill_mdres_info(struct mdrestore_struct *mdres,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (mdres->compress_method == COMPRESS_ZLIB) {
|
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)
|
if (!buffer)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
ret = uncompress(buffer, (unsigned long *)&size,
|
ret = uncompress(buffer, (unsigned long *)&size,
|
||||||
@ -1964,10 +1969,10 @@ static int build_chunk_tree(struct mdrestore_struct *mdres,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mdres->compress_method == COMPRESS_ZLIB) {
|
if (mdres->compress_method == COMPRESS_ZLIB) {
|
||||||
size_t size = MAX_PENDING_SIZE * 2;
|
size_t size = BTRFS_SUPER_INFO_SIZE;
|
||||||
u8 *tmp;
|
u8 *tmp;
|
||||||
|
|
||||||
tmp = malloc(MAX_PENDING_SIZE * 2);
|
tmp = malloc(size);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
Loading…
Reference in New Issue
Block a user