Skip to content

Commit 870b388

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

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

fs/btrfs/ctree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,8 @@ static inline void btrfs_init_map_token(struct btrfs_map_token *token,
13521352
struct extent_buffer *eb)
13531353
{
13541354
token->eb = eb;
1355-
token->kaddr = NULL;
1355+
token->kaddr = page_address(eb->pages[0]);
1356+
token->offset = 0;
13561357
}
13571358

13581359
/* some macros to generate set/get functions for the struct fields. This

fs/btrfs/struct-funcs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
5252
u##bits res; \
5353
\
5454
ASSERT(token); \
55-
\
56-
if (token->kaddr && token->offset <= offset && \
55+
ASSERT(token->kaddr); \
56+
if (token->offset <= offset && \
5757
(token->offset + PAGE_SIZE >= offset + size)) { \
5858
kaddr = token->kaddr; \
5959
p = kaddr + part_offset - token->offset; \
@@ -113,8 +113,8 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \
113113
int size = sizeof(u##bits); \
114114
\
115115
ASSERT(token); \
116-
\
117-
if (token->kaddr && token->offset <= offset && \
116+
ASSERT(token->kaddr); \
117+
if (token->offset <= offset && \
118118
(token->offset + PAGE_SIZE >= offset + size)) { \
119119
kaddr = token->kaddr; \
120120
p = kaddr + part_offset - token->offset; \

0 commit comments

Comments
 (0)