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: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2020-04-30 17:57:55 +02:00
Родитель ba8a9a0537
Коммит f4ca8c51d1
1 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -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 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); \
__le##bits leres; \
const int part = PAGE_SIZE - oip; \
u8 lebytes[sizeof(u##bits)]; \
\
ASSERT(check_setget_bounds(eb, ptr, off, 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); \
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)