Commit f4ca8c51 authored by David Sterba's avatar David Sterba

btrfs: optimize split page write in btrfs_set_##bits

The helper write_extent_buffer is called 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.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ba8a9a05
...@@ -141,18 +141,22 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ ...@@ -141,18 +141,22 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
{ \ { \
const unsigned long member_offset = (unsigned long)ptr + off; \ const unsigned long member_offset = (unsigned long)ptr + off; \
const unsigned long oip = offset_in_page(member_offset); \ const unsigned long oip = offset_in_page(member_offset); \
const unsigned long idx = member_offset >> PAGE_SHIFT; \
char *kaddr = page_address(eb->pages[idx]); \
const int size = sizeof(u##bits); \ const int size = sizeof(u##bits); \
__le##bits leres; \ const int part = PAGE_SIZE - oip; \
u8 lebytes[sizeof(u##bits)]; \
\ \
ASSERT(check_setget_bounds(eb, ptr, off, size)); \ ASSERT(check_setget_bounds(eb, ptr, off, size)); \
if (oip + size <= PAGE_SIZE) { \ if (oip + size <= PAGE_SIZE) { \
const unsigned long idx = member_offset >> PAGE_SHIFT; \
char *kaddr = page_address(eb->pages[idx]); \
put_unaligned_le##bits(val, kaddr + oip); \ put_unaligned_le##bits(val, kaddr + oip); \
return; \ return; \
} \ } \
leres = cpu_to_le##bits(val); \ \
write_extent_buffer(eb, &leres, member_offset, size); \ put_unaligned_le##bits(val, lebytes); \
memcpy(kaddr + oip, lebytes, part); \
kaddr = page_address(eb->pages[idx + 1]); \
memcpy(kaddr, lebytes + part, size - part); \
} }
DEFINE_BTRFS_SETGET_BITS(8) DEFINE_BTRFS_SETGET_BITS(8)
......
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