Decrease stack usage in BtrFS.

We have only 92K of stack and using over 4K per frame is wasteful

	* grub-core/fs/btrfs.c (grub_btrfs_lzo_decompress): Allocate on heap
	rather than stack.
This commit is contained in:
Vladimir Serbinenko 2013-11-16 16:03:28 +01:00
parent 7b5d51d837
commit deaa7052c5
2 changed files with 20 additions and 2 deletions

View file

@ -1,3 +1,12 @@
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in BtrFS.
We have only 92K of stack and using over 4K per frame is wasteful
* grub-core/fs/btrfs.c (grub_btrfs_lzo_decompress): Allocate on heap
rather than stack.
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in JFS.

View file

@ -911,7 +911,6 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
{
grub_uint32_t total_size, cblock_size;
grub_size_t ret = 0;
unsigned char buf[GRUB_BTRFS_LZO_BLOCK_SIZE];
char *ibuf0 = ibuf;
total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf));
@ -955,13 +954,21 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
if (off > 0 || osize < GRUB_BTRFS_LZO_BLOCK_SIZE)
{
grub_size_t to_copy = GRUB_BTRFS_LZO_BLOCK_SIZE - off;
grub_uint8_t *buf;
if (to_copy > osize)
to_copy = osize;
buf = grub_malloc (GRUB_BTRFS_LZO_BLOCK_SIZE);
if (!buf)
return -1;
if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize,
NULL) != LZO_E_OK)
{
grub_free (buf);
return -1;
}
if (to_copy > usize)
to_copy = usize;
@ -972,6 +979,8 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
obuf += to_copy;
ibuf += cblock_size;
off = 0;
grub_free (buf);
continue;
}