* [PATCH] btrfs: reduce size and overhead of extent_map_block_end()
@ 2024-07-23 15:16 fdmanana
2024-07-23 15:40 ` Josef Bacik
2024-07-23 21:52 ` Qu Wenruo
0 siblings, 2 replies; 3+ messages in thread
From: fdmanana @ 2024-07-23 15:16 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
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
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/extent_map.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index f85f0172b58b..806a8954b3d5 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -192,10 +192,13 @@ static inline u64 extent_map_block_len(const struct extent_map *em)
static inline u64 extent_map_block_end(const struct extent_map *em)
{
- if (extent_map_block_start(em) + extent_map_block_len(em) <
- extent_map_block_start(em))
+ const u64 block_start = extent_map_block_start(em);
+ const u64 block_end = block_start + extent_map_block_len(em);
+
+ if (block_end < block_start)
return (u64)-1;
- return extent_map_block_start(em) + extent_map_block_len(em);
+
+ return block_end;
}
static bool can_merge_extent_map(const struct extent_map *em)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: reduce size and overhead of extent_map_block_end()
2024-07-23 15:16 [PATCH] btrfs: reduce size and overhead of extent_map_block_end() fdmanana
@ 2024-07-23 15:40 ` Josef Bacik
2024-07-23 21:52 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2024-07-23 15:40 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Tue, Jul 23, 2024 at 04:16:03PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> 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
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: reduce size and overhead of extent_map_block_end()
2024-07-23 15:16 [PATCH] btrfs: reduce size and overhead of extent_map_block_end() fdmanana
2024-07-23 15:40 ` Josef Bacik
@ 2024-07-23 21:52 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2024-07-23 21:52 UTC (permalink / raw)
To: fdmanana, linux-btrfs
在 2024/7/24 00:46, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> 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
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/extent_map.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
> index f85f0172b58b..806a8954b3d5 100644
> --- a/fs/btrfs/extent_map.c
> +++ b/fs/btrfs/extent_map.c
> @@ -192,10 +192,13 @@ static inline u64 extent_map_block_len(const struct extent_map *em)
>
> static inline u64 extent_map_block_end(const struct extent_map *em)
> {
> - if (extent_map_block_start(em) + extent_map_block_len(em) <
> - extent_map_block_start(em))
> + const u64 block_start = extent_map_block_start(em);
> + const u64 block_end = block_start + extent_map_block_len(em);
> +
> + if (block_end < block_start)
> return (u64)-1;
> - return extent_map_block_start(em) + extent_map_block_len(em);
> +
> + return block_end;
> }
>
> static bool can_merge_extent_map(const struct extent_map *em)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-23 21:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 15:16 [PATCH] btrfs: reduce size and overhead of extent_map_block_end() fdmanana
2024-07-23 15:40 ` Josef Bacik
2024-07-23 21:52 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox