Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 9a42891

Browse files
YuKuai-huaweiaxboe
authored andcommitted
block: fix lost bio for plug enabled bio based device
With the following two conditions, bio will be lost: 1) blk plug is not enabled, for example, __blkdev_direct_IO_simple() and __blkdev_direct_IO_async(); 2) bio plug is enabled, for example write IO for raid1/raid10 while bitmap is enabled; Root cause is that blk_finish_plug() will add the bio to curent->bio_list, while such bio will not be handled: __submit_bio_noacct current->bio_list = bio_list_on_stack; blk_start_plug do { dm_submit_bio md_handle_request raid10_write_request -> generate new bio for underlying disks raid1_add_bio_to_plug -> bio is added to plug } while ((bio = bio_list_pop(&bio_list_on_stack[0]))) -> previous bio are all handled blk_finish_plug raid10_unplug raid1_submit_write submit_bio_noacct if (current->bio_list) bio_list_add(&current->bio_list[0], bio) -> add new bio current->bio_list = NULL -> new bio is lost Fix the problem by moving the plug into the while loop, so that current->bio_list will still be handled after blk_finish_plug(). By the way, enable plug for raid1/raid10 in this case will also prevent delay IO handling into daemon thread, which should also improve IO performance. Fixes: 060406c ("block: add plug while submitting IO") Reported-by: Changhui Zhong <czhong@redhat.com> Closes: https://lore.kernel.org/all/CAGVVp+Xsmzy2G9YuEatfMT6qv1M--YdOCQ0g7z7OVmcTbBxQAg@mail.gmail.com/ Signed-off-by: Yu Kuai <yukuai3@huawei.com> Tested-by: Changhui Zhong <czhong@redhat.com> Link: https://lore.kernel.org/r/20240521200308.983986-1-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f0eab3e commit 9a42891

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

block/blk-core.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,14 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q,
613613

614614
static void __submit_bio(struct bio *bio)
615615
{
616+
/* If plug is not used, add new plug here to cache nsecs time. */
617+
struct blk_plug plug;
618+
616619
if (unlikely(!blk_crypto_bio_prep(&bio)))
617620
return;
618621

622+
blk_start_plug(&plug);
623+
619624
if (!bio->bi_bdev->bd_has_submit_bio) {
620625
blk_mq_submit_bio(bio);
621626
} else if (likely(bio_queue_enter(bio) == 0)) {
@@ -624,6 +629,8 @@ static void __submit_bio(struct bio *bio)
624629
disk->fops->submit_bio(bio);
625630
blk_queue_exit(disk->queue);
626631
}
632+
633+
blk_finish_plug(&plug);
627634
}
628635

629636
/*
@@ -648,13 +655,11 @@ static void __submit_bio(struct bio *bio)
648655
static void __submit_bio_noacct(struct bio *bio)
649656
{
650657
struct bio_list bio_list_on_stack[2];
651-
struct blk_plug plug;
652658

653659
BUG_ON(bio->bi_next);
654660

655661
bio_list_init(&bio_list_on_stack[0]);
656662
current->bio_list = bio_list_on_stack;
657-
blk_start_plug(&plug);
658663

659664
do {
660665
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
@@ -688,23 +693,19 @@ static void __submit_bio_noacct(struct bio *bio)
688693
bio_list_merge(&bio_list_on_stack[0], &bio_list_on_stack[1]);
689694
} while ((bio = bio_list_pop(&bio_list_on_stack[0])));
690695

691-
blk_finish_plug(&plug);
692696
current->bio_list = NULL;
693697
}
694698

695699
static void __submit_bio_noacct_mq(struct bio *bio)
696700
{
697701
struct bio_list bio_list[2] = { };
698-
struct blk_plug plug;
699702

700703
current->bio_list = bio_list;
701-
blk_start_plug(&plug);
702704

703705
do {
704706
__submit_bio(bio);
705707
} while ((bio = bio_list_pop(&bio_list[0])));
706708

707-
blk_finish_plug(&plug);
708709
current->bio_list = NULL;
709710
}
710711

0 commit comments

Comments
 (0)