Commit 029e4a42 authored by David Sterba's avatar David Sterba

btrfs: speed up btrfs_set_##bits helpers

The helpers unconditionally call map_private_extent_buffer to get the
address of page containing the requested offset plus the mapping start
and length. Depending on the return value, the fast path uses unaligned
put to write data within a page, or fall back to write_extent_buffer
that can handle writes spanning more pages.

This is all wasteful. We know the number of bytes to write, 1/2/4/8 and
can find out the page. Then simply check if it's contained or the
fallback is needed.

This saves one function call to map_private_extent_buffer and several
unnecessary temporary variables.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 8f9da810
...@@ -142,27 +142,20 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \ ...@@ -142,27 +142,20 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \
void btrfs_set_##bits(struct extent_buffer *eb, void *ptr, \ void btrfs_set_##bits(struct extent_buffer *eb, void *ptr, \
unsigned long off, u##bits val) \ unsigned long off, u##bits val) \
{ \ { \
unsigned long part_offset = (unsigned long)ptr; \ const unsigned long member_offset = (unsigned long)ptr + off; \
unsigned long offset = part_offset + off; \ const unsigned long oip = offset_in_page(member_offset); \
void *p; \ const int size = sizeof(u##bits); \
int err; \ __le##bits leres; \
char *kaddr; \
unsigned long map_start; \
unsigned long map_len; \
int size = sizeof(u##bits); \
\ \
ASSERT(check_setget_bounds(eb, ptr, off, size)); \ ASSERT(check_setget_bounds(eb, ptr, off, size)); \
err = map_private_extent_buffer(eb, offset, size, \ if (oip + size <= PAGE_SIZE) { \
&kaddr, &map_start, &map_len); \ const unsigned long idx = member_offset >> PAGE_SHIFT; \
if (err) { \ char *kaddr = page_address(eb->pages[idx]); \
__le##bits val2; \ put_unaligned_le##bits(val, kaddr + oip); \
\
val2 = cpu_to_le##bits(val); \
write_extent_buffer(eb, &val2, offset, size); \
return; \ return; \
} \ } \
p = kaddr + part_offset - map_start; \ leres = cpu_to_le##bits(val); \
put_unaligned_le##bits(val, p + off); \ write_extent_buffer(eb, &leres, member_offset, size); \
} }
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