Skip to content

Commit f472d3c

Browse files
committed
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: Johannes Thumshirn <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f4ca8c5 commit f472d3c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

fs/btrfs/struct-funcs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \
115115
const unsigned long idx = member_offset >> PAGE_SHIFT; \
116116
const unsigned long oip = offset_in_page(member_offset); \
117117
const int size = sizeof(u##bits); \
118-
__le##bits leres; \
118+
u8 lebytes[sizeof(u##bits)]; \
119+
const int part = PAGE_SIZE - oip; \
119120
\
120121
ASSERT(token); \
121122
ASSERT(token->kaddr); \
@@ -125,16 +126,17 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \
125126
put_unaligned_le##bits(val, token->kaddr + oip); \
126127
return; \
127128
} \
129+
token->kaddr = page_address(token->eb->pages[idx]); \
130+
token->offset = idx << PAGE_SHIFT; \
128131
if (oip + size <= PAGE_SIZE) { \
129-
token->kaddr = page_address(token->eb->pages[idx]); \
130-
token->offset = idx << PAGE_SHIFT; \
131132
put_unaligned_le##bits(val, token->kaddr + oip); \
132133
return; \
133134
} \
135+
put_unaligned_le##bits(val, lebytes); \
136+
memcpy(token->kaddr + oip, lebytes, part); \
134137
token->kaddr = page_address(token->eb->pages[idx + 1]); \
135138
token->offset = (idx + 1) << PAGE_SHIFT; \
136-
leres = cpu_to_le##bits(val); \
137-
write_extent_buffer(token->eb, &leres, member_offset, size); \
139+
memcpy(token->kaddr, lebytes + part, size - part); \
138140
} \
139141
void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
140142
unsigned long off, u##bits val) \

0 commit comments

Comments
 (0)