Commit f472d3c2 authored by David Sterba's avatar David Sterba

btrfs: optimize split page write in btrfs_set_token_##bits

The fallback path calls helper write_extent_buffer to do write of the
data spanning two extent buffer pages. As the size is known, we can do
the write 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 f4ca8c51
...@@ -115,7 +115,8 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \ ...@@ -115,7 +115,8 @@ void btrfs_set_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); \
...@@ -125,16 +126,17 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \ ...@@ -125,16 +126,17 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \
put_unaligned_le##bits(val, token->kaddr + oip); \ put_unaligned_le##bits(val, token->kaddr + oip); \
return; \ return; \
} \ } \
token->kaddr = page_address(token->eb->pages[idx]); \
token->offset = idx << PAGE_SHIFT; \
if (oip + size <= PAGE_SIZE) { \ if (oip + size <= PAGE_SIZE) { \
token->kaddr = page_address(token->eb->pages[idx]); \
token->offset = idx << PAGE_SHIFT; \
put_unaligned_le##bits(val, token->kaddr + oip); \ put_unaligned_le##bits(val, token->kaddr + oip); \
return; \ return; \
} \ } \
put_unaligned_le##bits(val, lebytes); \
memcpy(token->kaddr + oip, lebytes, 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; \
leres = cpu_to_le##bits(val); \ memcpy(token->kaddr, lebytes + part, size - part); \
write_extent_buffer(token->eb, &leres, member_offset, size); \
} \ } \
void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
unsigned long off, u##bits val) \ unsigned long off, u##bits val) \
......
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