Commit ba8a9a05 authored by David Sterba's avatar David Sterba

btrfs: optimize split page read in btrfs_get_token_##bits

The fallback path calls helper read_extent_buffer 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. The cached
token address is set to the second page.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 84da071f
...@@ -66,7 +66,8 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ ...@@ -66,7 +66,8 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
const unsigned long idx = member_offset >> PAGE_SHIFT; \ const unsigned long idx = member_offset >> PAGE_SHIFT; \
const unsigned long oip = offset_in_page(member_offset); \ const unsigned long oip = offset_in_page(member_offset); \
const int size = sizeof(u##bits); \ const int size = sizeof(u##bits); \
__le##bits leres; \ u8 lebytes[sizeof(u##bits)]; \
const int part = PAGE_SIZE - oip; \
\ \
ASSERT(token); \ ASSERT(token); \
ASSERT(token->kaddr); \ ASSERT(token->kaddr); \
...@@ -75,15 +76,16 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ ...@@ -75,15 +76,16 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
member_offset + size <= token->offset + PAGE_SIZE) { \ member_offset + size <= token->offset + PAGE_SIZE) { \
return get_unaligned_le##bits(token->kaddr + oip); \ return get_unaligned_le##bits(token->kaddr + oip); \
} \ } \
if (oip + size <= PAGE_SIZE) { \
token->kaddr = page_address(token->eb->pages[idx]); \ token->kaddr = page_address(token->eb->pages[idx]); \
token->offset = idx << PAGE_SHIFT; \ token->offset = idx << PAGE_SHIFT; \
if (oip + size <= PAGE_SIZE) \
return get_unaligned_le##bits(token->kaddr + oip); \ return get_unaligned_le##bits(token->kaddr + oip); \
} \ \
memcpy(lebytes, token->kaddr + oip, part); \
token->kaddr = page_address(token->eb->pages[idx + 1]); \ token->kaddr = page_address(token->eb->pages[idx + 1]); \
token->offset = (idx + 1) << PAGE_SHIFT; \ token->offset = (idx + 1) << PAGE_SHIFT; \
read_extent_buffer(token->eb, &leres, member_offset, size); \ memcpy(lebytes + part, token->kaddr, size - part); \
return le##bits##_to_cpu(leres); \ return get_unaligned_le##bits(lebytes); \
} \ } \
u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
const void *ptr, unsigned long off) \ const void *ptr, unsigned long off) \
......
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