block: fix bio chaining in blk_next_bio()
PATCH 1/1 block: fix bio chaining in blk_next_bio()
While it seems to have worked for so long, it doesn't seem right that we set the new bio as the parent. bio_chain() seems to be used in the other way everywhere else anyway.
--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-lib.c +1 -1
@@ -15,7 +15,7 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)struct bio *new =bio_alloc (gfp, nr_pages);if (bio) { -bio_chain (bio, new); +bio_chain (new, bio);submit_bio (bio); }
Signature · 1 line
2.29.2
Quoted 15 lines · Tom Yan
While it seems to have worked for so long, it doesn't seem right that we set the new bio as the parent.
bio_chain()seems to be used in the other way everywhere else anyway.Signed-off-by Tom Yan <[email protected]>--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-lib.c +0
-0
block/blk-lib.c struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) · line 21
Quoted 8 lines
block/blk-lib.c +1
-1@@ -15,7 +15,7 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)struct bio *new =bio_alloc (gfp, nr_pages);if (bio) { -bio_chain (bio, new); +bio_chain (new, bio);submit_bio (bio); }
I don't think this is correct.
This code is submitting the original bio, and we _want_ to keep the newly allocated one even though the original might have been completed already. If we were setting the 'parent' to the original bio upper layers might infer that the entire request has been completed (as the original bio is now the 'parent' bio), which is patently not true.
So, rather not.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
I still don't think this sounds right.
See the definition of bio_chain():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/block/bio.c?h=v5.10-rc6#n344
And in turn bio_inc_remaining():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/bio.h?h=v5.10-rc6#n667
With the current blk_next_bio(), the first bio will never even be handled by bio_chain()/bio_inc_remaining()/bio_set_flag(bio, BIO_CHAIN). When the first submit_bio() is called, it won't have any idea that the next/new bio exists. What you said actually sounds a bit like the current situation.
Quoted 42 lines · Hannes Reinecke
Quoted 15 lines · Tom Yan
While it seems to have worked for so long, it doesn't seem right that we set the new bio as the parent.
bio_chain()seems to be used in the other way everywhere else anyway.Signed-off-by Tom Yan <[email protected]>--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-lib.c +0
-0block/blk-lib.c struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) · line 21
Quoted 8 lines
block/blk-lib.c +1
-1@@ -15,7 +15,7 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)struct bio *new =bio_alloc (gfp, nr_pages);if (bio) { -bio_chain (bio, new); +bio_chain (new, bio);submit_bio (bio); }I don't think this is correct.
This code is submitting the original bio, and we _want_ to keep the newly allocated one even though the original might have been completed already. If we were setting the 'parent' to the original bio upper layers might infer that the entire request has been completed (as the original bio is now the 'parent' bio), which is patently not true.So, rather not.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
[email protected] +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Also see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/block/bio.c?h=v5.10-rc6#n1384
btw. I really think the "new as parent" is a careless typo.
(Christoph?)
Quoted 58 lines · Tom Yan
I still don't think this sounds right.
See the definition of
bio_chain():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/block/bio.c?h=v5.10-rc6#n344And in turn
bio_inc_remaining():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/bio.h?h=v5.10-rc6#n667With the current
blk_next_bio(), the first bio will never even be handled by bio_chain()/bio_inc_remaining()/bio_set_flag(bio,BIO_CHAIN). When the firstsubmit_bio()is called, it won't have any idea that the next/new bio exists. What you said actually sounds a bit like the current situation.Quoted 42 lines · Hannes Reinecke
Quoted 15 lines · Tom Yan
While it seems to have worked for so long, it doesn't seem right that we set the new bio as the parent.
bio_chain()seems to be used in the other way everywhere else anyway.Signed-off-by Tom Yan <[email protected]>--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-lib.c +0
-0block/blk-lib.c struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) · line 21
Quoted 8 lines
block/blk-lib.c +1
-1@@ -15,7 +15,7 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)struct bio *new =bio_alloc (gfp, nr_pages);if (bio) { -bio_chain (bio, new); +bio_chain (new, bio);submit_bio (bio); }I don't think this is correct.
This code is submitting the original bio, and we _want_ to keep the newly allocated one even though the original might have been completed already. If we were setting the 'parent' to the original bio upper layers might infer that the entire request has been completed (as the original bio is now the 'parent' bio), which is patently not true.So, rather not.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
[email protected] +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Quoted 14 lines · Tom Yan
While it seems to have worked for so long, it doesn't seem right that we set the new bio as the parent.
bio_chain()seems to be used in the other way everywhere else anyway.Signed-off-by Tom Yan <[email protected]>--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-lib.c +0
-0
block/blk-lib.c struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) · line 20
Quoted 7 lines
block/blk-lib.c +1
-1@@ -15,7 +15,7 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)struct bio *new =bio_alloc (gfp, nr_pages);if (bio) { -bio_chain (bio, new); +bio_chain (new, bio);submit_bio (bio); }
This patch isn't needed. We simply wait for completion of the last issued bio, which .bi_end_io(submit_bio_wait_endio) is only called after all previous bios are done.
And the last bio is the ancestor of the whole chained bios, which are submitted in the following way(order):
bio 0 ---> bio 1 ---> ... -> bio N(the last bio)
thanks,
Ming
Are you saying that it would work either way?
Quoted 36 lines · Ming Lei
Quoted 14 lines · Tom Yan
While it seems to have worked for so long, it doesn't seem right that we set the new bio as the parent.
bio_chain()seems to be used in the other way everywhere else anyway.Signed-off-by Tom Yan <[email protected]>--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-lib.c +0
-0block/blk-lib.c struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) · line 20
Quoted 7 lines
block/blk-lib.c +1
-1@@ -15,7 +15,7 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)struct bio *new =bio_alloc (gfp, nr_pages);if (bio) { -bio_chain (bio, new); +bio_chain (new, bio);submit_bio (bio); }This patch isn't needed. We simply wait for completion of the last issued bio, which .bi_end_io(submit_bio_wait_endio) is only called after all previous bios are done.
And the last bio is the ancestor of the whole chained bios, which are submitted in the following way(order):
bio 0 ---> bio 1 ---> ... -> bio N(the last bio)thanks,
Ming
Quoted 1 line · Tom Yan
Are you saying that it would work either way?
Please don't do top reply which is hard to follow context.
Quoted 33 lines · Ming Lei
Quoted 31 lines · Tom Yan
Quoted 14 lines
While it seems to have worked for so long, it doesn't seem right that we set the new bio as the parent.
bio_chain()seems to be used in the other way everywhere else anyway.Signed-off-by Tom Yan <[email protected]>--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-lib.c +0
-0block/blk-lib.c struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) · line 20
Quoted 7 lines
block/blk-lib.c +1
-1@@ -15,7 +15,7 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)struct bio *new =bio_alloc (gfp, nr_pages);if (bio) { -bio_chain (bio, new); +bio_chain (new, bio);submit_bio (bio); }This patch isn't needed. We simply wait for completion of the last issued bio, which .bi_end_io(submit_bio_wait_endio) is only called after all previous bios are done.
And the last bio is the ancestor of the whole chained bios, which are submitted in the following way(order):
bio 0 ---> bio 1 ---> ... -> bio N(the last bio)
...
Quoted 2 lines
Are you saying that it would work either way?
No.
The current way of blk_next_bio() works just as expected, and your patch is actually wrong. Let's see one simple example, suppose one discard request is splitted into two bios(bio 0, and bio 1), after your patch is applied:
1) bio 0 becomes bio 1's parent, and bio 0 is submitted first
2) bio 1 is submitted finally via submit_bio_wait(), and bio 1's .bi_end_io/.bi_private is updated to submit_bio_wait_endio()/&done, so when bio 1 is completed, there isn't any way to know if bio 0 is completed, because the chain is cut by your patch.
Signature · 1 line
Ming