Skip to content

Commit 84da071

Browse files
committed
btrfs: optimize split page read in btrfs_get_##bits
The helper read_extent_buffer is called to do read of the data spanning two extent buffer pages. As the size is known, we can do the read directly in two steps. This removes one function call and compiler can optimize memcpy as the sizes are known at compile time. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c60ac0f commit 84da071

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

fs/btrfs/struct-funcs.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,20 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
9090
{ \
9191
const unsigned long member_offset = (unsigned long)ptr + off; \
9292
const unsigned long oip = offset_in_page(member_offset); \
93+
const unsigned long idx = member_offset >> PAGE_SHIFT; \
94+
char *kaddr = page_address(eb->pages[idx]); \
9395
const int size = sizeof(u##bits); \
94-
__le##bits leres; \
96+
const int part = PAGE_SIZE - oip; \
97+
u8 lebytes[sizeof(u##bits)]; \
9598
\
9699
ASSERT(check_setget_bounds(eb, ptr, off, size)); \
97-
if (oip + size <= PAGE_SIZE) { \
98-
const unsigned long idx = member_offset >> PAGE_SHIFT; \
99-
const char *kaddr = page_address(eb->pages[idx]); \
100+
if (oip + size <= PAGE_SIZE) \
100101
return get_unaligned_le##bits(kaddr + oip); \
101-
} \
102-
read_extent_buffer(eb, &leres, member_offset, size); \
103-
return le##bits##_to_cpu(leres); \
102+
\
103+
memcpy(lebytes, kaddr + oip, part); \
104+
kaddr = page_address(eb->pages[idx + 1]); \
105+
memcpy(lebytes + part, kaddr, size - part); \
106+
return get_unaligned_le##bits(lebytes); \
104107
} \
105108
void btrfs_set_token_##bits(struct btrfs_map_token *token, \
106109
const void *ptr, unsigned long off, \

0 commit comments

Comments
 (0)