Commit 62a73b20 authored by David Sterba's avatar David Sterba Committed by Stefan Bader

btrfs: tree-check: reduce stack consumption in check_dir_item

BugLink: https://bugs.launchpad.net/bugs/1818237

commit e2683fc9 upstream.

I've noticed that the updated item checker stack consumption increased
dramatically in 542f5385e20cf97447 ("btrfs: tree-checker: Add checker
for dir item")

tree-checker.c:check_leaf                    +552 (176 -> 728)

The array is 255 bytes long, dynamic allocation would slow down the
sanity checks so it's more reasonable to keep it on-stack. Moving the
variable to the scope of use reduces the stack usage again

tree-checker.c:check_leaf                    -264 (728 -> 464)
Reviewed-by: default avatarJosef Bacik <jbacik@fb.com>
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 8f6ecc84
...@@ -212,7 +212,6 @@ static int check_dir_item(struct btrfs_root *root, ...@@ -212,7 +212,6 @@ static int check_dir_item(struct btrfs_root *root,
di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
while (cur < item_size) { while (cur < item_size) {
char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)];
u32 name_len; u32 name_len;
u32 data_len; u32 data_len;
u32 max_name_len; u32 max_name_len;
...@@ -295,6 +294,8 @@ static int check_dir_item(struct btrfs_root *root, ...@@ -295,6 +294,8 @@ static int check_dir_item(struct btrfs_root *root,
*/ */
if (key->type == BTRFS_DIR_ITEM_KEY || if (key->type == BTRFS_DIR_ITEM_KEY ||
key->type == BTRFS_XATTR_ITEM_KEY) { key->type == BTRFS_XATTR_ITEM_KEY) {
char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)];
read_extent_buffer(leaf, namebuf, read_extent_buffer(leaf, namebuf,
(unsigned long)(di + 1), name_len); (unsigned long)(di + 1), name_len);
name_hash = btrfs_name_hash(namebuf, name_len); name_hash = btrfs_name_hash(namebuf, name_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment