From: Boris Burkov <boris@bur.io>
To: David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/7] btrfs: accessors: use type sizeof constants directly
Date: Wed, 2 Jul 2025 10:58:54 -0700 [thread overview]
Message-ID: <20250702175854.GA2308047@zen.localdomain> (raw)
In-Reply-To: <eedbe03f6ee33939841d4bf895519304dfa1c59f.1751390044.git.dsterba@suse.com>
On Tue, Jul 01, 2025 at 07:23:49PM +0200, David Sterba wrote:
> Now unit_size is used only once, so use it directly in 'part'
> calculation. Don't cache sizeof(type) in a variable. While this is a
> compile-time constant, forcing the type 'int' generates worse code as it
> leads to additional conversion from 32 to 64 bit type on x86_64.
>
> The sizeof() is used only a few times and it does not make the code that
> harder to read, so use it directly and let the compiler utilize the
> immediate constants in the context it needs. The .ko code size slightly
> increases (+50) but further patches will reduce that again.
>
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
> fs/btrfs/accessors.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/fs/btrfs/accessors.c b/fs/btrfs/accessors.c
> index b54c8abe467a06..2e90b9b14e73f4 100644
> --- a/fs/btrfs/accessors.c
> +++ b/fs/btrfs/accessors.c
> @@ -52,19 +52,17 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
> const unsigned long idx = get_eb_folio_index(eb, member_offset);\
> const unsigned long oil = get_eb_offset_in_folio(eb, \
> member_offset);\
> - const int unit_size = eb->folio_size; \
> char *kaddr = folio_address(eb->folios[idx]); \
> - const int size = sizeof(u##bits); \
> - const int part = unit_size - oil; \
> + const int part = eb->folio_size - oil; \
nit: the names oil and part are pretty non-sensical to me. Oil used to
be oip for Offset In Page. Is it Offset In foLio?
I can't figure out what part should mean.
So while I see why you're doing all the changes, I can' help but notice
that you removed the two named variables with logical names and left the
confusing ones. :)
> u8 lebytes[sizeof(u##bits)]; \
> \
> - ASSERT(check_setget_bounds(eb, ptr, off, size)); \
> + ASSERT(check_setget_bounds(eb, ptr, off, sizeof(u##bits))); \
> if (INLINE_EXTENT_BUFFER_PAGES == 1 || likely(sizeof(u##bits) <= part)) \
> return get_unaligned_le##bits(kaddr + oil); \
> \
> memcpy(lebytes, kaddr + oil, part); \
> kaddr = folio_address(eb->folios[idx + 1]); \
> - memcpy(lebytes + part, kaddr, size - part); \
> + memcpy(lebytes + part, kaddr, sizeof(u##bits) - part); \
> return get_unaligned_le##bits(lebytes); \
> } \
> void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
> @@ -74,13 +72,11 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
> const unsigned long idx = get_eb_folio_index(eb, member_offset);\
> const unsigned long oil = get_eb_offset_in_folio(eb, \
> member_offset);\
> - const int unit_size = eb->folio_size; \
> char *kaddr = folio_address(eb->folios[idx]); \
> - const int size = sizeof(u##bits); \
> - const int part = unit_size - oil; \
> + const int part = eb->folio_size - oil; \
> u8 lebytes[sizeof(u##bits)]; \
> \
> - ASSERT(check_setget_bounds(eb, ptr, off, size)); \
> + ASSERT(check_setget_bounds(eb, ptr, off, sizeof(u##bits))); \
> if (INLINE_EXTENT_BUFFER_PAGES == 1 || \
> likely(sizeof(u##bits) <= part)) { \
> put_unaligned_le##bits(val, kaddr + oil); \
> @@ -90,7 +86,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
> put_unaligned_le##bits(val, lebytes); \
> memcpy(kaddr + oil, lebytes, part); \
> kaddr = folio_address(eb->folios[idx + 1]); \
> - memcpy(kaddr, lebytes + part, size - part); \
> + memcpy(kaddr, lebytes + part, sizeof(u##bits) - part); \
> }
>
> DEFINE_BTRFS_SETGET_BITS(8)
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-07-02 17:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 17:23 [PATCH 0/7] Set/get accessor speedups David Sterba
2025-07-01 17:23 ` [PATCH 1/7] btrfs: accessors: simplify folio bounds checks David Sterba
2025-07-01 17:23 ` [PATCH 2/7] btrfs: accessors: use type sizeof constants directly David Sterba
2025-07-02 17:58 ` Boris Burkov [this message]
2025-07-03 21:20 ` David Sterba
2025-07-07 14:25 ` David Sterba
2025-07-01 17:23 ` [PATCH 3/7] btrfs: accessors: inline eb bounds check and factor out the error report David Sterba
2025-07-02 18:00 ` Boris Burkov
2025-07-03 21:16 ` David Sterba
2025-07-01 17:23 ` [PATCH 4/7] btrfs: accessors: compile-time fast path for u8 David Sterba
2025-07-01 17:23 ` [PATCH 5/7] btrfs: accessors: compile-time fast path for u16 David Sterba
2025-07-01 17:23 ` [PATCH 6/7] btrfs: accessors: set target address at initialization David Sterba
2025-07-01 17:23 ` [PATCH 7/7] btrfs: accessors: factor out split memcpy with two sources David Sterba
2025-07-02 18:53 ` Boris Burkov
2025-07-03 20:57 ` David Sterba
2025-07-02 18:54 ` [PATCH 0/7] Set/get accessor speedups Boris Burkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250702175854.GA2308047@zen.localdomain \
--to=boris@bur.io \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox