Decrease stack usage in JFS.

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

	* grub-core/fs/jfs.c (getblk): Allocate on heap rather than on
	stack. Note: this function is recursive.
	(grub_jfs_read_inode): Read only part we care about.
This commit is contained in:
Vladimir Serbinenko 2013-11-16 16:00:42 +01:00
parent 593865b907
commit 7b5d51d837
2 changed files with 33 additions and 13 deletions

View file

@ -1,7 +1,18 @@
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in JFS.
We have only 92K of stack and using over 4K per frame is wasteful
* grub-core/fs/jfs.c (getblk): Allocate on heap rather than on
stack. Note: this function is recursive.
(grub_jfs_read_inode): Read only part we care about.
2013-11-16 Leif Lindholm <leif.lindholm@linaro.org> 2013-11-16 Leif Lindholm <leif.lindholm@linaro.org>
* grub-core/kern/arm/uboot/startup.S: fix grub_uboot_syscall va_arg * grub-core/kern/arm/uboot/startup.S: fix grub_uboot_syscall va_arg
handling handling
2013-11-16 Andrey Borzenkov <arvidjaar@gmail.com> 2013-11-16 Andrey Borzenkov <arvidjaar@gmail.com>
* configure.ac: Restore -nostdlib for libgcc symbols tests. * configure.ac: Restore -nostdlib for libgcc symbols tests.

View file

@ -72,10 +72,13 @@ struct grub_jfs_extent
grub_uint32_t blk2; grub_uint32_t blk2;
} __attribute__ ((packed)); } __attribute__ ((packed));
#define GRUB_JFS_IAG_INODES_OFFSET 3072
#define GRUB_JFS_IAG_INODES_COUNT 128
struct grub_jfs_iag struct grub_jfs_iag
{ {
grub_uint8_t unused[3072]; grub_uint8_t unused[GRUB_JFS_IAG_INODES_OFFSET];
struct grub_jfs_extent inodes[128]; struct grub_jfs_extent inodes[GRUB_JFS_IAG_INODES_COUNT];
} __attribute__ ((packed)); } __attribute__ ((packed));
@ -283,20 +286,25 @@ getblk (struct grub_jfs_treehead *treehead,
if (found != -1) if (found != -1)
{ {
grub_int64_t ret = -1;
struct struct
{ {
struct grub_jfs_treehead treehead; struct grub_jfs_treehead treehead;
struct grub_jfs_tree_extent extents[254]; struct grub_jfs_tree_extent extents[254];
} tree; } *tree;
if (grub_disk_read (data->disk, tree = grub_zalloc (sizeof (*tree));
((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2)) if (!tree)
<< (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), 0,
sizeof (tree), (char *) &tree))
return -1; return -1;
return getblk (&tree.treehead, &tree.extents[0], data, blk); if (!grub_disk_read (data->disk,
((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2))
<< (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), 0,
sizeof (*tree), (char *) tree))
ret = getblk (&tree->treehead, &tree->extents[0], data, blk);
grub_free (tree);
return ret;
} }
return -1; return -1;
@ -316,7 +324,7 @@ static grub_err_t
grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino, grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino,
struct grub_jfs_inode *inode) struct grub_jfs_inode *inode)
{ {
struct grub_jfs_iag iag; struct grub_jfs_extent iag_inodes[GRUB_JFS_IAG_INODES_COUNT];
grub_uint32_t iagnum = ino / 4096; grub_uint32_t iagnum = ino / 4096;
unsigned inoext = (ino % 4096) / 32; unsigned inoext = (ino % 4096) / 32;
unsigned inonum = (ino % 4096) % 32; unsigned inonum = (ino % 4096) % 32;
@ -330,11 +338,12 @@ grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino,
/* Read in the IAG. */ /* Read in the IAG. */
if (grub_disk_read (data->disk, if (grub_disk_read (data->disk,
iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz) iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), 0, - GRUB_DISK_SECTOR_BITS),
sizeof (struct grub_jfs_iag), &iag)) GRUB_JFS_IAG_INODES_OFFSET,
sizeof (iag_inodes), &iag_inodes))
return grub_errno; return grub_errno;
inoblk = grub_le_to_cpu32 (iag.inodes[inoext].blk2); inoblk = grub_le_to_cpu32 (iag_inodes[inoext].blk2);
inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS); - GRUB_DISK_SECTOR_BITS);
inoblk += inonum; inoblk += inonum;