Commit 870b388d authored by David Sterba's avatar David Sterba

btrfs: preset set/get token with first page and drop condition

All the set/get helpers first check if the token contains a cached
address. After first use the address is always valid, but the extra
check is done for each call.

The token initialization can optimistically set it to the first extent
buffer page, that we know always exists. Then the condition in all
btrfs_token_*/btrfs_set_token_* can be simplified by removing the
address check from the condition, but for development the assertion
still makes sure it's valid.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a31356b9
......@@ -1352,7 +1352,8 @@ static inline void btrfs_init_map_token(struct btrfs_map_token *token,
struct extent_buffer *eb)
{
token->eb = eb;
token->kaddr = NULL;
token->kaddr = page_address(eb->pages[0]);
token->offset = 0;
}
/* some macros to generate set/get functions for the struct fields. This
......
......@@ -52,8 +52,8 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
u##bits res; \
\
ASSERT(token); \
\
if (token->kaddr && token->offset <= offset && \
ASSERT(token->kaddr); \
if (token->offset <= offset && \
(token->offset + PAGE_SIZE >= offset + size)) { \
kaddr = token->kaddr; \
p = kaddr + part_offset - token->offset; \
......@@ -113,8 +113,8 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \
int size = sizeof(u##bits); \
\
ASSERT(token); \
\
if (token->kaddr && token->offset <= offset && \
ASSERT(token->kaddr); \
if (token->offset <= offset && \
(token->offset + PAGE_SIZE >= offset + size)) { \
kaddr = token->kaddr; \
p = kaddr + part_offset - token->offset; \
......
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