Skip to contentSkip to conversation

btrfs: don't take a bio_counter reference for cloned bios

PATCH In review Christoph Hellwig 2 participants 3 messages Jun 25, 2022 – Jul 5, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: don't take a bio_counter reference for cloned bios

There is no need for multiple bio_counter references for a single I/O. Just release the reference when completing the bio and avoid additional counter roundtrips.

---

This is against the for-next branch as it is a follow up the review feeback to the "cleanup btrfs bio submission v2" series.

 fs/btrfs/ctree.h       | 1 -
 fs/btrfs/dev-replace.c | 5 -----
 fs/btrfs/volumes.c     | 6 +-----
 3 files changed, 1 insertion(+), 11 deletions(-)
fs/btrfs/ctree.h +0 -1
index 4e2569f84aabc..ad15c0c602a61 100644
@@ -3987,7 +3987,6 @@ static inline void btrfs_init_full_stripe_locks_tree(
 
 /* dev-replace.c */
 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info);
-void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info);
 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount);
 
 static inline void btrfs_bio_counter_dec(struct btrfs_fs_info *fs_info)
fs/btrfs/dev-replace.c +0 -5
index a7dd6ba25e990..aa435d04e8ef3 100644
@@ -1288,11 +1288,6 @@ int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace)
 	return 1;
 }
 
-void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info)
-{
-	percpu_counter_inc(&fs_info->dev_replace.bio_counter);
-}
-
 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount)
 {
 	percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount);
fs/btrfs/volumes.c +1 -5
index 6aa6bc769569a..207e136d1a721 100644
@@ -6647,8 +6647,6 @@ static void btrfs_end_bio(struct bio *bio)
 		}
 	}
 
-	btrfs_bio_counter_dec(bioc->fs_info);
-
 	if (bio != orig_bio) {
 		bio_endio(orig_bio);
 		bio_put(bio);
@@ -6664,6 +6662,7 @@ static void btrfs_end_bio(struct bio *bio)
 	else
 		orig_bio->bi_status = BLK_STS_OK;
 
+	btrfs_bio_counter_dec(bioc->fs_info);
 	bbio->mirror_num = bioc->mirror_num;
 	orig_bio->bi_end_io = bioc->end_io;
 	orig_bio->bi_private = bioc->private;
@@ -6698,8 +6697,6 @@ static void submit_stripe_bio(struct btrfs_io_context *bioc,
 	bio->bi_end_io = btrfs_end_bio;
 	bio->bi_iter.bi_sector = physical >> 9;
 
-	btrfs_bio_counter_inc_noblocked(fs_info);
-
 	if (!dev || !dev->bdev ||
 	    test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) ||
 	    (btrfs_op(bio) == BTRFS_MAP_WRITE &&
@@ -6780,7 +6777,6 @@ void btrfs_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, int mirror
 
 		submit_stripe_bio(bioc, bio, dev_nr, should_clone);
 	}
-	btrfs_bio_counter_dec(fs_info);
 }
 
 static bool dev_args_match_fs_devices(const struct btrfs_dev_lookup_args *args,
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Christoph Hellwig

There is no need for multiple bio_counter references for a single I/O. Just release the reference when completing the bio and avoid additional counter roundtrips.

Though this doesn't apply cleanly on current misc-next so had to manually clean it up. Also the changelog is somewhat terse essentially the block count is now being "carried" by the top-level bio or rather the bio_io_context since btrfs_bio_counter_dec() call shall be moved into btrfs_end_bioc.

#2 lore raw
Quoted 2 lines · Nikolay Borisov

Though this doesn't apply cleanly on current misc-next so had to manually clean it up.

This applies against the for-next branch fine, which still has a big chunk of bio related patches in it that didn't make it to misc-next.

Quoted 4 lines

Also the changelog is somewhat terse essentially the block count is now being "carried" by the top-level bio or rather the bio_io_context since btrfs_bio_counter_dec() call shall be moved into btrfs_end_bioc.

btrfs_end_bioc is gone in for-next.