From 58383c6866a76acb719b1f22caaba64fa4dd3f6e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 1 Jul 2025 19:23:51 +0200 Subject: [PATCH] btrfs: accessors: compile-time fast path for u8 Reading/writing 1 byte (u8) is a special case compared to the others as it's always contained in the folio we find, so the split memcpy will never be needed. Turn it to a compile-time check that the memcpy part can be optimized out. The stack usage is reduced: btrfs_set_8 -16 (32 -> 16) btrfs_get_8 -16 (24 -> 8) Code size reduction: text data bss dec hex filename 1454951 115665 16088 1586704 183610 pre/btrfs.ko 1454691 115665 16088 1586444 18350c post/btrfs.ko DELTA: -260 Reviewed-by: Boris Burkov Signed-off-by: David Sterba --- fs/btrfs/accessors.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/accessors.c b/fs/btrfs/accessors.c index a7b6b2d7bde22..547e9f8fb87d6 100644 --- a/fs/btrfs/accessors.c +++ b/fs/btrfs/accessors.c @@ -55,7 +55,8 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ report_setget_bounds(eb, ptr, off, sizeof(u##bits)); \ return 0; \ } \ - if (INLINE_EXTENT_BUFFER_PAGES == 1 || likely(sizeof(u##bits) <= part)) \ + if (INLINE_EXTENT_BUFFER_PAGES == 1 || sizeof(u##bits) == 1 || \ + likely(sizeof(u##bits) <= part)) \ return get_unaligned_le##bits(kaddr + oil); \ \ memcpy(lebytes, kaddr + oil, part); \ @@ -78,7 +79,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ report_setget_bounds(eb, ptr, off, sizeof(u##bits)); \ return; \ } \ - if (INLINE_EXTENT_BUFFER_PAGES == 1 || \ + if (INLINE_EXTENT_BUFFER_PAGES == 1 || sizeof(u##bits) == 1 || \ likely(sizeof(u##bits) <= part)) { \ put_unaligned_le##bits(val, kaddr + oil); \ return; \ -- 2.47.2