block: don't allow multiple bios for IOCB_NOWAIT issue
Jens Axboe
maintainerPATCH v2 1/1 block: don't allow multiple bios for IOCB_NOWAIT issue
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on: 613b14884b85 ("block: handle bio_split_to_limits() NULL return")
---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +18 -3
@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio); +blk_finish_plug (&plug); +return -EAGAIN ; + } + bio->bi_opf |=REQ_NOWAIT ; + }if (is_read) {if (dio->flags &DIO_SHOULD_DIRTY )
@@ -228,9 +246,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, }else {task_io_account_write (bio->bi_iter.bi_size); } -if (iocb->ki_flags &IOCB_NOWAIT ) - bio->bi_opf |=REQ_NOWAIT ; - dio->size += bio->bi_iter.bi_size; pos += bio->bi_iter.bi_size;
Signature · 1 line
Jens Axboe
Quoted 39 lines · Jens Axboe
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +5
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 238
Quoted 10 lines
block/fops.c +10
-0+* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio); +blk_finish_plug (&plug); +return -EAGAIN ;
Doesn't this mean that for a really very large IO request that has 100% chance of being split, the user will always get -EAGAIN ? Not that I mind, doing super large IOs with NOWAIT is not a smart thing to do in the first place... But as a user interface, it seems that this will prevent any forward progress for such really large NOWAIT IOs. Is that OK ?
Quoted 16 lines
block/fops.c +3
-3+ } + bio->bi_opf |=REQ_NOWAIT ; + }if (is_read) {if (dio->flags &DIO_SHOULD_DIRTY )@@ -228,9 +246,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, }else {task_io_account_write (bio->bi_iter.bi_size); } -if (iocb->ki_flags &IOCB_NOWAIT ) - bio->bi_opf |=REQ_NOWAIT ; - dio->size += bio->bi_iter.bi_size; pos += bio->bi_iter.bi_size;
Signature · 2 lines
Damien Le Moal Western Digital Research
Jens Axboe
maintainerQuoted 48 lines · Damien Le Moal
Quoted 47 lines · Jens Axboe
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +13
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio);
Quoted 8 lines
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 238
Quoted 2 lines
block/fops.c +2
-0+blk_finish_plug (&plug); +return -EAGAIN ;Doesn't this mean that for a really very large IO request that has 100% chance of being split, the user will always get
-EAGAIN? Not that I mind, doing super large IOs with NOWAIT is not a smart thing to do in the first place... But as a user interface, it seems that this will prevent any forward progress for such really large NOWAIT IOs. Is that OK ?
Right, if you asked for NOWAIT, then it would not necessarily succeed if it:
1) Needs multiple bios
2) Needs splitting
You're expected to attempt blocking issue at that point. Reasoning is explained in this (and the previous commit related to the issue), otherwise you end up with potentially various amounts of the request being written to disk or read from disk, but EAGAIN being returned for the request as a whole.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 61 lines · Jens Axboe
Quoted 48 lines · Damien Le Moal
Quoted 47 lines · Jens Axboe
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +13
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio);Quoted 8 lines
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 238
Quoted 2 lines
block/fops.c +2
-0+blk_finish_plug (&plug); +return -EAGAIN ;Doesn't this mean that for a really very large IO request that has 100% chance of being split, the user will always get
-EAGAIN? Not that I mind, doing super large IOs with NOWAIT is not a smart thing to do in the first place... But as a user interface, it seems that this will prevent any forward progress for such really large NOWAIT IOs. Is that OK ?Right, if you asked for NOWAIT, then it would not necessarily succeed if it:
Quoted 8 lines
1) Needs multiple bios
2) Needs splittingYou're expected to attempt blocking issue at that point. Reasoning is explained in this (and the previous commit related to the issue), otherwise you end up with potentially various amounts of the request being written to disk or read from disk, but EAGAIN being returned for the request as a whole.
BTW, this is no different than eg doing a buffered read and needing to read in the data. You'd get EAGAIN, and no amount of repeated retries would change that. You need to either block for the IO at that point, or otherwise start it so it will become available directly at some later point (eg readahead).
Signature · 1 line
Jens Axboe
Quoted 61 lines · Jens Axboe
Quoted 48 lines · Damien Le Moal
Quoted 47 lines · Jens Axboe
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +13
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio);Quoted 8 lines
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 238
Quoted 2 lines
block/fops.c +2
-0+blk_finish_plug (&plug); +return -EAGAIN ;Doesn't this mean that for a really very large IO request that has 100% chance of being split, the user will always get
-EAGAIN? Not that I mind, doing super large IOs with NOWAIT is not a smart thing to do in the first place... But as a user interface, it seems that this will prevent any forward progress for such really large NOWAIT IOs. Is that OK ?Right, if you asked for NOWAIT, then it would not necessarily succeed if it:
Quoted 8 lines
1) Needs multiple bios
2) Needs splittingYou're expected to attempt blocking issue at that point. Reasoning is explained in this (and the previous commit related to the issue), otherwise you end up with potentially various amounts of the request being written to disk or read from disk, but EAGAIN being returned for the request as a whole.
Yes, I understood all that and completely agree with it.
I was only wondering if this change may not surprise some (bad) userspace stuff. Do we need to update some man page or other doc, mentioning that there are no guarantees that a NOWAIT IO may actually be executed if it too large (e.g. larger than max_sectors_kb) ?
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 71 lines · Jens Axboe
Quoted 61 lines · Jens Axboe
Quoted 48 lines · Damien Le Moal
Quoted 47 lines · Jens Axboe
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +13
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio);Quoted 8 lines
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 238
Quoted 2 lines
block/fops.c +2
-0+blk_finish_plug (&plug); +return -EAGAIN ;Doesn't this mean that for a really very large IO request that has 100% chance of being split, the user will always get
-EAGAIN? Not that I mind, doing super large IOs with NOWAIT is not a smart thing to do in the first place... But as a user interface, it seems that this will prevent any forward progress for such really large NOWAIT IOs. Is that OK ?Right, if you asked for NOWAIT, then it would not necessarily succeed if it:
Quoted 8 lines
1) Needs multiple bios
2) Needs splittingYou're expected to attempt blocking issue at that point. Reasoning is explained in this (and the previous commit related to the issue), otherwise you end up with potentially various amounts of the request being written to disk or read from disk, but EAGAIN being returned for the request as a whole.
Quoted 5 lines
BTW, this is no different than eg doing a buffered read and needing to read in the data. You'd get EAGAIN, and no amount of repeated retries would change that. You need to either block for the IO at that point, or otherwise start it so it will become available directly at some later point (eg readahead).
Indeed.
Signature · 2 lines
Damien Le Moal Western Digital Research
Jens Axboe
maintainerQuoted 71 lines · Damien Le Moal
Quoted 61 lines · Jens Axboe
Quoted 48 lines · Damien Le Moal
Quoted 47 lines · Jens Axboe
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +13
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio);Quoted 8 lines
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 238
Quoted 2 lines
block/fops.c +2
-0+blk_finish_plug (&plug); +return -EAGAIN ;Doesn't this mean that for a really very large IO request that has 100% chance of being split, the user will always get
-EAGAIN? Not that I mind, doing super large IOs with NOWAIT is not a smart thing to do in the first place... But as a user interface, it seems that this will prevent any forward progress for such really large NOWAIT IOs. Is that OK ?Right, if you asked for NOWAIT, then it would not necessarily succeed if it:
Quoted 8 lines
1) Needs multiple bios
2) Needs splittingYou're expected to attempt blocking issue at that point. Reasoning is explained in this (and the previous commit related to the issue), otherwise you end up with potentially various amounts of the request being written to disk or read from disk, but EAGAIN being returned for the request as a whole.
Quoted 6 lines
Yes, I understood all that and completely agree with it.
I was only wondering if this change may not surprise some (bad) userspace stuff. Do we need to update some man page or other doc, mentioning that there are no guarantees that a NOWAIT IO may actually be executed if it too large (e.g. larger than
max_sectors_kb) ?
We can certainly add it to the man pages talking about RWF_NOWAIT. But there's never been a guarantee that any EAGAIN will later succeed under the same conditions, and honestly there are various conditions where this is already not true. And those same cases would spuriously yield EAGAIN before already, it's not a new condition for those sizes of IOs.
Signature · 1 line
Jens Axboe
Quoted 79 lines · Jens Axboe
Quoted 71 lines · Damien Le Moal
Quoted 61 lines · Jens Axboe
Quoted 48 lines · Damien Le Moal
Quoted 47 lines · Jens Axboe
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +13
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_endio (bio);break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio);Quoted 8 lines
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 238
Quoted 2 lines
block/fops.c +2
-0+blk_finish_plug (&plug); +return -EAGAIN ;Doesn't this mean that for a really very large IO request that has 100% chance of being split, the user will always get
-EAGAIN? Not that I mind, doing super large IOs with NOWAIT is not a smart thing to do in the first place... But as a user interface, it seems that this will prevent any forward progress for such really large NOWAIT IOs. Is that OK ?Right, if you asked for NOWAIT, then it would not necessarily succeed if it:
Quoted 8 lines
1) Needs multiple bios
2) Needs splittingYou're expected to attempt blocking issue at that point. Reasoning is explained in this (and the previous commit related to the issue), otherwise you end up with potentially various amounts of the request being written to disk or read from disk, but EAGAIN being returned for the request as a whole.
Quoted 6 lines
Yes, I understood all that and completely agree with it.
I was only wondering if this change may not surprise some (bad) userspace stuff. Do we need to update some man page or other doc, mentioning that there are no guarantees that a NOWAIT IO may actually be executed if it too large (e.g. larger than
max_sectors_kb) ?
Quoted 6 lines
We can certainly add it to the man pages talking about
RWF_NOWAIT. But there's never been a guarantee that any EAGAIN will later succeed under the same conditions, and honestly there are various conditions where this is already not true. And those same cases would spuriously yield EAGAIN before already, it's not a new condition for those sizes of IOs.
OK. Thanks.
Signature · 2 lines
Damien Le Moal Western Digital Research
From: Jens Axboe <[email protected]> Sent: Monday, January 16, 2023 1:06 PM
Quoted 58 lines
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +18
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, structiov_iter *iter,bio_endio (bio );break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio); +blk_finish_plug (&plug); +return -EAGAIN ; + } + bio->bi_opf |=REQ_NOWAIT ; + }if (is_read) {block/fops.c +0
-0if (dio->flags &DIO_SHOULD_DIRTY )
block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 251
Quoted 9 lines
block/fops.c +0
-3@@ -228,9 +246,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, }else {task_io_account_write (bio->bi_iter.bi_size); } -if (iocb->ki_flags &IOCB_NOWAIT ) - bio->bi_opf |=REQ_NOWAIT ; - dio->size += bio->bi_iter.bi_size; pos += bio->bi_iter.bi_size;
I've wrapped up my testing on this patch. All testing was via io_uring -- I did not test other paths. Testing was against a combination of this patch and the previous patch set for a similar problem. [1]
I tested with a simple test program to issue single I/Os, and verified the expected paths were taken through the block layer and io_uring code for various size I/Os, including over 1 Mbyte. No EAGAIN errors were seen. This testing was with a 6.1 kernel.
Also tested the original app that surfaced the problem. It's a larger scale workload using io_uring, and is where the problem was originally encountered. That workload runs on a purpose-built 5.15 kernel, so I backported both patches to 5.15 for this testing. All looks good. No EAGAIN errors were seen.
Michael
Jens Axboe
maintainerQuoted 79 lines · Michael Kelley (LINUX)
From: Jens Axboe <[email protected]> Sent: Monday, January 16, 2023 1:06 PM
Quoted 58 lines
If we're doing a large IO request which needs to be split into multiple bios for issue, then we can run into the same situation as the below marked commit fixes - parts will complete just fine, one or more parts will fail to allocate a request. This will result in a partially completed read or write request, where the caller gets EAGAIN even though parts of the IO completed just fine.
Do the same for large bios as we do for splits - fail a NOWAIT request with EAGAIN. This isn't technically fixing an issue in the below marked patch, but for stable purposes, we should have either none of them or both.
This depends on:
613b14884b85("block: handlebio_split_to_limits()NULL return")Cc [email protected] # 5.15+Fixes 9cea62b2cbab ("block: don't allow splitting of a REQ_NOWAIT bio")Reported-and-tested-by Michael Kelley <[email protected]>Signed-off-by Jens Axboe <[email protected]>---
Since v1: catch this at submit time instead, since we can have various valid cases where the number of single page segments will not take a bio segment (page merging, huge pages).
block/fops.c +18
-0@@ -221,6 +221,24 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, structiov_iter *iter,bio_endio (bio );break ; } +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* This is nonblocking IO, and we need to allocate +* another bio if we have data left to map. As we +* cannot guarantee that one of the sub bios will not +* fail getting issued FOR NOWAIT and as error results +* are coalesced across all of them, be safe and ask for +* a retry of this from blocking context. +*/ +if (unlikely (iov_iter_count (iter))) { +bio_release_pages (bio, false); +bio_clear_flag (bio,BIO_REFFED ); +bio_put (bio); +blk_finish_plug (&plug); +return -EAGAIN ; + } + bio->bi_opf |=REQ_NOWAIT ; + }if (is_read) {block/fops.c +0
-0if (dio->flags &DIO_SHOULD_DIRTY )block/fops.c static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, · line 251
Quoted 9 lines
block/fops.c +0
-3@@ -228,9 +246,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, }else {task_io_account_write (bio->bi_iter.bi_size); } -if (iocb->ki_flags &IOCB_NOWAIT ) - bio->bi_opf |=REQ_NOWAIT ; - dio->size += bio->bi_iter.bi_size; pos += bio->bi_iter.bi_size;I've wrapped up my testing on this patch. All testing was via
io_uring-- I did not test other paths. Testing was against a combination of this patch and the previous patch set for a similar problem. [1]I tested with a simple test program to issue single I/Os, and verified the expected paths were taken through the block layer and
io_uringcode for various size I/Os, including over 1 Mbyte. No EAGAIN errors were seen. This testing was with a 6.1 kernel.
Quoted 5 lines
Also tested the original app that surfaced the problem. It's a larger scale workload using
io_uring, and is where the problem was originally encountered. That workload runs on a purpose-built 5.15 kernel, so I backported both patches to 5.15 for this testing. All looks good. No EAGAIN errors were seen.
Thanks a lot for your thorough testing! Can you share the 5.15 backports, so we can put them into 5.15-stable as well potentially?
Signature · 1 line
Jens Axboe
From: Jens Axboe <[email protected]> Sent: Saturday, January 21, 2023 1:11 PM
Quoted 3 lines · Michael Kelley (LINUX)
Quoted 1 line
From: Jens Axboe <[email protected]> Sent: Monday, January 16, 2023 1:06 PM
[snip]
Quoted 11 lines
Quoted 11 lines
I've wrapped up my testing on this patch. All testing was via
io_uring-- I did not test other paths. Testing was against a combination of this patch and the previous patch set for a similar problem. [1]I tested with a simple test program to issue single I/Os, and verified the expected paths were taken through the block layer and
io_uringcode for various size I/Os, including over 1 Mbyte. No EAGAIN errors were seen. This testing was with a 6.1 kernel.
Quoted 9 lines
Quoted 5 lines
Also tested the original app that surfaced the problem. It's a larger scale workload using
io_uring, and is where the problem was originally encountered. That workload runs on a purpose-built 5.15 kernel, so I backported both patches to 5.15 for this testing. All looks good. No EAGAIN errors were seen.Thanks a lot for your thorough testing! Can you share the 5.15 backports, so we can put them into 5.15-stable as well potentially?
Certainly. What's the best way to do that? Should I send them to you, or to the linux-block list? Or post directly to [email protected]? If the latter, maybe I need to wait until it has an upstream commit ID that can be referenced. Also, you or someone should do a quick review of the backport to make sure I didn't break something in a path I didn't test.
Michael
Jens Axboe
maintainerQuoted 28 lines · Michael Kelley (LINUX)
From: Jens Axboe <[email protected]> Sent: Saturday, January 21, 2023 1:11 PM
Quoted 3 lines · Michael Kelley (LINUX)
Quoted 1 line
From: Jens Axboe <[email protected]> Sent: Monday, January 16, 2023 1:06 PM
[snip]
Quoted 11 lines
Quoted 11 lines
I've wrapped up my testing on this patch. All testing was via
io_uring-- I did not test other paths. Testing was against a combination of this patch and the previous patch set for a similar problem. [1]I tested with a simple test program to issue single I/Os, and verified the expected paths were taken through the block layer and
io_uringcode for various size I/Os, including over 1 Mbyte. No EAGAIN errors were seen. This testing was with a 6.1 kernel.Quoted 9 lines
Quoted 5 lines
Also tested the original app that surfaced the problem. It's a larger scale workload using
io_uring, and is where the problem was originally encountered. That workload runs on a purpose-built 5.15 kernel, so I backported both patches to 5.15 for this testing. All looks good. No EAGAIN errors were seen.Thanks a lot for your thorough testing! Can you share the 5.15 backports, so we can put them into 5.15-stable as well potentially?
Quoted 6 lines
Certainly. What's the best way to do that? Should I send them to you, or to the linux-block list? Or post directly to [email protected]? If the latter, maybe I need to wait until it has an upstream commit ID that can be referenced. Also, you or someone should do a quick review of the backport to make sure I didn't break something in a path I didn't test.
Just send them to the block list, then we have them for when the commit hits upstream and gives us a chance to review them upfront.
Thanks!
Signature · 1 line
Jens Axboe
From: Jens Axboe <[email protected]> Sent: Tuesday, January 24, 2023 8:13 AM
Quoted 37 lines · Michael Kelley (LINUX)
Quoted 28 lines
From: Jens Axboe <[email protected]> Sent: Saturday, January 21, 2023 1:11 PM
Quoted 3 lines · Michael Kelley (LINUX)
Quoted 1 line
From: Jens Axboe <[email protected]> Sent: Monday, January 16, 2023 1:06 PM
[snip]
Quoted 11 lines
Quoted 11 lines
I've wrapped up my testing on this patch. All testing was via
io_uring-- I did not test other paths. Testing was against a combination of this patch and the previous patch set for a similar problem. [1]I tested with a simple test program to issue single I/Os, and verified the expected paths were taken through the block layer and
io_uringcode for various size I/Os, including over 1 Mbyte. No EAGAIN errors were seen. This testing was with a 6.1 kernel.Quoted 9 lines
Quoted 5 lines
Also tested the original app that surfaced the problem. It's a larger scale workload using
io_uring, and is where the problem was originally encountered. That workload runs on a purpose-built 5.15 kernel, so I backported both patches to 5.15 for this testing. All looks good. No EAGAIN errors were seen.Thanks a lot for your thorough testing! Can you share the 5.15 backports, so we can put them into 5.15-stable as well potentially?
Quoted 6 lines
Certainly. What's the best way to do that? Should I send them to you, or to the linux-block list? Or post directly to [email protected]? If the latter, maybe I need to wait until it has an upstream commit ID that can be referenced. Also, you or someone should do a quick review of the backport to make sure I didn't break something in a path I didn't test.
Quoted 5 lines
Just send them to the block list, then we have them for when the commit hits upstream and gives us a chance to review them upfront.
Thanks!
Your first two patches for handling bio splitting have already been
backported to 5.15 and are included in 5.15.90. However, in reviewing
the backports, stable commit 613b14884b85 didn't update dm_submit_bio()
to check for a NULL bio being returned by blk_queue_split(). Presumably
that needs to be fixed unless there is a reason the check isn't needed (which I didn't see).
Separately, I've posted a v5.15.90 backport for the __blkdev_direct_IO() fix for multiple bio's.
Michael