simple synchronous read repair v2
Subsystems (2)
Hi all,
this is my take on the read repair code. It borrow a lot of concepts and patches from Qu's attempt. The big difference is that it does away with multiple in-flight repair bios, but instead just does one at a time, but tries to make it as big as possible.
My aim here is mostly to fix up the messy I/O completions for the direct I/O path, that make further bio optimizations rather annoying, but it also gives better I/O patterns for repair (although I'm not sure anyone cares) and removes a fair chunk of code.
[this is on top of a not commit yet series. I kinda hate doing that, but
with all the hot repair discussion going on right now we might as well have an uptodate version of this series out on the list]
Git tree:
git://git.infradead.org/users/hch/misc.git btrfs-read_repair
Gitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/btrfs-read_repair
Changes since v1:
- rebased on top of the "misc btrfs cleanups" series that contains various patches previously in this series and the "cleanup btrfs bio handling, part 2 v4" series
- handle partial reads due to checksum failures
- handle large I/O for parity RAID repair as well
- add a lot more comments
- rename btrfs_read_repair_end to btrfs_read_repair_finish
Diffstat:
fs/btrfs/Makefile | 2 fs/btrfs/btrfs_inode.h | 5 fs/btrfs/extent-io-tree.h | 15 - fs/btrfs/extent_io.c | 570 ++++--------------------------------------- fs/btrfs/extent_io.h | 25 - fs/btrfs/inode.c | 55 +--- fs/btrfs/read-repair.c | 248 ++++++++++++++++++ fs/btrfs/read-repair.h | 33 ++ fs/btrfs/super.c | 9 fs/btrfs/volumes.c | 97 +++++++ fs/btrfs/volumes.h | 2 include/trace/events/btrfs.h | 1 12 files changed, 467 insertions(+), 595 deletions(-)
PATCH 1/9 btrfs: save the original bi_iter into btrfs_bio for buffered read
From: Qu Wenruo <[email protected]>
Although we have btrfs_bio::iter, it currently have very limited usage:
- RAID56
Which is not needed at all
- btrfs_bio_clone()
This is used mostly for direct IO.
For the incoming read repair patches, we want to grab the original logical bytenr, and be able to iterate the range of the bio (no matter if it's cloned).
So this patch will also save btrfs_bio::iter for buffered read bios at submit_one_bio().
And for the sake of consistency, also save the btrfs_bio::iter for direct IO at btrfs_submit_dio_bio().
The reason that we didn't save the iter in btrfs_map_bio() is, btrfs_map_bio() is going to handle various bios, with or without btrfs_bio bioset.
And we want to keep btrfs_map_bio() to handle and only handle plain bios without bother the bioset.
--- fs/btrfs/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/btrfs/inode.c +8 -0
@@ -2633,6 +2633,10 @@ void btrfs_submit_data_read_bio(struct inode *inode, struct bio *bio,struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);blk_status_t ret; +/* save the original iter for read repair */ +if (bio_op (bio) ==REQ_OP_READ ) +btrfs_bio (bio)->iter = bio->bi_iter; +if (compress_type !=BTRFS_COMPRESS_NONE ) {/* * btrfs_submit_compressed_read will handle completing the bio
@@ -7947,6 +7951,10 @@ static inline blk_status_t btrfs_submit_dio_bio(struct bio *bio,struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);struct btrfs_dio_private *dip = bio->bi_private;blk_status_t ret; + +/* save the original iter for read repair */ +if (btrfs_op (bio) ==BTRFS_MAP_READ ) { +btrfs_bio (bio)->iter = bio->bi_iter;if (BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM ) goto map;
Signature · 1 line
2.30.2
PATCH 2/9 btrfs: set ->file_offset in end_bio_extent_readpage
In reply to Christoph HellwigThe new repair code expects ->file_offset to be set for all bios. Set it just after entering end_bio_extent_readpage. As that requires looking at the first vector before the first loop iteration also use that opportunity to set various file-wide variables just once instead of once per loop iteration.
--- fs/btrfs/extent_io.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
fs/btrfs/extent_io.c +12 -10
@@ -3009,25 +3009,30 @@ static struct extent_buffer *find_extent_buffer_readpage(*/ static void end_bio_extent_readpage (struct bio *bio) { +struct bio_vec *first_vec =bio_first_bvec_all (bio); +struct inode *inode = first_vec->bv_page->mapping->host; +struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +const u32 sectorsize = fs_info->sectorsize;struct bio_vec *bvec;struct btrfs_bio *bbio =btrfs_bio (bio); -struct extent_io_tree *tree, *failure_tree; +int mirror = bbio->mirror_num; +struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree; +struct extent_io_tree *failure_tree = &BTRFS_I (inode)->io_failure_tree; +bool uptodate = !bio->bi_status;struct processed_extent processed = {0 };/* * The offset to the beginning of a bio, since one bio can never be * larger than UINT_MAX, u32 here is enough. */ u32 bio_offset =0 ; -int mirror;struct bvec_iter_all iter_all; +btrfs_bio (bio)->file_offset = +page_offset (first_vec->bv_page) + first_vec->bv_offset; +ASSERT (!bio_flagged (bio,BIO_CLONED ));bio_for_each_segment_all (bvec, bio, iter_all) { -bool uptodate = !bio->bi_status;struct page *page = bvec->bv_page; -struct inode *inode = page->mapping->host; -struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); -const u32 sectorsize = fs_info->sectorsize;unsigned int error_bitmap = (unsigned int )-1 ;bool repair = false;u64 start;
@@ -3037,9 +3042,7 @@ static void end_bio_extent_readpage(struct bio *bio)btrfs_debug (fs_info,"end_bio_extent_readpage: bi_sector=%llu, err=%d, mirror=%u" , bio->bi_iter.bi_sector, bio->bi_status, - bbio->mirror_num); - tree = &BTRFS_I (inode)->io_tree; - failure_tree = &BTRFS_I (inode)->io_failure_tree; + mirror);/* * We always issue full-sector reads, but if some block in a
@@ -3062,7 +3065,6 @@ static void end_bio_extent_readpage(struct bio *bio) end = start + bvec->bv_len -1 ; len = bvec->bv_len; - mirror = bbio->mirror_num;if (likely (uptodate)) {if (is_data_inode (inode)) { error_bitmap = btrfs_verify_data_csum(bbio,
Signature · 1 line
2.30.2
PATCH 3/9 btrfs: factor out a btrfs_map_repair_bio helper
In reply to Christoph HellwigFactor out the guts of repair_io_failure so that we have a new helper to submit synchronous I/O for repair. Unlike repair_io_failure itself this helper also handles reads.
--- fs/btrfs/extent_io.c | 82 ++++++-------------------------------------- fs/btrfs/volumes.c | 69 +++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ 3 files changed, 81 insertions(+), 72 deletions(-)
fs/btrfs/extent_io.c +10 -72
@@ -2308,27 +2308,13 @@ int free_io_failure(struct extent_io_tree *failure_tree,return err; } -/* -* this bypasses the standard btrfs submit functions deliberately, as -* the standard behavior is to write all copies in a raid setup. here we only -* want to write the one bad copy. so we do the mapping for ourselves and issue -* submit_bio directly. -* to avoid any synchronization issues, wait for the data after writing, which -* actually prevents the read that triggered the error from finishing. -* currently, there can be no more than two copies of every data bit. thus, -* exactly one rewrite is required. -*/ static int repair_io_failure (struct btrfs_fs_info *fs_info,u64 ino,u64 start,u64 length,u64 logical,struct page *page,unsigned int pg_offset,int mirror_num) { -struct btrfs_device *dev;struct bio_vec bvec;struct bio bio; -u64 map_length =0 ; -u64 sector; -struct btrfs_io_context *bioc =NULL ; -int ret =0 ; +int ret;ASSERT (!(fs_info->sb->s_flags &SB_RDONLY ));BUG_ON (!mirror_num);
@@ -2336,67 +2322,19 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,if (btrfs_repair_one_zone (fs_info, logical))return 0 ; - map_length = length; - -/* -* Avoid races with device replace and make sure our bioc has devices -* associated to its stripes that don't go away while we are doing the -* read repair operation. -*/ -btrfs_bio_counter_inc_blocked (fs_info); -if (btrfs_is_parity_mirror (fs_info, logical, length)) { -/* -* Note that we don't use BTRFS_MAP_WRITE because it's supposed -* to update all raid stripes, but here we just want to correct -* bad stripe, thus BTRFS_MAP_READ is abused to only get the bad -* stripe's dev and sector. -*/ - ret =btrfs_map_block (fs_info,BTRFS_MAP_READ , logical, - &map_length, &bioc,0 ); -if (ret) - goto out_counter_dec; -ASSERT (bioc->mirror_num ==1 ); - }else { - ret =btrfs_map_block (fs_info,BTRFS_MAP_WRITE , logical, - &map_length, &bioc, mirror_num); -if (ret) - goto out_counter_dec; -BUG_ON (mirror_num != bioc->mirror_num); - } - - sector = bioc->stripes[bioc->mirror_num -1 ].physical >>9 ; - dev = bioc->stripes[bioc->mirror_num -1 ].dev; -btrfs_put_bioc (bioc); - -if (!dev || !dev->bdev || - !test_bit (BTRFS_DEV_STATE_WRITEABLE , &dev->dev_state)) { - ret = -EIO ; - goto out_counter_dec; - } - -bio_init (&bio, dev->bdev, &bvec,1 ,REQ_OP_WRITE |REQ_SYNC ); - bio.bi_iter.bi_sector = sector; +bio_init (&bio,NULL , &bvec,1 ,REQ_OP_WRITE |REQ_SYNC ); + bio.bi_iter.bi_sector = logical >>9 ;__bio_add_page (&bio, page, length, pg_offset); + ret =btrfs_map_repair_bio (fs_info, &bio, mirror_num); +bio_uninit (&bio); -btrfsic_check_bio (&bio); - ret =submit_bio_wait (&bio); -if (ret) { -/* try to remap that extent elsewhere? */ -btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS ); - goto out_bio_uninit; - } +if (ret) +return ret;btrfs_info_rl_in_rcu (fs_info, -"read error corrected: ino %llu off %llu (dev %s sector %llu)" , - ino, start, -rcu_str_deref (dev->name), sector); - ret =0 ; - -out_bio_uninit: -bio_uninit (&bio); -out_counter_dec: -btrfs_bio_counter_dec (fs_info); -return ret; +"read error corrected: ino %llu off %llu (logical %llu)" , + ino, start, logical); +return 0 ; }int btrfs_repair_eb_io_failure (const struct extent_buffer *eb,int mirror_num)
fs/btrfs/volumes.c +69 -0
75 lines not on this page · raw message
fs/btrfs/volumes.h +2 -0
@@ -565,6 +565,8 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,void btrfs_mapping_tree_free (struct extent_map_tree *tree);blk_status_t btrfs_map_bio (struct btrfs_fs_info *fs_info,struct bio *bio,int mirror_num); +int btrfs_map_repair_bio (struct btrfs_fs_info *fs_info,struct bio *bio, +int mirror_num);int btrfs_open_devices (struct btrfs_fs_devices *fs_devices,fmode_t flags,void *holder); struct btrfs_device *btrfs_scan_one_device(const char *path,
Signature · 1 line
2.30.2
PATCH 4/9 btrfs: support read bios in btrfs_map_repair_bio
In reply to Christoph HellwigEnhance btrfs_map_repair_bio to also support reading so that we have a single function dealing with all synchronous bio I/O for the repair code.
--- fs/btrfs/volumes.c | 48 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-)
fs/btrfs/volumes.c +38 -10
@@ -6805,6 +6805,11 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,return errno_to_blk_status (ret); } +static void btrfs_bio_end_io_sync (struct bio *bio) +{ +complete (bio->bi_private); +} +/* * This bypasses the standard btrfs submit functions deliberately, as the * standard behavior is to write all copies in a raid setup. Here we only want
@@ -6814,15 +6819,17 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,int btrfs_map_repair_bio (struct btrfs_fs_info *fs_info,struct bio *bio,int mirror_num) { +enum btrfs_map_op op =btrfs_op (bio);u64 logical = bio->bi_iter.bi_sector <<9 ;u64 map_length = bio->bi_iter.bi_size; +bool is_raid56 =btrfs_is_parity_mirror (fs_info, logical, map_length);struct btrfs_io_context *bioc =NULL ; +unsigned int stripe_idx =0 ;struct btrfs_device *dev;u64 sector;int ret;ASSERT (mirror_num); -ASSERT (bio_op (bio) ==REQ_OP_WRITE );/* * Avoid races with device replace and make sure our bioc has devices
@@ -6830,7 +6837,23 @@ int btrfs_map_repair_bio(struct btrfs_fs_info *fs_info, struct bio *bio,* read repair operation. */ btrfs_bio_counter_inc_blocked (fs_info); -if (btrfs_is_parity_mirror (fs_info, logical, map_length)) { +if (is_raid56) { +if (op ==BTRFS_MAP_READ ) { +DECLARE_COMPLETION_ONSTACK (done); + + ret =__btrfs_map_block (fs_info, op, logical, + &map_length, &bioc, mirror_num,1 ); +if (ret) + goto out_counter_dec; + + bio->bi_private = &done; + bio->bi_end_io = btrfs_bio_end_io_sync; + ret =raid56_parity_recover (bio, bioc, + map_length, mirror_num,1 ); +wait_for_completion_io (&done); + goto out_bio_status; + } +/* * Note that we don't use BTRFS_MAP_WRITE because it's supposed * to update all raid stripes, but here we just want to correct
@@ -6843,19 +6866,24 @@ int btrfs_map_repair_bio(struct btrfs_fs_info *fs_info, struct bio *bio, goto out_counter_dec;ASSERT (bioc->mirror_num ==1 ); }else { - ret =btrfs_map_block (fs_info,BTRFS_MAP_WRITE , logical, - &map_length, &bioc, mirror_num); + ret =btrfs_map_block (fs_info, op, logical, &map_length, &bioc, + mirror_num);if (ret) goto out_counter_dec; -BUG_ON (mirror_num != bioc->mirror_num); + +if (op ==BTRFS_MAP_WRITE ) { +ASSERT (mirror_num == bioc->mirror_num); + stripe_idx = bioc->mirror_num -1 ; + } } - sector = bioc->stripes[bioc->mirror_num -1 ].physical >>9 ; - dev = bioc->stripes[bioc->mirror_num -1 ].dev; + sector = bioc->stripes[stripe_idx].physical >>9 ; + dev = bioc->stripes[stripe_idx].dev;btrfs_put_bioc (bioc);if (!dev || !dev->bdev || - !test_bit (BTRFS_DEV_STATE_WRITEABLE , &dev->dev_state)) { + (op ==BTRFS_MAP_WRITE && + !test_bit (BTRFS_DEV_STATE_WRITEABLE , &dev->dev_state))) { ret = -EIO ; goto out_counter_dec; }
@@ -6865,9 +6893,9 @@ int btrfs_map_repair_bio(struct btrfs_fs_info *fs_info, struct bio *bio,btrfsic_check_bio (bio);submit_bio_wait (bio); - +out_bio_status: ret =blk_status_to_errno (bio->bi_status); -if (ret) +if (ret && op ==BTRFS_MAP_WRITE )btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS ); out_counter_dec:btrfs_bio_counter_dec (fs_info);
Signature · 1 line
2.30.2
PATCH 5/9 btrfs: add new read repair infrastructure
In reply to Christoph HellwigThis adds a new read repair implementation for btrfs. It is synchronous in that the end I/O handlers call them, and will get back the results instead of potentially getting multiple concurrent calls back into the original end I/O handler. The synchronous nature has the following advantages:
- there is no need for a per-I/O tree of I/O failures, as everything related to the I/O failure can be handled locally
- not having separate repair end I/O helpers will in the future help to reuse the direct I/O bio from iomap for the actual submission and thus remove the btrfs_dio_private infrastructure
Because submitting many sector size synchronous I/Os would be very slow when multiple sectors (or a whole read) fail, this new code instead submits a single read and repair write bio for each contiguous section. It uses clone of the bio to do that and thus does not need to allocate any extra bio_vecs. Note that this cloning is open coded instead of using the block layer clone helpers as the clone is based on the save iter in the btrfs_bio, and not bio.bi_iter, which at the point that the repair code is called has been advanced by the low-level driver.
--- fs/btrfs/Makefile | 2 +- fs/btrfs/inode.c | 2 +- fs/btrfs/read-repair.c | 248 +++++++++++++++++++++++++++++++++++++++++ fs/btrfs/read-repair.h | 33 ++++++ fs/btrfs/super.c | 9 +- 5 files changed, 290 insertions(+), 4 deletions(-) create mode 100644 fs/btrfs/read-repair.c create mode 100644 fs/btrfs/read-repair.h
fs/btrfs/Makefile +1 -1
@@ -31,7 +31,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \ block-rsv.o delalloc-space.o block-group.o discard.o reflink.o \ - subpage.o tree-mod-log.o + subpage.o tree-mod-log.o read-repair.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
fs/btrfs/inode.c +1 -1
@@ -7953,7 +7953,7 @@ static inline blk_status_t btrfs_submit_dio_bio(struct bio *bio,blk_status_t ret;/* save the original iter for read repair */ -if (btrfs_op (bio) ==BTRFS_MAP_READ ) { +if (btrfs_op (bio) ==BTRFS_MAP_READ )btrfs_bio (bio)->iter = bio->bi_iter;if (BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM )
fs/btrfs/read-repair.c new file +248 -0
248 lines not on this page · raw message
fs/btrfs/read-repair.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef BTRFS_READ_REPAIR_H +#define BTRFS_READ_REPAIR_H + +struct btrfs_read_repair { +u64 start_offset; +bool in_use; +int num_copies; +}; + +typedef void (*repair_endio_t )(struct btrfs_bio *repair_bbio, +struct inode *inode,bool uptodate); + +bool btrfs_read_repair_add (struct btrfs_read_repair *rr, +struct btrfs_bio *failed_bbio,struct inode *inode, +u64 bio_offset); +bool __btrfs_read_repair_finish (struct btrfs_read_repair *rr, +struct btrfs_bio *failed_bbio,struct inode *inode, +u64 end_offset,repair_endio_t end_io); +static inline bool btrfs_read_repair_finish (struct btrfs_read_repair *rr, +struct btrfs_bio *failed_bbio,struct inode *inode, +u64 end_offset,repair_endio_t endio) +{ +if (!rr->in_use) +return true; +return __btrfs_read_repair_finish (rr, failed_bbio, inode, end_offset, + endio); +} + +int __init btrfs_read_repair_init (void ); +void btrfs_read_repair_exit (void ); + +#endif /* BTRFS_READ_REPAIR_H */
fs/btrfs/super.c +7 -2
@@ -48,6 +48,7 @@#include "block-group.h" #include "discard.h" #include "qgroup.h" +#include "read-repair.h" #define CREATE_TRACE_POINTS #include <trace/events/btrfs.h>
@@ -2645,10 +2646,12 @@ static int __init init_btrfs_fs(void) err =extent_io_init ();if (err) goto free_cachep; - - err =extent_state_cache_init (); + err =btrfs_read_repair_init ();if (err) goto free_extent_io; + err =extent_state_cache_init (); +if (err) + goto free_read_repair; err =extent_map_init ();if (err)
@@ -2706,6 +2709,8 @@ static int __init init_btrfs_fs(void)extent_map_exit (); free_extent_state_cache:extent_state_cache_exit (); +free_read_repair: +btrfs_read_repair_exit (); free_extent_io:extent_io_exit (); free_cachep:
Signature · 1 line
2.30.2
PATCH 6/9 btrfs: use the new read repair code for direct I/O
In reply to Christoph HellwigRewrite btrfs_check_read_dio_bio to use btrfs_bio_for_each_sector and start/end a repair session as needed.
--- fs/btrfs/inode.c | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-)
fs/btrfs/inode.c +10 -30
@@ -55,6 +55,7 @@#include "zoned.h" #include "subpage.h" #include "inode-item.h" +#include "read-repair.h" struct btrfs_iget_args {u64 ino;
@@ -7853,55 +7854,34 @@ static void btrfs_dio_private_put(struct btrfs_dio_private *dip)bio_endio (&dip->bio); } -static void submit_dio_repair_bio (struct inode *inode,struct bio *bio, -int mirror_num, -enum btrfs_compression_type compress_type) -{ -struct btrfs_dio_private *dip = bio->bi_private; -struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); - -BUG_ON (bio_op (bio) ==REQ_OP_WRITE ); - -refcount_inc (&dip->refs); -if (btrfs_map_bio (fs_info, bio, mirror_num)) -refcount_dec (&dip->refs); -} -static blk_status_t btrfs_check_read_dio_bio (struct btrfs_dio_private *dip,struct btrfs_bio *bbio,const bool uptodate) {struct inode *inode = dip->inode;struct btrfs_fs_info *fs_info =BTRFS_I (inode)->root->fs_info; -struct extent_io_tree *failure_tree = &BTRFS_I (inode)->io_failure_tree; -struct extent_io_tree *io_tree = &BTRFS_I (inode)->io_tree;const bool csum = !(BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM ); +struct btrfs_read_repair rr = { };blk_status_t err =BLK_STS_OK ;struct bvec_iter iter;struct bio_vec bv;u32 offset;btrfs_bio_for_each_sector (fs_info, bv, bbio, iter, offset) { -u64 start = bbio->file_offset + offset; -if (uptodate && (!csum || !check_data_csum (inode, bbio, offset, bv.bv_page, - bv.bv_offset, start))) { -clean_io_failure (fs_info, failure_tree, io_tree, start, - bv.bv_page,btrfs_ino (BTRFS_I (inode)), - bv.bv_offset); + bv.bv_offset, bbio->file_offset + offset))) { +if (!btrfs_read_repair_finish (&rr, bbio, inode, offset, +NULL )) + err =BLK_STS_IOERR ; }else { -int ret; - - ret =btrfs_repair_one_sector (inode, &bbio->bio, offset, - bv.bv_page, bv.bv_offset, start, - bbio->mirror_num, - submit_dio_repair_bio); -if (ret) - err =errno_to_blk_status (ret); +if (!btrfs_read_repair_add (&rr, bbio, inode, offset)) + err =BLK_STS_IOERR ; } } +if (!btrfs_read_repair_finish (&rr, bbio, inode, offset,NULL )) + err =BLK_STS_IOERR ;return err; }
Signature · 1 line
2.30.2
PATCH 7/9 btrfs: use the new read repair code for buffered reads
In reply to Christoph HellwigStart/end a repair session as needed in end_bio_extent_readpage and submit_data_read_repair. Unlike direct I/O, the buffered I/O handler completes I/O on a per-sector basis and thus needs to pass an endio handler to the repair code, which unlocks all pages and marks them as either uptodate or not.
--- fs/btrfs/extent_io.c | 76 ++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 41 deletions(-)
fs/btrfs/extent_io.c +35 -41
@@ -30,6 +30,7 @@#include "zoned.h" #include "block-group.h" #include "compression.h" +#include "read-repair.h" static struct kmem_cache *extent_state_cache;static struct kmem_cache *extent_buffer_cache;
@@ -2683,14 +2684,29 @@ static void end_sector_io(struct page *page, u64 offset, bool uptodate) offset + sectorsize - 1, &cached); } +static void end_read_repair (struct btrfs_bio *repair_bbio,struct inode *inode, +bool uptodate) +{ +struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +struct bvec_iter iter; +struct bio_vec bv; +u32 offset; + +btrfs_bio_for_each_sector (fs_info, bv, repair_bbio, iter, offset) +end_sector_io (bv.bv_page, repair_bbio->file_offset + offset, + uptodate); +} +static void submit_data_read_repair (struct inode *inode,struct bio *failed_bio,u32 bio_offset,const struct bio_vec *bvec, -int failed_mirror,unsigned int error_bitmap) +int failed_mirror, +unsigned int error_bitmap, +struct btrfs_read_repair *rr) { -const unsigned int pgoff = bvec->bv_offset; +struct btrfs_bio *failed_bbio =btrfs_bio (failed_bio);struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +u64 start =page_offset (bvec->bv_page) + bvec->bv_offset;struct page *page = bvec->bv_page; -const u64 start =page_offset (bvec->bv_page) + bvec->bv_offset;const u64 end = start + bvec->bv_len -1 ;const u32 sectorsize = fs_info->sectorsize;const int nr_bits = (end +1 - start) >> fs_info->sectorsize_bits;
@@ -2712,38 +2728,17 @@ static void submit_data_read_repair(struct inode *inode, struct bio *failed_bio,/* Iterate through all the sectors in the range */ for (i =0 ; i < nr_bits; i++) { -const unsigned int offset = i * sectorsize; -bool uptodate = false; -int ret; - -if (!(error_bitmap & (1U << i))) { -/* -* This sector has no error, just end the page read -* and unlock the range. -*/ - uptodate = true; - goto next; +bool uptodate = !(error_bitmap & (1U << i)); + +if (uptodate || + !btrfs_read_repair_add (rr, failed_bbio, inode, + bio_offset)) { +btrfs_read_repair_finish (rr, failed_bbio, inode, + bio_offset, end_read_repair); +end_sector_io (page, start, uptodate); } - - ret =btrfs_repair_one_sector (inode, failed_bio, - bio_offset + offset, - page, pgoff + offset, start + offset, - failed_mirror, btrfs_submit_data_read_bio); -if (!ret) { -/* -* We have submitted the read repair, the page release -* will be handled by the endio function of the -* submitted repair bio. -* Thus we don't need to do any thing here. -*/ -continue ; - } -/* -* Continue on failed repair, otherwise the remaining sectors -* will not be properly unlocked. -*/ -next: -end_sector_io (page, start + offset, uptodate); + bio_offset += sectorsize; + start += sectorsize; } }
@@ -2954,8 +2949,6 @@ static void end_bio_extent_readpage(struct bio *bio)struct bio_vec *bvec;struct btrfs_bio *bbio =btrfs_bio (bio);int mirror = bbio->mirror_num; -struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree; -struct extent_io_tree *failure_tree = &BTRFS_I (inode)->io_failure_tree;bool uptodate = !bio->bi_status;struct processed_extent processed = {0 };/*
@@ -2964,6 +2957,7 @@ static void end_bio_extent_readpage(struct bio *bio)*/ u32 bio_offset =0 ;struct bvec_iter_all iter_all; +struct btrfs_read_repair rr = { };btrfs_bio (bio)->file_offset =page_offset (first_vec->bv_page) + first_vec->bv_offset;
@@ -3020,10 +3014,6 @@ static void end_bio_extent_readpage(struct bio *bio)loff_t i_size =i_size_read (inode);pgoff_t end_index = i_size >>PAGE_SHIFT ; -clean_io_failure (BTRFS_I (inode)->root->fs_info, - failure_tree, tree, start, page, -btrfs_ino (BTRFS_I (inode)),0 ); -/* * Zero out the remaining part if this range straddles * i_size.
@@ -3063,9 +3053,11 @@ static void end_bio_extent_readpage(struct bio *bio)* and bad sectors, we just continue to the next bvec. */ submit_data_read_repair (inode, bio, bio_offset, bvec, - mirror, error_bitmap); + mirror, error_bitmap, &rr); }else {/* Update page status and unlock */ +btrfs_read_repair_finish (&rr,btrfs_bio (bio), inode, + bio_offset, end_read_repair);end_page_read (page, uptodate, start, len);endio_readpage_release_extent (&processed,BTRFS_I (inode), start, end,PageUptodate (page));
@@ -3076,6 +3068,8 @@ static void end_bio_extent_readpage(struct bio *bio) }/* Release the last extent */ +btrfs_read_repair_finish (&rr,btrfs_bio (bio), inode, bio_offset, + end_read_repair);endio_readpage_release_extent (&processed,NULL ,0 ,0 , false);btrfs_bio_free_csum (bbio);bio_put (bio);
Signature · 1 line
2.30.2
Re: [PATCH 7/9] btrfs: use the new read repair code for buffered reads
Quoted 147 lines · Christoph Hellwig
Start/end a repair session as needed in
end_bio_extent_readpageandsubmit_data_read_repair. Unlike direct I/O, the buffered I/O handler completes I/O on a per-sector basis and thus needs to pass an endio handler to the repair code, which unlocks all pages and marks them as either uptodate or not.Signed-off-by Christoph Hellwig <[email protected]>--- fs/btrfs/extent_io.c | 76 ++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 41 deletions(-)fs/btrfs/extent_io.c +33
-41@@ -30,6 +30,7 @@#include "zoned.h" #include "block-group.h" #include "compression.h" +#include "read-repair.h" static struct kmem_cache *extent_state_cache;static struct kmem_cache *extent_buffer_cache;@@ -2683,14 +2684,29 @@ static void end_sector_io(struct page *page, u64 offset, bool uptodate) offset + sectorsize - 1, &cached); } +static void end_read_repair (struct btrfs_bio *repair_bbio,struct inode *inode, +bool uptodate) +{ +struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +struct bvec_iter iter; +struct bio_vec bv; +u32 offset; + +btrfs_bio_for_each_sector (fs_info, bv, repair_bbio, iter, offset) +end_sector_io (bv.bv_page, repair_bbio->file_offset + offset, + uptodate); +} +static void submit_data_read_repair (struct inode *inode,struct bio *failed_bio,u32 bio_offset,const struct bio_vec *bvec, -int failed_mirror,unsigned int error_bitmap) +int failed_mirror, +unsigned int error_bitmap, +struct btrfs_read_repair *rr) { -const unsigned int pgoff = bvec->bv_offset; +struct btrfs_bio *failed_bbio =btrfs_bio (failed_bio);struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +u64 start =page_offset (bvec->bv_page) + bvec->bv_offset;struct page *page = bvec->bv_page; -const u64 start =page_offset (bvec->bv_page) + bvec->bv_offset;const u64 end = start + bvec->bv_len -1 ;const u32 sectorsize = fs_info->sectorsize;const int nr_bits = (end +1 - start) >> fs_info->sectorsize_bits;@@ -2712,38 +2728,17 @@ static void submit_data_read_repair(struct inode *inode, struct bio *failed_bio,/* Iterate through all the sectors in the range */ for (i =0 ; i < nr_bits; i++) { -const unsigned int offset = i * sectorsize; -bool uptodate = false; -int ret; - -if (!(error_bitmap & (1U << i))) { -/* -* This sector has no error, just end the page read -* and unlock the range. -*/ - uptodate = true; - goto next; +bool uptodate = !(error_bitmap & (1U << i)); + +if (uptodate || + !btrfs_read_repair_add (rr, failed_bbio, inode, + bio_offset)) { +btrfs_read_repair_finish (rr, failed_bbio, inode, + bio_offset, end_read_repair); +end_sector_io (page, start, uptodate); } - - ret =btrfs_repair_one_sector (inode, failed_bio, - bio_offset + offset, - page, pgoff + offset, start + offset, - failed_mirror, btrfs_submit_data_read_bio); -if (!ret) { -/* -* We have submitted the read repair, the page release -* will be handled by the endio function of the -* submitted repair bio. -* Thus we don't need to do any thing here. -*/ -continue ; - } -/* -* Continue on failed repair, otherwise the remaining sectors -* will not be properly unlocked. -*/ -next: -end_sector_io (page, start + offset, uptodate); + bio_offset += sectorsize; + start += sectorsize; } }@@ -2954,8 +2949,6 @@ static void end_bio_extent_readpage(struct bio *bio)struct bio_vec *bvec;struct btrfs_bio *bbio =btrfs_bio (bio);int mirror = bbio->mirror_num; -struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree; -struct extent_io_tree *failure_tree = &BTRFS_I (inode)->io_failure_tree;bool uptodate = !bio->bi_status;struct processed_extent processed = {0 };/* @@ -2964,6 +2957,7 @@ static void end_bio_extent_readpage(struct bio *bio)*/ u32 bio_offset =0 ;struct bvec_iter_all iter_all; +struct btrfs_read_repair rr = { };btrfs_bio (bio)->file_offset =page_offset (first_vec->bv_page) + first_vec->bv_offset;@@ -3020,10 +3014,6 @@ static void end_bio_extent_readpage(struct bio *bio)loff_t i_size =i_size_read (inode);pgoff_t end_index = i_size >>PAGE_SHIFT ; -clean_io_failure (BTRFS_I (inode)->root->fs_info, - failure_tree, tree, start, page, -btrfs_ino (BTRFS_I (inode)),0 ); -/* * Zero out the remaining part if this range straddles * i_size. @@ -3063,9 +3053,11 @@ static void end_bio_extent_readpage(struct bio *bio)* and bad sectors, we just continue to the next bvec. */ submit_data_read_repair (inode, bio, bio_offset, bvec, - mirror, error_bitmap); + mirror, error_bitmap, &rr); }else {/* Update page status and unlock */ +btrfs_read_repair_finish (&rr,btrfs_bio (bio), inode, + bio_offset, end_read_repair);end_page_read (page, uptodate, start, len);endio_readpage_release_extent (&processed,BTRFS_I (inode), start, end,PageUptodate (page));
fs/btrfs/extent_io.c static void end_bio_extent_readpage(struct bio *bio) · line 3072
Quoted 5 lines
fs/btrfs/extent_io.c +2
-0@@ -3076,6 +3068,8 @@ static void end_bio_extent_readpage(struct bio *bio) }/* Release the last extent */ +btrfs_read_repair_finish (&rr,btrfs_bio (bio), inode, bio_offset, + end_read_repair);
This part is wrong, it's leading to BUG_ON(!locked_page(page)) when we do the end_io. We're essentially read_repair_finish for a page that is outside of our bio. The continuous testing caught this last week but I didn't notice it until yesterday. I pulled this part out and now btrfs/101 runs without panicing. Thanks,
Josef
PATCH 8/9 btrfs: remove io_failure_record infrastructure completely
In reply to Christoph HellwigFrom: Qu Wenruo <[email protected]>
Since our read repair are always handled by btrfs_read_repair_ctrl, which only has the lifespan inside endio function.
This means we no longer needs to record which range and its mirror number for failure.
Now if we failed to read some data page, we have already tried every mirrors we have, thus no need to record the failed range.
Thus this patch can remove the whole io_failure_record structure and its related functions.
--- fs/btrfs/btrfs_inode.h | 5 - fs/btrfs/extent-io-tree.h | 15 -- fs/btrfs/extent_io.c | 365 ----------------------------------- fs/btrfs/extent_io.h | 25 --- fs/btrfs/inode.c | 7 - include/trace/events/btrfs.h | 1 - 6 files changed, 418 deletions(-)
fs/btrfs/btrfs_inode.h +0 -5
@@ -91,11 +91,6 @@ struct btrfs_inode {/* the io_tree does range state (DIRTY, LOCKED etc) */ struct extent_io_tree io_tree; -/* special utility tree used to record which mirrors have already been -* tried when checksums fail for a given block -*/ -struct extent_io_tree io_failure_tree; -/* * Keep track of where the inode has extent items mapped in order to * make sure the i_size adjustments are accurate
fs/btrfs/extent-io-tree.h +0 -15
@@ -56,7 +56,6 @@ enum {IO_TREE_FS_EXCLUDED_EXTENTS ,IO_TREE_BTREE_INODE_IO ,IO_TREE_INODE_IO , -IO_TREE_INODE_IO_FAILURE ,IO_TREE_RELOC_BLOCKS ,IO_TREE_TRANS_DIRTY_PAGES , IO_TREE_ROOT_DIRTY_LOG_PAGES,
@@ -250,18 +249,4 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, u64 *end, u64 max_bytes, struct extent_state **cached_state); -/* This should be reworked in the future and put elsewhere. */ -struct io_failure_record *get_state_failrec (struct extent_io_tree *tree,u64 start); -int set_state_failrec (struct extent_io_tree *tree,u64 start, -struct io_failure_record *failrec); -void btrfs_free_io_failure_record (struct btrfs_inode *inode,u64 start, -u64 end); -int free_io_failure (struct extent_io_tree *failure_tree, -struct extent_io_tree *io_tree, -struct io_failure_record *rec); -int clean_io_failure (struct btrfs_fs_info *fs_info, -struct extent_io_tree *failure_tree, -struct extent_io_tree *io_tree,u64 start, -struct page *page,u64 ino,unsigned int pg_offset); -#endif /* BTRFS_EXTENT_IO_TREE_H */
fs/btrfs/extent_io.c +0 -365
383 lines not on this page · raw message
fs/btrfs/extent_io.h +0 -25
@@ -61,7 +61,6 @@ struct btrfs_root;struct btrfs_inode ;struct btrfs_io_bio ;struct btrfs_fs_info ; -struct io_failure_record ;struct extent_io_tree ; typedef void (submit_bio_hook_t)(struct inode *inode, struct bio *bio,
@@ -252,30 +251,6 @@ struct bio *btrfs_bio_clone_partial(struct bio *orig, u64 offset, u64 size);void end_extent_writepage (struct page *page,int err,u64 start,u64 end);int btrfs_repair_eb_io_failure (const struct extent_buffer *eb,int mirror_num); -/* -* When IO fails, either with EIO or csum verification fails, we -* try other mirrors that might have a good copy of the data. This -* io_failure_record is used to record state as we go through all the -* mirrors. If another mirror has good data, the sector is set up to date -* and things continue. If a good mirror can't be found, the original -* bio end_io callback is called to indicate things have failed. -*/ -struct io_failure_record { -struct page *page; -u64 start; -u64 len; -u64 logical; -enum btrfs_compression_type compress_type; -int this_mirror; -int failed_mirror; -}; - -int btrfs_repair_one_sector (struct inode *inode, -struct bio *failed_bio,u32 bio_offset, -struct page *page,unsigned int pgoff, -u64 start,int failed_mirror, -submit_bio_hook_t *submit_bio_hook); -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS bool find_lock_delalloc_range(struct inode *inode, struct page *locked_page, u64 *start,
fs/btrfs/inode.c +0 -7
@@ -3133,8 +3133,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) ordered_extent->disk_num_bytes); } -btrfs_free_io_failure_record (inode, start, end); -if (test_bit (BTRFS_ORDERED_TRUNCATED , &ordered_extent->flags)) { truncated = true; logical_len = ordered_extent->truncated_len;
@@ -5345,8 +5343,6 @@ void btrfs_evict_inode(struct inode *inode)if (is_bad_inode (inode)) goto no_delete; -btrfs_free_io_failure_record (BTRFS_I (inode),0 , (u64)-1 ); -if (test_bit (BTRFS_FS_LOG_RECOVERING , &fs_info->flags)) goto no_delete;
@@ -8818,12 +8814,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) inode = &ei->vfs_inode;extent_map_tree_init (&ei->extent_tree);extent_io_tree_init (fs_info, &ei->io_tree,IO_TREE_INODE_IO , inode); -extent_io_tree_init (fs_info, &ei->io_failure_tree, -IO_TREE_INODE_IO_FAILURE , inode);extent_io_tree_init (fs_info, &ei->file_extent_tree,IO_TREE_INODE_FILE_EXTENT , inode); ei->io_tree.track_uptodate = true; - ei->io_failure_tree.track_uptodate = true;atomic_set (&ei->sync_writers,0 );mutex_init (&ei->log_mutex);btrfs_ordered_inode_tree_init (&ei->ordered_tree);
include/trace/events/btrfs.h +0 -1
@@ -82,7 +82,6 @@ struct btrfs_space_info; EM( IO_TREE_FS_EXCLUDED_EXTENTS, "EXCLUDED_EXTENTS") \ EM( IO_TREE_BTREE_INODE_IO, "BTREE_INODE_IO") \ EM( IO_TREE_INODE_IO, "INODE_IO") \ - EM( IO_TREE_INODE_IO_FAILURE, "INODE_IO_FAILURE") \ EM( IO_TREE_RELOC_BLOCKS, "RELOC_BLOCKS") \ EM( IO_TREE_TRANS_DIRTY_PAGES, "TRANS_DIRTY_PAGES") \EM (IO_TREE_ROOT_DIRTY_LOG_PAGES ,"ROOT_DIRTY_LOG_PAGES" ) \
Signature · 1 line
2.30.2
PATCH 9/9 btrfs: fold repair_io_failure into btrfs_repair_eb_io_failure
In reply to Christoph HellwigFold repair_io_failure into the only remaining caller.
This is still inefficient with single page I/Os, but I have some ideas on how to improve the metadata repair in the future.
--- fs/btrfs/extent_io.c | 51 +++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 34 deletions(-)
fs/btrfs/extent_io.c +17 -34
@@ -2225,35 +2225,6 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,return bitset; } -static int repair_io_failure (struct btrfs_fs_info *fs_info,u64 ino,u64 start, -u64 length,u64 logical,struct page *page, -unsigned int pg_offset,int mirror_num) -{ -struct bio_vec bvec; -struct bio bio; -int ret; - -ASSERT (!(fs_info->sb->s_flags &SB_RDONLY )); -BUG_ON (!mirror_num); - -if (btrfs_repair_one_zone (fs_info, logical)) -return 0 ; - -bio_init (&bio,NULL , &bvec,1 ,REQ_OP_WRITE |REQ_SYNC ); - bio.bi_iter.bi_sector = logical >>9 ; -__bio_add_page (&bio, page, length, pg_offset); - ret =btrfs_map_repair_bio (fs_info, &bio, mirror_num); -bio_uninit (&bio); - -if (ret) -return ret; - -btrfs_info_rl_in_rcu (fs_info, -"read error corrected: ino %llu off %llu (logical %llu)" , - ino, start, logical); -return 0 ; -} -int btrfs_repair_eb_io_failure (const struct extent_buffer *eb,int mirror_num) {struct btrfs_fs_info *fs_info = eb->fs_info;
@@ -2261,20 +2232,32 @@ int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num)int i, num_pages =num_extent_pages (eb);int ret =0 ; +WARN_ON_ONCE (!mirror_num); +if (sb_rdonly (fs_info->sb))return -EROFS ; +if (btrfs_repair_one_zone (fs_info, eb->start)) +return 0 ; +for (i =0 ; i < num_pages; i++) {struct page *p = eb->pages[i]; +struct bio_vec bvec; +struct bio bio; + +bio_init (&bio,NULL , &bvec,1 ,REQ_OP_WRITE |REQ_SYNC ); + bio.bi_iter.bi_sector = start >>9 ; +__bio_add_page (&bio, p,PAGE_SIZE , start -page_offset (p)); + ret =btrfs_map_repair_bio (fs_info, &bio, mirror_num); +bio_uninit (&bio); - ret =repair_io_failure (fs_info,0 , start,PAGE_SIZE , start, p, - start -page_offset (p), mirror_num);if (ret) -break ; - start +=PAGE_SIZE ; +return ret; } -return ret; +btrfs_info_rl_in_rcu (fs_info, +"metadata read error corrected: logical %llu." , eb->start); +return 0 ; }static void end_page_read (struct page *page,bool uptodate,u64 start,u32 len)
Signature · 1 line
2.30.2
Quoted 24 lines · Christoph Hellwig
Hi all,
this is my take on the read repair code. It borrow a lot of concepts and patches from Qu's attempt. The big difference is that it does away with multiple in-flight repair bios, but instead just does one at a time, but tries to make it as big as possible.
My aim here is mostly to fix up the messy I/O completions for the direct I/O path, that make further bio optimizations rather annoying, but it also gives better I/O patterns for repair (although I'm not sure anyone cares) and removes a fair chunk of code.
[this is on top of a not commit yet series. I kinda hate doing that, but
with all the hot repair discussion going on right now we might as well have an uptodate version of this series out on the list]Git tree:
git://git.infradead.org/users/hch/misc.gitbtrfs-read_repairGitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/btrfs-read_repair
Quoted 8 lines
Changes since v1:
- rebased on top of the "misc btrfs cleanups" series that contains various patches previously in this series and the "cleanup btrfs bio handling, part 2 v4" series
- handle partial reads due to checksum failures
- handle large I/O for parity RAID repair as well
- add a lot more comments
- renamebtrfs_read_repair_endtobtrfs_read_repair_finish
The preparatory patches and other bio patches are now in misc-next, so I'm adding this branch for-next. At this point I'm cosidering this for merge as it has better performance compared to the simple repair from Qu, though I still need some time to finish the review.
Quoted 34 lines · David Sterba
Quoted 24 lines · Christoph Hellwig
Hi all,
this is my take on the read repair code. It borrow a lot of concepts and patches from Qu's attempt. The big difference is that it does away with multiple in-flight repair bios, but instead just does one at a time, but tries to make it as big as possible.
My aim here is mostly to fix up the messy I/O completions for the direct I/O path, that make further bio optimizations rather annoying, but it also gives better I/O patterns for repair (although I'm not sure anyone cares) and removes a fair chunk of code.
[this is on top of a not commit yet series. I kinda hate doing that, but
with all the hot repair discussion going on right now we might as well have an uptodate version of this series out on the list]Git tree:
git://git.infradead.org/users/hch/misc.gitbtrfs-read_repairGitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/btrfs-read_repair
Quoted 8 lines
Changes since v1:
- rebased on top of the "misc btrfs cleanups" series that contains various patches previously in this series and the "cleanup btrfs bio handling, part 2 v4" series
- handle partial reads due to checksum failures
- handle large I/O for parity RAID repair as well
- add a lot more comments
- renamebtrfs_read_repair_endtobtrfs_read_repair_finish
Quoted 4 lines
The preparatory patches and other bio patches are now in misc-next, so I'm adding this branch for-next. At this point I'm cosidering this for merge as it has better performance compared to the simple repair from Qu, though I still need some time to finish the review.
OK, although I'd say, considering the latest read-repair test, we may want to simply the write part, to only write the data back to the initial mirror.
Thanks,
Qu
Quoted 1 line · Qu Wenruo
OK, although I'd say, considering the latest read-repair test,
What is the latest read repair test?
Quoted 3 lines
we may
want to simply the write part, to only write the data back to the initial mirror.
Why would we not write back the correct data to all known bad mirrors?
Quoted 4 lines · Christoph Hellwig
Quoted 1 line · Qu Wenruo
OK, although I'd say, considering the latest read-repair test,
What is the latest read repair test?
IIRC some RAID1C3 cases like:
https://patchwork.kernel.org/project/linux-btrfs/patch/[email protected]/
As currently, we only write the recovered data back to *previous* corrupted mirror, it doesn't ensure our initial mirror get repaired.
Quoted 6 lines
Quoted 4 lines
we may
want to simply the write part, to only write the data back to the initial mirror.Why would we not write back the correct data to all known bad mirrors?
Because then you also need to record which mirrors are bad.
I doubt you want to bring a more complex version to write back to all corrupted copies.
And in fact, only writing back to the initial mirror is also going to make recovery faster and easier, as now we only need to do one synchronous writeback.
Thanks,
Qu
Quoted 2 lines · Qu Wenruo
As currently, we only write the recovered data back to *previous* corrupted mirror, it doesn't ensure our initial mirror get repaired.
Yes. So it leaves the file system in a degraded state and reduces redundancy.
Quoted 3 lines
And in fact, only writing back to the initial mirror is also going to make recovery faster and easier, as now we only need to do one synchronous writeback.
It does make recovery faster by not doing most of it. By that logic we should stop repairing in the I/O path at all. Which, thinking about it, might actually not be a bad idea. Instead of doing synchronous repair from the I/O path, just serve the actual I/O with reads and instead kick of a background scrub process to fix it. This removes code duplication between read repair and scrub, speeds up the reads themselves, including reducing the amount of I/O we might be doing under memory pressure and allows the scrube code to actually do the right thing everywhere, including rebuilding parity in the RAID6 case, something that the read repair (both old and new) do not handle at all.
Quoted 11 lines · Christoph Hellwig
Quoted 2 lines · Qu Wenruo
As currently, we only write the recovered data back to *previous* corrupted mirror, it doesn't ensure our initial mirror get repaired.
Yes. So it leaves the file system in a degraded state and reduces redundancy.
Quoted 3 lines
And in fact, only writing back to the initial mirror is also going to make recovery faster and easier, as now we only need to do one synchronous writeback.
Quoted 5 lines
It does make recovery faster by not doing most of it. By that logic we should stop repairing in the I/O path at all. Which, thinking about it, might actually not be a bad idea. Instead of doing synchronous repair from the I/O path, just serve the actual I/O with reads and instead kick of a background scrub process to fix it.
That has its own problem, mostly due to the lack of granularity from scrub.
Currently scrub can only work at a device level, which means we need to scrub the whole device just for several corrupted sectors.
I got your point, but unfortunately unless we greatly enhanced the granularity of scrub, it's not yet feasible for now, thus I'm afraid we have to go the current path for near future.
I totally understand there are tons of scrub related code needs to be improved, from the damn stupid multiple devices scrubbing method to how to handle RAID56 scrub better.
And that would be my next main target, as it is the basis for mount time scrub (thus for write-intent bitmap tree).
Quoted 8 lines
This removes code
duplication between read repair and scrub, speeds up the reads themselves, including reducing the amount of I/O we might be doing under memory pressure and allows the scrube code to actually do the right thing everywhere, including rebuilding parity in the RAID6 case, something that the read repair (both old and new) do not handle at all.
Yep, for RAID56 it's always a pain in the backend.
But let's focus on traditional mirror based ones for now, and I still think just writing back the initial mirror is not a bad idea for this particular case.
Another alternative is to write back the recovered data back to any corrupted mirrors asynchronously.
(This means more complex code though)
For the existing at most 2 mirrors profiles (DUP,RAID1,RAID10), this is no different than the existing behavior anyway.
For RAID1C3/C4, those two profiles are new profiles (which we didn't really test read-repair that well).
Defining a better and determining behavior is what we should do when introducing those two profiles.
Thanks,
Qu