Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+10 -9
+10 -9
fs/btrfs/extent_io.c
··· 4018 4018 size_t cur; 4019 4019 size_t offset; 4020 4020 char *dst = (char *)dstv; 4021 - unsigned long i = get_eb_folio_index(eb, start); 4021 + unsigned long i; 4022 4022 4023 4023 if (check_eb_range(eb, start, len)) { 4024 4024 /* ··· 4035 4035 } 4036 4036 4037 4037 offset = get_eb_offset_in_folio(eb, start); 4038 - 4038 + i = get_eb_folio_index(eb, start); 4039 4039 while (len > 0) { 4040 4040 char *kaddr; 4041 4041 ··· 4058 4058 size_t cur; 4059 4059 size_t offset; 4060 4060 char __user *dst = (char __user *)dstv; 4061 - unsigned long i = get_eb_folio_index(eb, start); 4061 + unsigned long i; 4062 4062 int ret = 0; 4063 4063 4064 4064 WARN_ON(start > eb->len); ··· 4071 4071 } 4072 4072 4073 4073 offset = get_eb_offset_in_folio(eb, start); 4074 - 4074 + i = get_eb_folio_index(eb, start); 4075 4075 while (len > 0) { 4076 4076 char *kaddr; 4077 4077 ··· 4099 4099 size_t offset; 4100 4100 char *kaddr; 4101 4101 char *ptr = (char *)ptrv; 4102 - unsigned long i = get_eb_folio_index(eb, start); 4102 + unsigned long i; 4103 4103 int ret = 0; 4104 4104 4105 4105 if (check_eb_range(eb, start, len)) ··· 4109 4109 return memcmp(ptrv, eb->addr + start, len); 4110 4110 4111 4111 offset = get_eb_offset_in_folio(eb, start); 4112 - 4112 + i = get_eb_folio_index(eb, start); 4113 4113 while (len > 0) { 4114 4114 cur = min(len, unit_size - offset); 4115 4115 kaddr = folio_address(eb->folios[i]); ··· 4169 4169 size_t offset; 4170 4170 char *kaddr; 4171 4171 const char *src = (const char *)srcv; 4172 - unsigned long i = get_eb_folio_index(eb, start); 4172 + unsigned long i; 4173 4173 /* For unmapped (dummy) ebs, no need to check their uptodate status. */ 4174 4174 const bool check_uptodate = !test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags); 4175 4175 ··· 4185 4185 } 4186 4186 4187 4187 offset = get_eb_offset_in_folio(eb, start); 4188 - 4188 + i = get_eb_folio_index(eb, start); 4189 4189 while (len > 0) { 4190 4190 if (check_uptodate) 4191 4191 assert_eb_folio_uptodate(eb, i); ··· 4271 4271 size_t cur; 4272 4272 size_t offset; 4273 4273 char *kaddr; 4274 - unsigned long i = get_eb_folio_index(dst, dst_offset); 4274 + unsigned long i; 4275 4275 4276 4276 if (check_eb_range(dst, dst_offset, len) || 4277 4277 check_eb_range(src, src_offset, len)) ··· 4281 4281 4282 4282 offset = get_eb_offset_in_folio(dst, dst_offset); 4283 4283 4284 + i = get_eb_folio_index(dst, dst_offset); 4284 4285 while (len > 0) { 4285 4286 assert_eb_folio_uptodate(dst, i); 4286 4287