All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 8/9] btrfs: simplify eb checksum verification in btrfs_validate_metadata_buffer
Date: Wed, 26 May 2021 18:31:39 +0200	[thread overview]
Message-ID: <20210526163139.GG7604@twin.jikos.cz> (raw)
In-Reply-To: <0b51e0c9-896a-4ee2-f965-eec7b57cbd39@gmx.com>

On Wed, May 26, 2021 at 08:05:51AM +0800, Qu Wenruo wrote:
> On 2021/5/26 上午1:08, David Sterba wrote:
> > The verification copies the calculated checksum bytes to a temporary
> > buffer but this is not necessary. We can map the eb header on the first
> > page and use the checksum bytes directly.
> >
> > This saves at least one function call and boundary checks so it could
> > lead to a minor performance improvement.
> >
> > Signed-off-by: David Sterba <dsterba@suse.com>
> 
> The idea is good, and should be pretty simple to test.
> 
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> 
> But still a nitpick inlined below.
> > ---
> >   fs/btrfs/disk-io.c | 10 +++++-----
> >   1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> > index 6dc137684899..868e358f6923 100644
> > --- a/fs/btrfs/disk-io.c
> > +++ b/fs/btrfs/disk-io.c
> > @@ -584,6 +584,7 @@ static int validate_extent_buffer(struct extent_buffer *eb)
> >   	const u32 csum_size = fs_info->csum_size;
> >   	u8 found_level;
> >   	u8 result[BTRFS_CSUM_SIZE];
> > +	const struct btrfs_header *header;
> >   	int ret = 0;
> >
> >   	found_start = btrfs_header_bytenr(eb);
> > @@ -608,15 +609,14 @@ static int validate_extent_buffer(struct extent_buffer *eb)
> >   	}
> >
> >   	csum_tree_block(eb, result);
> > +	header = page_address(eb->pages[0]) +
> > +		 get_eb_offset_in_page(eb, offsetof(struct btrfs_leaf, header));
> 
> It takes me near a minute to figure why it's not just
> "get_eb_offset_in_page(eb, 0)".
> 
> I'm not sure if we really need that explicit way to just get 0,
> especially most of us (and even some advanced users) know that csum
> comes at the very beginning of a tree block.
> 
> And the mention of btrfs_leave can sometimes be confusing, especially
> when we could have tree nodes passed in.

Ah right, I wanted to use the offsetof for clarity but that it could be
used with nodes makes it confusing again. What if it's replaced by

	get_eb_offset_in_page(eb, offsetof(struct btrfs_header, csum));

This makes it clear that it's the checksum and from the experience we
know it's at offset 0. I'd rather avoid magic constants and offsets but
you're right that everybody knows that the checksum is at the beginning
of btree block.

  reply	other threads:[~2021-05-26 16:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 17:08 [PATCH 0/9] Misc fixups and cleanups David Sterba
2021-05-25 17:08 ` [PATCH 1/9] btrfs: sysfs: fix format string for some discard stats David Sterba
2021-05-25 23:47   ` Qu Wenruo
2021-05-26  6:01   ` Anand Jain
2021-05-25 17:08 ` [PATCH 2/9] btrfs: clear defrag status of a root if starting transaction fails David Sterba
2021-05-25 23:49   ` Qu Wenruo
2021-05-26  6:05   ` Anand Jain
2021-05-25 17:08 ` [PATCH 3/9] btrfs: clear log tree recovering status " David Sterba
2021-05-25 23:50   ` Qu Wenruo
2021-05-26  6:57   ` Anand Jain
2021-05-25 17:08 ` [PATCH 4/9] btrfs: scrub: factor out common scrub_stripe constraints David Sterba
2021-05-25 23:51   ` Qu Wenruo
2021-05-26  7:16   ` Anand Jain
2021-05-25 17:08 ` [PATCH 5/9] btrfs: document byte swap optimization of root_item::flags accessors David Sterba
2021-05-26  7:28   ` Anand Jain
2021-05-25 17:08 ` [PATCH 6/9] btrfs: reduce compressed_bio members' types David Sterba
2021-05-26  8:40   ` [PATCH] btrfs: optimize users of members of the struct compressed_bio Anand Jain
2021-05-26 16:34     ` David Sterba
2021-05-26  8:41   ` [PATCH 6/9] btrfs: reduce compressed_bio members' types Anand Jain
2021-05-25 17:08 ` [PATCH 7/9] btrfs: remove extra sb::s_id from message in btrfs_validate_metadata_buffer David Sterba
2021-05-25 23:59   ` Qu Wenruo
2021-05-26 12:54   ` Anand Jain
2021-05-25 17:08 ` [PATCH 8/9] btrfs: simplify eb checksum verification " David Sterba
2021-05-26  0:05   ` Qu Wenruo
2021-05-26 16:31     ` David Sterba [this message]
2021-05-26 16:58       ` David Sterba
2021-05-26 23:13         ` Qu Wenruo
2021-05-26 23:13           ` David Sterba
2021-05-25 17:08 ` [PATCH 9/9] btrfs: clean up header members offsets in write helpers David Sterba
2021-05-26  0:07   ` Qu Wenruo

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=20210526163139.GG7604@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.