Skip to content

Commit 6f7d81d

Browse files
fdmananakdave
authored andcommitted
btrfs: use memcmp_extent_buffer() at replay_one_extent()
Instead of using memcmp(), which requires copying both file extent items from each extent buffer into a local buffer, use memcmp_extent_buffer() so that we only need to copy one of the file extent items and directly use the extent buffer of the other file extent item for the comparison. This reduces code size, saves one memory copy and reduces stack usage. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent e0d5e3b commit 6f7d81d

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

fs/btrfs/tree-log.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -688,25 +688,18 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
688688
if (ret == 0 &&
689689
(found_type == BTRFS_FILE_EXTENT_REG ||
690690
found_type == BTRFS_FILE_EXTENT_PREALLOC)) {
691-
struct btrfs_file_extent_item cmp1;
692-
struct btrfs_file_extent_item cmp2;
693-
struct btrfs_file_extent_item *existing;
694-
struct extent_buffer *leaf;
695-
696-
leaf = path->nodes[0];
697-
existing = btrfs_item_ptr(leaf, path->slots[0],
698-
struct btrfs_file_extent_item);
691+
struct btrfs_file_extent_item existing;
692+
unsigned long ptr;
699693

700-
read_extent_buffer(eb, &cmp1, (unsigned long)item,
701-
sizeof(cmp1));
702-
read_extent_buffer(leaf, &cmp2, (unsigned long)existing,
703-
sizeof(cmp2));
694+
ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]);
695+
read_extent_buffer(path->nodes[0], &existing, ptr, sizeof(existing));
704696

705697
/*
706698
* we already have a pointer to this exact extent,
707699
* we don't have to do anything
708700
*/
709-
if (memcmp(&cmp1, &cmp2, sizeof(cmp1)) == 0) {
701+
if (memcmp_extent_buffer(eb, &existing, (unsigned long)item,
702+
sizeof(existing)) == 0) {
710703
btrfs_release_path(path);
711704
goto out;
712705
}

0 commit comments

Comments
 (0)