Skip to content

Commit a16c62c

Browse files
committed
btrfs: accessors: simplify folio bounds checks
As we can have non-contiguous range in the eb->folios, any item can be straddling two folios and we need to check if it can be read in one go or in two parts. For that there's a check which is not implemented in the simplest way: offset in folio + size <= folio size With a simple expression transformation: oil + size <= unit_size size <= unit_size - oil sizeof() <= part this can be simplified and reusing existing run-time or compile-time constants. Add likely() annotation for this expression as this is the fast path and compiler sometimes reorders that after the followup block with the memcpy (observed in practice with other simplifications). Overall effect on stack consumption: btrfs_get_8 -8 (80 -> 72) btrfs_set_8 -8 (88 -> 80) And .ko size (due to optimizations making use of the direct constants): text data bss dec hex filename 1456601 115665 16088 1588354 183c82 pre/btrfs.ko 1456093 115665 16088 1587846 183a86 post/btrfs.ko DELTA: -508 Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8049427 commit a16c62c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/btrfs/accessors.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
5959
u8 lebytes[sizeof(u##bits)]; \
6060
\
6161
ASSERT(check_setget_bounds(eb, ptr, off, size)); \
62-
if (INLINE_EXTENT_BUFFER_PAGES == 1 || oil + size <= unit_size) \
62+
if (INLINE_EXTENT_BUFFER_PAGES == 1 || likely(sizeof(u##bits) <= part)) \
6363
return get_unaligned_le##bits(kaddr + oil); \
6464
\
6565
memcpy(lebytes, kaddr + oil, part); \
@@ -82,7 +82,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
8282
\
8383
ASSERT(check_setget_bounds(eb, ptr, off, size)); \
8484
if (INLINE_EXTENT_BUFFER_PAGES == 1 || \
85-
oil + size <= unit_size) { \
85+
likely(sizeof(u##bits) <= part)) { \
8686
put_unaligned_le##bits(val, kaddr + oil); \
8787
return; \
8888
} \

0 commit comments

Comments
 (0)