Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
On Tue, Jan 03 2017, Jack Wang wrote: > 2016-12-23 12:45 GMT+01:00 Lars Ellenberg: >> On Fri, Dec 23, 2016 at 09:49:53AM +0100, Michael Wang wrote: >>> Dear Maintainers >>> >>> I'd like to ask for the status of this patch since we hit the >>> issue too during our testing on md raid1. >>> >>> Split remainder bio_A was queued ahead, following by bio_B for >>> lower device, at this moment raid start freezing, the loop take >>> out bio_A firstly and deliver it, which will hung since raid is >>> freezing, while the freezing never end since it waiting for >>> bio_B to finish, and bio_B is still on the queue, waiting for >>> bio_A to finish... >>> >>> We're looking for a good solution and we found this patch >>> already progressed a lot, but we can't find it on linux-next, >>> so we'd like to ask are we still planning to have this fix >>> in upstream? >> >> I don't see why not, I'd even like to have it in older kernels, >> but did not have the time and energy to push it. >> >> Thanks for the bump. >> >> Lars >> > Hi folks, > > As Michael mentioned, we hit a bug this patch is trying to fix. > Neil suggested another way to fix it. I attached below. > I personal prefer Neil's version as it's less code change, and straight > forward. > > Could you share your comments, we can get one fix into mainline. > > Thanks, > Jinpu > From 69a4829a55503e496ce9c730d2c8e3dd8a08874a Mon Sep 17 00:00:00 2001 > From: NeilBrown > Date: Wed, 14 Dec 2016 16:55:52 +0100 > Subject: [PATCH] block: fix deadlock between freeze_array() and wait_barrier() > > When we call wait_barrier, we might have some bios waiting > in current->bio_list, which prevents the array_freeze call to > complete. Those can only be internal READs, which have already > passed the wait_barrier call (thus incrementing nr_pending), but > still were not submitted to the lower level, due to generic_make_request > logic to avoid recursive calls. In such case, we have a deadlock: > - array_frozen is already set to 1, so wait_barrier unconditionally waits, so > - internal READ bios will not be submitted, thus freeze_array will > never completes. > > To fix this, modify generic_make_request to always sort bio_list_on_stack > first with lowest level, then higher, until same level. > > Sent to linux-raid mail list: > https://marc.info/?l=linux-raid=148232453107685=2 > This should probably also have Inspired-by: Lars Ellenberg or something that, as I was building on Lars' ideas when I wrote this. It would also be worth noting in the description that this addresses issues with dm and drbd as well as md. In fact, I think that with this patch in place, much of the need for the rescue_workqueue won't exist any more. I cannot promise it can be removed completely, but it should be to hard to make it optional and only enabled for those few block devices that will still need it. The rescuer should only be needed for a bioset which can be allocated From twice in the one call the ->make_request_fn. This would include raid0 for example, though raid0_make_reqest could be re-written to not use a loop and to just call generic_make_request(bio) if bio != split. Thanks, NeilBrown > Suggested-by: NeilBrown > Signed-off-by: Jack Wang > --- > block/blk-core.c | 20 > 1 file changed, 20 insertions(+) > > diff --git a/block/blk-core.c b/block/blk-core.c > index 9e3ac56..47ef373 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -2138,10 +2138,30 @@ blk_qc_t generic_make_request(struct bio *bio) > struct request_queue *q = bdev_get_queue(bio->bi_bdev); > > if (likely(blk_queue_enter(q, __GFP_DIRECT_RECLAIM) == 0)) { > + struct bio_list lower, same, hold; > + > + /* Create a fresh bio_list for all subordinate requests > */ > + bio_list_init(); > + bio_list_merge(, _list_on_stack); > + bio_list_init(_list_on_stack); > > ret = q->make_request_fn(q, bio); > > blk_queue_exit(q); > + /* sort new bios into those for a lower level > + * and those for the same level > + */ > + bio_list_init(); > + bio_list_init(); > + while ((bio = bio_list_pop(_list_on_stack)) != NULL) > + if (q == bdev_get_queue(bio->bi_bdev)) > + bio_list_add(, bio); > + else > + bio_list_add(, bio); > + /* now assemble so we handle the lowest level first */ > + bio_list_merge(_list_on_stack, ); > + bio_list_merge(_list_on_stack, ); > + bio_list_merge(_list_on_stack,
Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
On Tue, Jan 03 2017, Jack Wang wrote: > 2016-12-23 12:45 GMT+01:00 Lars Ellenberg : >> On Fri, Dec 23, 2016 at 09:49:53AM +0100, Michael Wang wrote: >>> Dear Maintainers >>> >>> I'd like to ask for the status of this patch since we hit the >>> issue too during our testing on md raid1. >>> >>> Split remainder bio_A was queued ahead, following by bio_B for >>> lower device, at this moment raid start freezing, the loop take >>> out bio_A firstly and deliver it, which will hung since raid is >>> freezing, while the freezing never end since it waiting for >>> bio_B to finish, and bio_B is still on the queue, waiting for >>> bio_A to finish... >>> >>> We're looking for a good solution and we found this patch >>> already progressed a lot, but we can't find it on linux-next, >>> so we'd like to ask are we still planning to have this fix >>> in upstream? >> >> I don't see why not, I'd even like to have it in older kernels, >> but did not have the time and energy to push it. >> >> Thanks for the bump. >> >> Lars >> > Hi folks, > > As Michael mentioned, we hit a bug this patch is trying to fix. > Neil suggested another way to fix it. I attached below. > I personal prefer Neil's version as it's less code change, and straight > forward. > > Could you share your comments, we can get one fix into mainline. > > Thanks, > Jinpu > From 69a4829a55503e496ce9c730d2c8e3dd8a08874a Mon Sep 17 00:00:00 2001 > From: NeilBrown > Date: Wed, 14 Dec 2016 16:55:52 +0100 > Subject: [PATCH] block: fix deadlock between freeze_array() and wait_barrier() > > When we call wait_barrier, we might have some bios waiting > in current->bio_list, which prevents the array_freeze call to > complete. Those can only be internal READs, which have already > passed the wait_barrier call (thus incrementing nr_pending), but > still were not submitted to the lower level, due to generic_make_request > logic to avoid recursive calls. In such case, we have a deadlock: > - array_frozen is already set to 1, so wait_barrier unconditionally waits, so > - internal READ bios will not be submitted, thus freeze_array will > never completes. > > To fix this, modify generic_make_request to always sort bio_list_on_stack > first with lowest level, then higher, until same level. > > Sent to linux-raid mail list: > https://marc.info/?l=linux-raid=148232453107685=2 > This should probably also have Inspired-by: Lars Ellenberg or something that, as I was building on Lars' ideas when I wrote this. It would also be worth noting in the description that this addresses issues with dm and drbd as well as md. In fact, I think that with this patch in place, much of the need for the rescue_workqueue won't exist any more. I cannot promise it can be removed completely, but it should be to hard to make it optional and only enabled for those few block devices that will still need it. The rescuer should only be needed for a bioset which can be allocated From twice in the one call the ->make_request_fn. This would include raid0 for example, though raid0_make_reqest could be re-written to not use a loop and to just call generic_make_request(bio) if bio != split. Thanks, NeilBrown > Suggested-by: NeilBrown > Signed-off-by: Jack Wang > --- > block/blk-core.c | 20 > 1 file changed, 20 insertions(+) > > diff --git a/block/blk-core.c b/block/blk-core.c > index 9e3ac56..47ef373 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -2138,10 +2138,30 @@ blk_qc_t generic_make_request(struct bio *bio) > struct request_queue *q = bdev_get_queue(bio->bi_bdev); > > if (likely(blk_queue_enter(q, __GFP_DIRECT_RECLAIM) == 0)) { > + struct bio_list lower, same, hold; > + > + /* Create a fresh bio_list for all subordinate requests > */ > + bio_list_init(); > + bio_list_merge(, _list_on_stack); > + bio_list_init(_list_on_stack); > > ret = q->make_request_fn(q, bio); > > blk_queue_exit(q); > + /* sort new bios into those for a lower level > + * and those for the same level > + */ > + bio_list_init(); > + bio_list_init(); > + while ((bio = bio_list_pop(_list_on_stack)) != NULL) > + if (q == bdev_get_queue(bio->bi_bdev)) > + bio_list_add(, bio); > + else > + bio_list_add(, bio); > + /* now assemble so we handle the lowest level first */ > + bio_list_merge(_list_on_stack, ); > + bio_list_merge(_list_on_stack, ); > + bio_list_merge(_list_on_stack, ); > > bio = bio_list_pop(current->bio_list); > } else { > -- > 2.7.4
Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
2016-12-23 12:45 GMT+01:00 Lars Ellenberg: > On Fri, Dec 23, 2016 at 09:49:53AM +0100, Michael Wang wrote: >> Dear Maintainers >> >> I'd like to ask for the status of this patch since we hit the >> issue too during our testing on md raid1. >> >> Split remainder bio_A was queued ahead, following by bio_B for >> lower device, at this moment raid start freezing, the loop take >> out bio_A firstly and deliver it, which will hung since raid is >> freezing, while the freezing never end since it waiting for >> bio_B to finish, and bio_B is still on the queue, waiting for >> bio_A to finish... >> >> We're looking for a good solution and we found this patch >> already progressed a lot, but we can't find it on linux-next, >> so we'd like to ask are we still planning to have this fix >> in upstream? > > I don't see why not, I'd even like to have it in older kernels, > but did not have the time and energy to push it. > > Thanks for the bump. > > Lars > Hi folks, As Michael mentioned, we hit a bug this patch is trying to fix. Neil suggested another way to fix it. I attached below. I personal prefer Neil's version as it's less code change, and straight forward. Could you share your comments, we can get one fix into mainline. Thanks, Jinpu From 69a4829a55503e496ce9c730d2c8e3dd8a08874a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 14 Dec 2016 16:55:52 +0100 Subject: [PATCH] block: fix deadlock between freeze_array() and wait_barrier() When we call wait_barrier, we might have some bios waiting in current->bio_list, which prevents the array_freeze call to complete. Those can only be internal READs, which have already passed the wait_barrier call (thus incrementing nr_pending), but still were not submitted to the lower level, due to generic_make_request logic to avoid recursive calls. In such case, we have a deadlock: - array_frozen is already set to 1, so wait_barrier unconditionally waits, so - internal READ bios will not be submitted, thus freeze_array will never completes. To fix this, modify generic_make_request to always sort bio_list_on_stack first with lowest level, then higher, until same level. Sent to linux-raid mail list: https://marc.info/?l=linux-raid=148232453107685=2 Suggested-by: NeilBrown Signed-off-by: Jack Wang --- block/blk-core.c | 20 1 file changed, 20 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 9e3ac56..47ef373 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2138,10 +2138,30 @@ blk_qc_t generic_make_request(struct bio *bio) struct request_queue *q = bdev_get_queue(bio->bi_bdev); if (likely(blk_queue_enter(q, __GFP_DIRECT_RECLAIM) == 0)) { + struct bio_list lower, same, hold; + + /* Create a fresh bio_list for all subordinate requests */ + bio_list_init(); + bio_list_merge(, _list_on_stack); + bio_list_init(_list_on_stack); ret = q->make_request_fn(q, bio); blk_queue_exit(q); + /* sort new bios into those for a lower level + * and those for the same level + */ + bio_list_init(); + bio_list_init(); + while ((bio = bio_list_pop(_list_on_stack)) != NULL) +if (q == bdev_get_queue(bio->bi_bdev)) + bio_list_add(, bio); +else + bio_list_add(, bio); + /* now assemble so we handle the lowest level first */ + bio_list_merge(_list_on_stack, ); + bio_list_merge(_list_on_stack, ); + bio_list_merge(_list_on_stack, ); bio = bio_list_pop(current->bio_list); } else { -- 2.7.4
Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
2016-12-23 12:45 GMT+01:00 Lars Ellenberg : > On Fri, Dec 23, 2016 at 09:49:53AM +0100, Michael Wang wrote: >> Dear Maintainers >> >> I'd like to ask for the status of this patch since we hit the >> issue too during our testing on md raid1. >> >> Split remainder bio_A was queued ahead, following by bio_B for >> lower device, at this moment raid start freezing, the loop take >> out bio_A firstly and deliver it, which will hung since raid is >> freezing, while the freezing never end since it waiting for >> bio_B to finish, and bio_B is still on the queue, waiting for >> bio_A to finish... >> >> We're looking for a good solution and we found this patch >> already progressed a lot, but we can't find it on linux-next, >> so we'd like to ask are we still planning to have this fix >> in upstream? > > I don't see why not, I'd even like to have it in older kernels, > but did not have the time and energy to push it. > > Thanks for the bump. > > Lars > Hi folks, As Michael mentioned, we hit a bug this patch is trying to fix. Neil suggested another way to fix it. I attached below. I personal prefer Neil's version as it's less code change, and straight forward. Could you share your comments, we can get one fix into mainline. Thanks, Jinpu From 69a4829a55503e496ce9c730d2c8e3dd8a08874a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 14 Dec 2016 16:55:52 +0100 Subject: [PATCH] block: fix deadlock between freeze_array() and wait_barrier() When we call wait_barrier, we might have some bios waiting in current->bio_list, which prevents the array_freeze call to complete. Those can only be internal READs, which have already passed the wait_barrier call (thus incrementing nr_pending), but still were not submitted to the lower level, due to generic_make_request logic to avoid recursive calls. In such case, we have a deadlock: - array_frozen is already set to 1, so wait_barrier unconditionally waits, so - internal READ bios will not be submitted, thus freeze_array will never completes. To fix this, modify generic_make_request to always sort bio_list_on_stack first with lowest level, then higher, until same level. Sent to linux-raid mail list: https://marc.info/?l=linux-raid=148232453107685=2 Suggested-by: NeilBrown Signed-off-by: Jack Wang --- block/blk-core.c | 20 1 file changed, 20 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 9e3ac56..47ef373 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2138,10 +2138,30 @@ blk_qc_t generic_make_request(struct bio *bio) struct request_queue *q = bdev_get_queue(bio->bi_bdev); if (likely(blk_queue_enter(q, __GFP_DIRECT_RECLAIM) == 0)) { + struct bio_list lower, same, hold; + + /* Create a fresh bio_list for all subordinate requests */ + bio_list_init(); + bio_list_merge(, _list_on_stack); + bio_list_init(_list_on_stack); ret = q->make_request_fn(q, bio); blk_queue_exit(q); + /* sort new bios into those for a lower level + * and those for the same level + */ + bio_list_init(); + bio_list_init(); + while ((bio = bio_list_pop(_list_on_stack)) != NULL) +if (q == bdev_get_queue(bio->bi_bdev)) + bio_list_add(, bio); +else + bio_list_add(, bio); + /* now assemble so we handle the lowest level first */ + bio_list_merge(_list_on_stack, ); + bio_list_merge(_list_on_stack, ); + bio_list_merge(_list_on_stack, ); bio = bio_list_pop(current->bio_list); } else { -- 2.7.4
Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
On Tue, 12 Jul 2016, NeilBrown wrote: > On Tue, Jul 12 2016, Lars Ellenberg wrote: > > > > > Instead, I suggest to distinguish between recursive calls to > > generic_make_request(), and pushing back the remainder part in > > blk_queue_split(), by pointing current->bio_lists to a > > struct recursion_to_iteration_bio_lists { > > struct bio_list recursion; > > struct bio_list queue; > > } > > > > By providing each q->make_request_fn() with an empty "recursion" > > bio_list, then merging any recursively submitted bios to the > > head of the "queue" list, we can make the recursion-to-iteration > > logic in generic_make_request() process deepest level bios first, > > and "sibling" bios of the same level in "natural" order. > > > > Signed-off-by: Lars Ellenberg> > Signed-off-by: Roland Kammerer > > Reviewed-by: NeilBrown > > Thanks again for doing this - I think this is a very significant > improvement and could allow other simplifications. Thank you Lars for all of this work! It seems like there have been many 4.3+ blockdev stacking issues and this will certainly address some of those (maybe all of them?). (I think we hit this while trying drbd in 4.4 so we dropped back to 4.1 without issue.) It would be great to hear 4.4.y stable pick this up if compatible. Do you believe that this patch would solve any of the proposals by others since 4.3 related to bio splitting/large bios? I've been collecting a list, none of which appear have landed yet as of 4.7-rc7 (but correct me if I'm wrong): A. [PATCH v2] block: make sure big bio is splitted into at most 256 bvecs by Ming Lei: https://patchwork.kernel.org/patch/9169483/ B. block: don't make BLK_DEF_MAX_SECTORS too big by Shaohua Li: http://www.spinics.net/lists/linux-bcache/msg03525.html C. [1/3] block: flush queued bios when process blocks to avoid deadlock by Mikulas Patocka: https://patchwork.kernel.org/patch/9204125/ (was https://patchwork.kernel.org/patch/7398411/) D. dm-crypt: Fix error with too large bios by Mikulas Patocka: https://patchwork.kernel.org/patch/9138595/ The A,B,D are known to fix large bio issues when stacking dm+bcache (though the B,D are trivial and probably necessary even with your patch). Patch C was mentioned earlier in this thread by Mike Snitzer and you commented briefly that his patch might solve the issue; given that, and in the interest of minimizing duplicate effort, which of the following best describes the situation? 1. Your patch could supersede Mikulas's patch; they address the same issue. 2. Mikulas's patch addresses different issues such and both patches should be applied. 3. There is overlap between both your patch and Mikulas's such that both #1,#2 are true and effort to solve this has been duplicated. If #3, then what might be done to resolve the overlap? What are the opinions of the authors and can a consensus be reached so we can see these pushed upstream with the appropriate stable Cc tags and ultimately fix 4.4.y? -- Eric Wheeler
Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
On Tue, 12 Jul 2016, NeilBrown wrote: > On Tue, Jul 12 2016, Lars Ellenberg wrote: > > > > > Instead, I suggest to distinguish between recursive calls to > > generic_make_request(), and pushing back the remainder part in > > blk_queue_split(), by pointing current->bio_lists to a > > struct recursion_to_iteration_bio_lists { > > struct bio_list recursion; > > struct bio_list queue; > > } > > > > By providing each q->make_request_fn() with an empty "recursion" > > bio_list, then merging any recursively submitted bios to the > > head of the "queue" list, we can make the recursion-to-iteration > > logic in generic_make_request() process deepest level bios first, > > and "sibling" bios of the same level in "natural" order. > > > > Signed-off-by: Lars Ellenberg > > Signed-off-by: Roland Kammerer > > Reviewed-by: NeilBrown > > Thanks again for doing this - I think this is a very significant > improvement and could allow other simplifications. Thank you Lars for all of this work! It seems like there have been many 4.3+ blockdev stacking issues and this will certainly address some of those (maybe all of them?). (I think we hit this while trying drbd in 4.4 so we dropped back to 4.1 without issue.) It would be great to hear 4.4.y stable pick this up if compatible. Do you believe that this patch would solve any of the proposals by others since 4.3 related to bio splitting/large bios? I've been collecting a list, none of which appear have landed yet as of 4.7-rc7 (but correct me if I'm wrong): A. [PATCH v2] block: make sure big bio is splitted into at most 256 bvecs by Ming Lei: https://patchwork.kernel.org/patch/9169483/ B. block: don't make BLK_DEF_MAX_SECTORS too big by Shaohua Li: http://www.spinics.net/lists/linux-bcache/msg03525.html C. [1/3] block: flush queued bios when process blocks to avoid deadlock by Mikulas Patocka: https://patchwork.kernel.org/patch/9204125/ (was https://patchwork.kernel.org/patch/7398411/) D. dm-crypt: Fix error with too large bios by Mikulas Patocka: https://patchwork.kernel.org/patch/9138595/ The A,B,D are known to fix large bio issues when stacking dm+bcache (though the B,D are trivial and probably necessary even with your patch). Patch C was mentioned earlier in this thread by Mike Snitzer and you commented briefly that his patch might solve the issue; given that, and in the interest of minimizing duplicate effort, which of the following best describes the situation? 1. Your patch could supersede Mikulas's patch; they address the same issue. 2. Mikulas's patch addresses different issues such and both patches should be applied. 3. There is overlap between both your patch and Mikulas's such that both #1,#2 are true and effort to solve this has been duplicated. If #3, then what might be done to resolve the overlap? What are the opinions of the authors and can a consensus be reached so we can see these pushed upstream with the appropriate stable Cc tags and ultimately fix 4.4.y? -- Eric Wheeler
Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
On Tue, Jul 12 2016, Lars Ellenberg wrote: > > Instead, I suggest to distinguish between recursive calls to > generic_make_request(), and pushing back the remainder part in > blk_queue_split(), by pointing current->bio_lists to a > struct recursion_to_iteration_bio_lists { > struct bio_list recursion; > struct bio_list queue; > } > > By providing each q->make_request_fn() with an empty "recursion" > bio_list, then merging any recursively submitted bios to the > head of the "queue" list, we can make the recursion-to-iteration > logic in generic_make_request() process deepest level bios first, > and "sibling" bios of the same level in "natural" order. > > Signed-off-by: Lars Ellenberg> Signed-off-by: Roland Kammerer Reviewed-by: NeilBrown Thanks again for doing this - I think this is a very significant improvement and could allow other simplifications. NeilBrown signature.asc Description: PGP signature
Re: [dm-devel] [PATCH v2 1/1] block: fix blk_queue_split() resource exhaustion
On Tue, Jul 12 2016, Lars Ellenberg wrote: > > Instead, I suggest to distinguish between recursive calls to > generic_make_request(), and pushing back the remainder part in > blk_queue_split(), by pointing current->bio_lists to a > struct recursion_to_iteration_bio_lists { > struct bio_list recursion; > struct bio_list queue; > } > > By providing each q->make_request_fn() with an empty "recursion" > bio_list, then merging any recursively submitted bios to the > head of the "queue" list, we can make the recursion-to-iteration > logic in generic_make_request() process deepest level bios first, > and "sibling" bios of the same level in "natural" order. > > Signed-off-by: Lars Ellenberg > Signed-off-by: Roland Kammerer Reviewed-by: NeilBrown Thanks again for doing this - I think this is a very significant improvement and could allow other simplifications. NeilBrown signature.asc Description: PGP signature