Skip to content

Commit 4915b61

Browse files
committed
btrfs: accessors: factor out split memcpy with two sources
The case of a reading the bytes from 2 folios needs two memcpy()s, the compiler does not emit calls but two inline loops. Factoring out the code makes some improvement (stack, code) and in the future will provide an optimized implementation as well. (The analogical version with two destinations is not done as it increases stack usage but can be done if needed.) The address of the second folio is reordered before the first memcpy, which leads to an optimization reusing the vmemmap_base and page_offset_base (implementing folio_address()). Stack usage reduction: btrfs_get_32 -8 (32 -> 24) btrfs_get_64 -8 (32 -> 24) Code size reduction: text data bss dec hex filename 1454279 115665 16088 1586032 183370 pre/btrfs.ko 1454229 115665 16088 1585982 18333e post/btrfs.ko DELTA: -50 As this is the last patch in this series, here's the overall diff starting and including commit "btrfs: accessors: simplify folio bounds checks": Stack: btrfs_set_16 -72 (88 -> 16) btrfs_get_32 -56 (80 -> 24) btrfs_set_8 -72 (88 -> 16) btrfs_set_64 -64 (88 -> 24) btrfs_get_8 -72 (80 -> 8) btrfs_get_16 -64 (80 -> 16) btrfs_set_32 -64 (88 -> 24) btrfs_get_64 -56 (80 -> 24) NEW (48): report_setget_bounds 48 LOST/NEW DELTA: +48 PRE/POST DELTA: -472 Code: text data bss dec hex filename 1456601 115665 16088 1588354 183c82 pre/btrfs.ko 1454229 115665 16088 1585982 18333e post/btrfs.ko DELTA: -2372 Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent ab138a9 commit 4915b61

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

fs/btrfs/accessors.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ static void __cold report_setget_bounds(const struct extent_buffer *eb,
2020
(unsigned long)ptr, eb->start, member_offset, size);
2121
}
2222

23+
/* Copy bytes from @src1 and @src2 to @dest. */
24+
static __always_inline void memcpy_split_src(char *dest, const char *src1,
25+
const char *src2, const size_t len1,
26+
const size_t total)
27+
{
28+
memcpy(dest, src1, len1);
29+
memcpy(dest + len1, src2, total - len1);
30+
}
31+
2332
/*
2433
* Macro templates that define helpers to read/write extent buffer data of a
2534
* given size, that are also used via ctree.h for access to item members by
@@ -64,9 +73,9 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
6473
kaddr = folio_address(eb->folios[idx + 1]); \
6574
lebytes[1] = *kaddr; \
6675
} else { \
67-
memcpy(lebytes, kaddr, part); \
68-
kaddr = folio_address(eb->folios[idx + 1]); \
69-
memcpy(lebytes + part, kaddr, sizeof(u##bits) - part); \
76+
memcpy_split_src(lebytes, kaddr, \
77+
folio_address(eb->folios[idx + 1]), \
78+
part, sizeof(u##bits)); \
7079
} \
7180
return get_unaligned_le##bits(lebytes); \
7281
} \

0 commit comments

Comments
 (0)