btrfs: pre-load data checksum for reads in btrfs_submit_bio

Instead of calling btrfs_lookup_bio_sums in every caller of
btrfs_submit_bio that reads data, do the call once in btrfs_submit_bio.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Christoph Hellwig 2023-01-21 07:50:05 +01:00 committed by David Sterba
parent 7276aa7d38
commit 1c2b3ee3b0
3 changed files with 10 additions and 32 deletions

View file

@ -14,6 +14,7 @@
#include "dev-replace.h"
#include "rcu-string.h"
#include "zoned.h"
#include "file-item.h"
static struct bio_set btrfs_bioset;
@ -253,9 +254,16 @@ void btrfs_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, int mirror
BUG();
}
/* Save the iter for the end_io handler for data reads. */
if (bio_op(bio) == REQ_OP_READ && !(bio->bi_opf & REQ_META))
/*
* Save the iter for the end_io handler and preload the checksums for
* data reads.
*/
if (bio_op(bio) == REQ_OP_READ && !(bio->bi_opf & REQ_META)) {
bbio->iter = bio->bi_iter;
ret = btrfs_lookup_bio_sums(bbio);
if (ret)
goto fail;
}
if (!bioc) {
/* Single mirror read/write fast path */

View file

@ -797,12 +797,6 @@ void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
*/
btrfs_bio(comp_bio)->file_offset = file_offset;
ret = btrfs_lookup_bio_sums(btrfs_bio(comp_bio));
if (ret) {
btrfs_bio_end_io(btrfs_bio(comp_bio), ret);
break;
}
ASSERT(comp_bio->bi_iter.bi_size);
btrfs_submit_bio(fs_info, comp_bio, mirror_num);
comp_bio = NULL;

View file

@ -2762,7 +2762,6 @@ void btrfs_submit_data_read_bio(struct btrfs_inode *inode, struct bio *bio,
int mirror_num, enum btrfs_compression_type compress_type)
{
struct btrfs_fs_info *fs_info = inode->root->fs_info;
blk_status_t ret;
if (compress_type != BTRFS_COMPRESS_NONE) {
/*
@ -2773,16 +2772,6 @@ void btrfs_submit_data_read_bio(struct btrfs_inode *inode, struct bio *bio,
return;
}
/*
* Lookup bio sums does extra checks around whether we need to csum or
* not, which is why we ignore skip_sum here.
*/
ret = btrfs_lookup_bio_sums(btrfs_bio(bio));
if (ret) {
btrfs_bio_end_io(btrfs_bio(bio), ret);
return;
}
btrfs_submit_bio(fs_info, bio, mirror_num);
}
@ -8004,12 +7993,6 @@ static void btrfs_submit_dio_bio(struct bio *bio, struct btrfs_inode *inode,
btrfs_bio_end_io(btrfs_bio(bio), ret);
return;
}
} else {
ret = btrfs_lookup_bio_sums(btrfs_bio(bio));
if (ret) {
btrfs_bio_end_io(btrfs_bio(bio), ret);
return;
}
}
map:
btrfs_submit_bio(fs_info, bio, 0);
@ -10269,13 +10252,6 @@ static blk_status_t submit_encoded_read_bio(struct btrfs_inode *inode,
{
struct btrfs_encoded_read_private *priv = btrfs_bio(bio)->private;
struct btrfs_fs_info *fs_info = inode->root->fs_info;
blk_status_t ret;
if (!priv->skip_csum) {
ret = btrfs_lookup_bio_sums(btrfs_bio(bio));
if (ret)
return ret;
}
atomic_inc(&priv->pending);
btrfs_submit_bio(fs_info, bio, mirror_num);