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

btrfs: reduce size and overhead of extent_map_block_end()

At extent_map_block_end() we are calling the inline functions
extent_map_block_start() and extent_map_block_len() multiple times, which
results in expanding their code multiple times, increasing the compiled
code size and repeating the computations those functions do.

Improve this by caching their results in local variables.

The size of the module before this change:

$ size fs/btrfs/btrfs.ko
text data bss dec hex filename
1755770 163800 16920 1936490 1d8c6a fs/btrfs/btrfs.ko

And after this change:

$ size fs/btrfs/btrfs.ko
text data bss dec hex filename
1755656 163800 16920 1936376 1d8bf8 fs/btrfs/btrfs.ko

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Filipe Manana and committed by
David Sterba
ab094670 7fa5230b

+6 -3
+6 -3
fs/btrfs/extent_map.c
··· 192 192 193 193 static inline u64 extent_map_block_end(const struct extent_map *em) 194 194 { 195 - if (extent_map_block_start(em) + extent_map_block_len(em) < 196 - extent_map_block_start(em)) 195 + const u64 block_start = extent_map_block_start(em); 196 + const u64 block_end = block_start + extent_map_block_len(em); 197 + 198 + if (block_end < block_start) 197 199 return (u64)-1; 198 - return extent_map_block_start(em) + extent_map_block_len(em); 200 + 201 + return block_end; 199 202 } 200 203 201 204 static bool can_merge_extent_map(const struct extent_map *em)