From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/4] btrfs: simplify tree block checksumming loop
Date: Fri, 28 Feb 2020 16:41:23 +0800 [thread overview]
Message-ID: <a21a2263-c2d1-084b-4ebe-6f909da4afcb@gmx.com> (raw)
In-Reply-To: <4f450bbeec245479a3bc2b40d023d1979d622587.1582832619.git.dsterba@suse.com>
[-- Attachment #1.1: Type: text/plain, Size: 2543 bytes --]
On 2020/2/28 上午4:00, David Sterba wrote:
> Thw whole point of csum_tree_block is to iterate over all extent buffer
> pages and pass it to checksumming functions. The bytes where checksum is
> stored must be skipped, thus map_private_extent_buffer. This complicates
> further offset calculations.
>
> As the first page will be always present, checksum the relevant bytes
> unconditionally and then do a simple iteration over the remaining pages.
The new operation looks much better.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
>
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
> fs/btrfs/disk-io.c | 32 ++++++++------------------------
> 1 file changed, 8 insertions(+), 24 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 3952e4a2f3d7..5f74eb69f2fe 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -259,38 +259,22 @@ struct extent_map *btree_get_extent(struct btrfs_inode *inode,
> static int csum_tree_block(struct extent_buffer *buf, u8 *result)
> {
> struct btrfs_fs_info *fs_info = buf->fs_info;
> + const int num_pages = fs_info->nodesize >> PAGE_SHIFT;
> SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
> - unsigned long len;
> - unsigned long cur_len;
> - unsigned long offset = BTRFS_CSUM_SIZE;
> char *kaddr;
> - unsigned long map_start;
> - unsigned long map_len;
> - int err;
> + int i;
>
> shash->tfm = fs_info->csum_shash;
> crypto_shash_init(shash);
> + kaddr = page_address(buf->pages[0]);
> + crypto_shash_update(shash, kaddr + BTRFS_CSUM_SIZE,
> + PAGE_SIZE - BTRFS_CSUM_SIZE);
>
> - len = buf->len - offset;
> -
> - while (len > 0) {
> - /*
> - * Note: we don't need to check for the err == 1 case here, as
> - * with the given combination of 'start = BTRFS_CSUM_SIZE (32)'
> - * and 'min_len = 32' and the currently implemented mapping
> - * algorithm we cannot cross a page boundary.
> - */
> - err = map_private_extent_buffer(buf, offset, 32,
> - &kaddr, &map_start, &map_len);
> - if (WARN_ON(err))
> - return err;
> - cur_len = min(len, map_len - (offset - map_start));
> - crypto_shash_update(shash, kaddr + offset - map_start, cur_len);
> - len -= cur_len;
> - offset += cur_len;
> + for (i = 1; i < num_pages; i++) {
> + kaddr = page_address(buf->pages[i]);
> + crypto_shash_update(shash, kaddr, PAGE_SIZE);
> }
> memset(result, 0, BTRFS_CSUM_SIZE);
> -
> crypto_shash_final(shash, result);
>
> return 0;
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-02-28 8:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-27 20:00 [PATCH 0/4] Misc cleanups David Sterba
2020-02-27 20:00 ` [PATCH 1/4] btrfs: inline checksum name and driver definitions David Sterba
2020-02-27 22:31 ` Johannes Thumshirn
2020-02-28 8:38 ` Qu Wenruo
2020-02-27 20:00 ` [PATCH 2/4] btrfs: simplify tree block checksumming loop David Sterba
2020-02-27 22:52 ` Johannes Thumshirn
2020-02-28 8:41 ` Qu Wenruo [this message]
2020-02-27 20:00 ` [PATCH 3/4] btrfs: return void from csum_tree_block David Sterba
2020-02-27 22:32 ` Johannes Thumshirn
2020-02-28 8:41 ` Qu Wenruo
2020-02-27 20:00 ` [PATCH 4/4] btrfs: balance: factor out convert profile validation David Sterba
2020-02-27 22:33 ` Johannes Thumshirn
2020-02-28 8:43 ` 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=a21a2263-c2d1-084b-4ebe-6f909da4afcb@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--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