Skip to content

Commit b8aa337

Browse files
committed
btrfs: read eb folio index right before loops
There are generic helpers to access extent buffer folio data of any length, potentially iterating over a few of them. This is a slow path, either we use the type based accessors or the eb folio allocation is contiguous and we can use the memcpy/memcmp helpers. The initialization of 'i' is done at the beginning though it may not be needed. Move it right before the folio loop, this has minor effect on generated code in __write_extent_buffer(). Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent aae9042 commit b8aa337

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

fs/btrfs/extent_io.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4018,7 +4018,7 @@ void read_extent_buffer(const struct extent_buffer *eb, void *dstv,
40184018
size_t cur;
40194019
size_t offset;
40204020
char *dst = (char *)dstv;
4021-
unsigned long i = get_eb_folio_index(eb, start);
4021+
unsigned long i;
40224022

40234023
if (check_eb_range(eb, start, len)) {
40244024
/*
@@ -4035,7 +4035,7 @@ void read_extent_buffer(const struct extent_buffer *eb, void *dstv,
40354035
}
40364036

40374037
offset = get_eb_offset_in_folio(eb, start);
4038-
4038+
i = get_eb_folio_index(eb, start);
40394039
while (len > 0) {
40404040
char *kaddr;
40414041

@@ -4058,7 +4058,7 @@ int read_extent_buffer_to_user_nofault(const struct extent_buffer *eb,
40584058
size_t cur;
40594059
size_t offset;
40604060
char __user *dst = (char __user *)dstv;
4061-
unsigned long i = get_eb_folio_index(eb, start);
4061+
unsigned long i;
40624062
int ret = 0;
40634063

40644064
WARN_ON(start > eb->len);
@@ -4071,7 +4071,7 @@ int read_extent_buffer_to_user_nofault(const struct extent_buffer *eb,
40714071
}
40724072

40734073
offset = get_eb_offset_in_folio(eb, start);
4074-
4074+
i = get_eb_folio_index(eb, start);
40754075
while (len > 0) {
40764076
char *kaddr;
40774077

@@ -4099,7 +4099,7 @@ int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
40994099
size_t offset;
41004100
char *kaddr;
41014101
char *ptr = (char *)ptrv;
4102-
unsigned long i = get_eb_folio_index(eb, start);
4102+
unsigned long i;
41034103
int ret = 0;
41044104

41054105
if (check_eb_range(eb, start, len))
@@ -4109,7 +4109,7 @@ int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
41094109
return memcmp(ptrv, eb->addr + start, len);
41104110

41114111
offset = get_eb_offset_in_folio(eb, start);
4112-
4112+
i = get_eb_folio_index(eb, start);
41134113
while (len > 0) {
41144114
cur = min(len, unit_size - offset);
41154115
kaddr = folio_address(eb->folios[i]);
@@ -4169,7 +4169,7 @@ static void __write_extent_buffer(const struct extent_buffer *eb,
41694169
size_t offset;
41704170
char *kaddr;
41714171
const char *src = (const char *)srcv;
4172-
unsigned long i = get_eb_folio_index(eb, start);
4172+
unsigned long i;
41734173
/* For unmapped (dummy) ebs, no need to check their uptodate status. */
41744174
const bool check_uptodate = !test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags);
41754175

@@ -4185,7 +4185,7 @@ static void __write_extent_buffer(const struct extent_buffer *eb,
41854185
}
41864186

41874187
offset = get_eb_offset_in_folio(eb, start);
4188-
4188+
i = get_eb_folio_index(eb, start);
41894189
while (len > 0) {
41904190
if (check_uptodate)
41914191
assert_eb_folio_uptodate(eb, i);
@@ -4271,7 +4271,7 @@ void copy_extent_buffer(const struct extent_buffer *dst,
42714271
size_t cur;
42724272
size_t offset;
42734273
char *kaddr;
4274-
unsigned long i = get_eb_folio_index(dst, dst_offset);
4274+
unsigned long i;
42754275

42764276
if (check_eb_range(dst, dst_offset, len) ||
42774277
check_eb_range(src, src_offset, len))
@@ -4281,6 +4281,7 @@ void copy_extent_buffer(const struct extent_buffer *dst,
42814281

42824282
offset = get_eb_offset_in_folio(dst, dst_offset);
42834283

4284+
i = get_eb_folio_index(dst, dst_offset);
42844285
while (len > 0) {
42854286
assert_eb_folio_uptodate(dst, i);
42864287

0 commit comments

Comments
 (0)