Btrfs: rewrite BTRFS_SETGET_FUNCS macro
PATCH 1/1 Btrfs: rewrite BTRFS_SETGET_FUNCS macro
BTRFS_SETGET_FUNCS macro is used to generate btrfs_set_foo() and btrfs_foo() functions, which read and write specific fields in the extent buffer.
The total number of set/get functions is ~200, but in fact we only need 8 functions: 2 for u8 field, 2 for u16, 2 for u32 and 2 for u64.
It results in redunction of ~22K bytes.
text data bss dec hex filename 528069 4328 1060 533457 823d1 fs/btrfs/btrfs.o.orig 505997 4328 1060 511385 7cd99 fs/btrfs/btrfs.o
Compared btrfs_set_bits() with btrfs_set_foo(), the extra runtime overhead is we have to pass one more argument.
Signed-off-by Li Zefan <[email protected]>
--- fs/btrfs/ctree.h | 26 +++++++++-- fs/btrfs/struct-funcs.c | 118 ++++++++++++++++++++++++----------------------- 2 files changed, 83 insertions(+), 61 deletions(-)
fs/btrfs/ctree.h +22 -4
@@ -1406,11 +1406,29 @@ struct btrfs_ioctl_defrag_range_args { offsetof(type, member), \ sizeof(((type *)0)->member))) -#ifndef BTRFS_SETGET_FUNCS +#define DECLARE_BTRFS_SETGET_BITS (bits) \ +u##bits btrfs_get_u##bits(struct extent_buffer *eb, void *ptr, \ + unsigned long off); \ +void btrfs_set_u##bits(struct extent_buffer *eb, void *ptr, \ + unsigned long off, u##bits val) + +DECLARE_BTRFS_SETGET_BITS (8 ); +DECLARE_BTRFS_SETGET_BITS (16 ); +DECLARE_BTRFS_SETGET_BITS (32 ); +DECLARE_BTRFS_SETGET_BITS (64 ); +#define BTRFS_SETGET_FUNCS (name, type, member, bits) \ -u##bits btrfs_##name(struct extent_buffer *eb, type *s); \ -void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val); -#endif +static inline u##bits btrfs_##name(struct extent_buffer *eb, type *s) \ +{ \ + BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0)->member)); \ + return btrfs_get_u##bits(eb, s, offsetof(type, member)); \ +} \ +static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \ + u##bits val) \ +{ \ + BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ + btrfs_set_u##bits(eb, s, offsetof(type, member), val); \ +}#define BTRFS_SETGET_HEADER_FUNCS (name, type, member, bits) \ static inline u##bits btrfs_##name(struct extent_buffer *eb) \
fs/btrfs/struct-funcs.c +61 -57
141 lines not on this page · raw message
Signature · 1 line
1.7.3.1