]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
btrfs: preset set/get token with first page and drop condition
authorDavid Sterba <dsterba@suse.com>
Wed, 29 Apr 2020 17:29:04 +0000 (19:29 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 May 2020 09:25:32 +0000 (11:25 +0200)
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 <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/struct-funcs.c

index dcb82d690e76c3b19ab65724152aa46fb5e894b4..557de0dc904aa2709b6550519e1c4ad6aebbab8a 100644 (file)
@@ -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
index cebd0b5e4f37cd24eda8ad36fb70c7417c617187..cef628a5a9e0c18b002d93e2115bbac0cd7fed97 100644 (file)
@@ -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;                \