diff mbox series

[v4,2/2] block,iomap: disable iopoll when split needed

Message ID 20201117075625.46118-3-jefflexu@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series block, iomap: disable iopoll for split bio | expand

Commit Message

Jingbo Xu Nov. 17, 2020, 7:56 a.m. UTC
Both blkdev fs and iomap-based fs (ext4, xfs, etc.) currently support
sync iopoll. One single bio can contain at most BIO_MAX_PAGES, i.e. 256
bio_vec. If the input iov_iter contains more than 256 segments, then
one dio will be split into multiple bios, which may cause potential
deadlock for sync iopoll.

When it comes to sync iopoll, the bio is submitted without REQ_NOWAIT
flag set and the process may hang in blk_mq_get_tag() if the dio needs
to be split into multiple bios and thus can rapidly exhausts the queue
depth. The process has to wait for the completion of the previously
allocated requests, which should be reaped by the following sync
polling, and thus causing a potential deadlock.

In fact there's a subtle difference of handling of HIPRI IO between
blkdev fs and iomap-based fs, when dio need to be split into multiple
bios. blkdev fs will set REQ_HIPRI for only the last split bio, leaving
the previous bios queued into normal hardware queues, and not causing
the trouble described above. iomap-based fs will set REQ_HIPRI for all
split bios, and thus may cause the potential deadlock described above.

Noted that though the analysis described above, currently blkdev fs and
iomap-based fs won't trigger this potential deadlock. Because only
preadv2(2)/pwritev2(2) are capable of *sync* polling as only these two
can set RWF_NOWAIT. Currently the maximum number of iovecs of one single
preadv2(2)/pwritev2(2) call is UIO_MAXIOV, i.e. 1024, while the minimum
queue depth is BLKDEV_MIN_RQ i.e. 4. That means one
preadv2(2)/pwritev2(2) call can submit at most 4 bios, which will fill
up the queue depth *exactly* and thus there's no deadlock in this case.

However this constraint can be fragile. Disable iopoll when one dio need
to be split into multiple bios.Though blkdev fs may not suffer this issue,
still it may not make much sense to iopoll for big IO, since iopoll is
initially for small size, latency sensitive IO.

Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
 fs/block_dev.c       |  9 +++++++++
 fs/iomap/direct-io.c | 10 ++++++++++
 2 files changed, 19 insertions(+)

Comments

Darrick J. Wong Nov. 17, 2020, 5:37 p.m. UTC | #1
On Tue, Nov 17, 2020 at 03:56:25PM +0800, Jeffle Xu wrote:
> Both blkdev fs and iomap-based fs (ext4, xfs, etc.) currently support

$ ./scripts/get_maintainer.pl fs/iomap/direct-io.c
Christoph Hellwig <hch@infradead.org> (supporter:IOMAP FILESYSTEM LIBRARY)
"Darrick J. Wong" <darrick.wong@oracle.com> (supporter:IOMAP FILESYSTEM LIBRARY)
linux-xfs@vger.kernel.org (supporter:IOMAP FILESYSTEM LIBRARY)
linux-fsdevel@vger.kernel.org (supporter:IOMAP FILESYSTEM LIBRARY)
linux-kernel@vger.kernel.org (open list)

Please cc both iomap maintainers and the appropriate lists when you
propose changes to fs/iomap/.  At a bare minimum cc linux-fsdevel for
changes under fs/.

> sync iopoll. One single bio can contain at most BIO_MAX_PAGES, i.e. 256
> bio_vec. If the input iov_iter contains more than 256 segments, then
> one dio will be split into multiple bios, which may cause potential
> deadlock for sync iopoll.
> 
> When it comes to sync iopoll, the bio is submitted without REQ_NOWAIT
> flag set and the process may hang in blk_mq_get_tag() if the dio needs
> to be split into multiple bios and thus can rapidly exhausts the queue
> depth. The process has to wait for the completion of the previously
> allocated requests, which should be reaped by the following sync
> polling, and thus causing a potential deadlock.
> 
> In fact there's a subtle difference of handling of HIPRI IO between
> blkdev fs and iomap-based fs, when dio need to be split into multiple
> bios. blkdev fs will set REQ_HIPRI for only the last split bio, leaving
> the previous bios queued into normal hardware queues, and not causing
> the trouble described above. iomap-based fs will set REQ_HIPRI for all
> split bios, and thus may cause the potential deadlock described above.
> 
> Noted that though the analysis described above, currently blkdev fs and
> iomap-based fs won't trigger this potential deadlock. Because only
> preadv2(2)/pwritev2(2) are capable of *sync* polling as only these two
> can set RWF_NOWAIT. Currently the maximum number of iovecs of one single
> preadv2(2)/pwritev2(2) call is UIO_MAXIOV, i.e. 1024, while the minimum
> queue depth is BLKDEV_MIN_RQ i.e. 4. That means one
> preadv2(2)/pwritev2(2) call can submit at most 4 bios, which will fill
> up the queue depth *exactly* and thus there's no deadlock in this case.
> 
> However this constraint can be fragile. Disable iopoll when one dio need
> to be split into multiple bios.Though blkdev fs may not suffer this issue,
> still it may not make much sense to iopoll for big IO, since iopoll is
> initially for small size, latency sensitive IO.
> 
> Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
> ---
>  fs/block_dev.c       |  9 +++++++++
>  fs/iomap/direct-io.c | 10 ++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 9e84b1928b94..ed3f46e8fa91 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -436,6 +436,15 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
>  			break;
>  		}
>  
> +		/*
> +		 * The current dio needs to be split into multiple bios here.
> +		 * iopoll for split bio will cause subtle trouble such as
> +		 * hang when doing sync polling, while iopoll is initially
> +		 * for small size, latency sensitive IO. Thus disable iopoll
> +		 * if split needed.
> +		 */
> +		iocb->ki_flags &= ~IOCB_HIPRI;
> +
>  		if (!dio->multi_bio) {
>  			/*
>  			 * AIO needs an extra reference to ensure the dio
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 933f234d5bec..396ac0f91a43 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -309,6 +309,16 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
>  		copied += n;
>  
>  		nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
> +		/*
> +		 * The current dio needs to be split into multiple bios here.
> +		 * iopoll for split bio will cause subtle trouble such as
> +		 * hang when doing sync polling, while iopoll is initially
> +		 * for small size, latency sensitive IO. Thus disable iopoll
> +		 * if split needed.
> +		 */
> +		if (nr_pages)
> +			dio->iocb->ki_flags &= ~IOCB_HIPRI;

Hmm, I was about to ask what happens if the user's HIPRI request gets
downgraded from polling mode, but the manpage doesn't say anything about
the kernel having to return an error if it can't use polling mode, so I
guess downgrading is...fine?

Well, maybe it isn't, since this also results in a downgrade when I send
a 1MB polled pwrite to my otherwise idle MegaSSD that has thousands of
queue depth.  I think?  <shrug> I'm not the one who uses polling mode,
fwiw.

--D

> +
>  		iomap_dio_submit_bio(dio, iomap, bio, pos);
>  		pos += n;
>  	} while (nr_pages);
> -- 
> 2.27.0
>
Jingbo Xu Nov. 18, 2020, 1:56 a.m. UTC | #2
On 11/18/20 1:37 AM, Darrick J. Wong wrote:
> On Tue, Nov 17, 2020 at 03:56:25PM +0800, Jeffle Xu wrote:
>> Both blkdev fs and iomap-based fs (ext4, xfs, etc.) currently support
> $ ./scripts/get_maintainer.pl fs/iomap/direct-io.c
> Christoph Hellwig <hch@infradead.org> (supporter:IOMAP FILESYSTEM LIBRARY)
> "Darrick J. Wong" <darrick.wong@oracle.com> (supporter:IOMAP FILESYSTEM LIBRARY)
> linux-xfs@vger.kernel.org (supporter:IOMAP FILESYSTEM LIBRARY)
> linux-fsdevel@vger.kernel.org (supporter:IOMAP FILESYSTEM LIBRARY)
> linux-kernel@vger.kernel.org (open list)
>
> Please cc both iomap maintainers and the appropriate lists when you
> propose changes to fs/iomap/.  At a bare minimum cc linux-fsdevel for
> changes under fs/.
Got it.
>
>> sync iopoll. One single bio can contain at most BIO_MAX_PAGES, i.e. 256
>> bio_vec. If the input iov_iter contains more than 256 segments, then
>> one dio will be split into multiple bios, which may cause potential
>> deadlock for sync iopoll.
>>
>> When it comes to sync iopoll, the bio is submitted without REQ_NOWAIT
>> flag set and the process may hang in blk_mq_get_tag() if the dio needs
>> to be split into multiple bios and thus can rapidly exhausts the queue
>> depth. The process has to wait for the completion of the previously
>> allocated requests, which should be reaped by the following sync
>> polling, and thus causing a potential deadlock.
>>
>> In fact there's a subtle difference of handling of HIPRI IO between
>> blkdev fs and iomap-based fs, when dio need to be split into multiple
>> bios. blkdev fs will set REQ_HIPRI for only the last split bio, leaving
>> the previous bios queued into normal hardware queues, and not causing
>> the trouble described above. iomap-based fs will set REQ_HIPRI for all
>> split bios, and thus may cause the potential deadlock described above.
>>
>> Noted that though the analysis described above, currently blkdev fs and
>> iomap-based fs won't trigger this potential deadlock. Because only
>> preadv2(2)/pwritev2(2) are capable of *sync* polling as only these two
>> can set RWF_NOWAIT.

s/RWF_NOWAIT/RWF_HIPRI


>>   Currently the maximum number of iovecs of one single
>> preadv2(2)/pwritev2(2) call is UIO_MAXIOV, i.e. 1024, while the minimum
>> queue depth is BLKDEV_MIN_RQ i.e. 4. That means one
>> preadv2(2)/pwritev2(2) call can submit at most 4 bios, which will fill
>> up the queue depth *exactly* and thus there's no deadlock in this case.
>>
>> However this constraint can be fragile. Disable iopoll when one dio need
>> to be split into multiple bios.Though blkdev fs may not suffer this issue,
>> still it may not make much sense to iopoll for big IO, since iopoll is
>> initially for small size, latency sensitive IO.
>>
>> Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
>> ---
>>   fs/block_dev.c       |  9 +++++++++
>>   fs/iomap/direct-io.c | 10 ++++++++++
>>   2 files changed, 19 insertions(+)
>>
>> diff --git a/fs/block_dev.c b/fs/block_dev.c
>> index 9e84b1928b94..ed3f46e8fa91 100644
>> --- a/fs/block_dev.c
>> +++ b/fs/block_dev.c
>> @@ -436,6 +436,15 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
>>   			break;
>>   		}
>>   
>> +		/*
>> +		 * The current dio needs to be split into multiple bios here.
>> +		 * iopoll for split bio will cause subtle trouble such as
>> +		 * hang when doing sync polling, while iopoll is initially
>> +		 * for small size, latency sensitive IO. Thus disable iopoll
>> +		 * if split needed.
>> +		 */
>> +		iocb->ki_flags &= ~IOCB_HIPRI;
>> +
>>   		if (!dio->multi_bio) {
>>   			/*
>>   			 * AIO needs an extra reference to ensure the dio
>> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
>> index 933f234d5bec..396ac0f91a43 100644
>> --- a/fs/iomap/direct-io.c
>> +++ b/fs/iomap/direct-io.c
>> @@ -309,6 +309,16 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
>>   		copied += n;
>>   
>>   		nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
>> +		/*
>> +		 * The current dio needs to be split into multiple bios here.
>> +		 * iopoll for split bio will cause subtle trouble such as
>> +		 * hang when doing sync polling, while iopoll is initially
>> +		 * for small size, latency sensitive IO. Thus disable iopoll
>> +		 * if split needed.
>> +		 */
>> +		if (nr_pages)
>> +			dio->iocb->ki_flags &= ~IOCB_HIPRI;
> Hmm, I was about to ask what happens if the user's HIPRI request gets
> downgraded from polling mode, but the manpage doesn't say anything about
> the kernel having to return an error if it can't use polling mode, so I
> guess downgrading is...fine?

Yes if the block device doesn't support iopoll, then HIPRI pread/pwrite 
will automatically

gets downgraded from polling mode.


> Well, maybe it isn't, since this also results in a downgrade when I send
> a 1MB polled pwrite to my otherwise idle MegaSSD that has thousands of
> queue depth.  I think?  <shrug> I'm not the one who uses polling mode,
> fwiw.

Indeed that's true. iopoll gets disabled once the dio gets split,
even though the block device has thousands of queue depth. This
design is chose just because it is the simplest one..., though
this one should have no big problem.

As I described in the comment, iopoll is initially for small size
IO. We have ever tested the latency of Optane SSD

bs | latency (us)

---- | ----

read 4k | 14

read 128k | 68

write 4k | 17

write 128k | 75


The overhead of interrupt is about several (under 10) microseconds. The 
overhead of

interrupt when doing 128k IO may not be as important as that of small 
size IO, thus

the performance gain of iopoll will decreased a lot at least for 128k IO.


In my computer, @max_sectors of one nvme SSD is 128k, so the split bio 
is much

likely larger than 128k, in which case the performance loss should be 
acceptable

(though I have not test it).


>
>> +
>>   		iomap_dio_submit_bio(dio, iomap, bio, pos);
>>   		pos += n;
>>   	} while (nr_pages);
>> -- 
>> 2.27.0
>>
Christoph Hellwig Nov. 19, 2020, 5:55 p.m. UTC | #3
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 933f234d5bec..396ac0f91a43 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -309,6 +309,16 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
>  		copied += n;
>  
>  		nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
> +		/*
> +		 * The current dio needs to be split into multiple bios here.
> +		 * iopoll for split bio will cause subtle trouble such as
> +		 * hang when doing sync polling, while iopoll is initially
> +		 * for small size, latency sensitive IO. Thus disable iopoll
> +		 * if split needed.
> +		 */
> +		if (nr_pages)
> +			dio->iocb->ki_flags &= ~IOCB_HIPRI;

I think this is confusing two things.  One is that we don't handle
polling well when there are multiple bios.  For this I think we should
only call bio_set_polled when we know there is a single bio.  But it
has nothing to do with a bio being split, as we can't know that at this
level.
Jingbo Xu Nov. 20, 2020, 10:06 a.m. UTC | #4
On 11/20/20 1:55 AM, Christoph Hellwig wrote:
>> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
>> index 933f234d5bec..396ac0f91a43 100644
>> --- a/fs/iomap/direct-io.c
>> +++ b/fs/iomap/direct-io.c
>> @@ -309,6 +309,16 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
>>   		copied += n;
>>   
>>   		nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
>> +		/*
>> +		 * The current dio needs to be split into multiple bios here.
>> +		 * iopoll for split bio will cause subtle trouble such as
>> +		 * hang when doing sync polling, while iopoll is initially
>> +		 * for small size, latency sensitive IO. Thus disable iopoll
>> +		 * if split needed.
>> +		 */
>> +		if (nr_pages)
>> +			dio->iocb->ki_flags &= ~IOCB_HIPRI;
> I think this is confusing two things.

Indeed there's two level of split concerning this issue when doing sync 
iopoll.


The first is that one bio got split in block-core, and patch 1 of this 
patch set just fixes this.


Second is that one dio got split into multiple bios in fs layer, and 
patch 2 fixes this.


>   One is that we don't handle
> polling well when there are multiple bios.  For this I think we should
> only call bio_set_polled when we know there is a single bio.


How about the following patch:


--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -60,12 +60,12 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)
  EXPORT_SYMBOL_GPL(iomap_dio_iopoll);

  static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap 
*iomap,
-               struct bio *bio, loff_t pos)
+               struct bio *bio, loff_t pos, bool split)
  {
         atomic_inc(&dio->ref);

         if (dio->iocb->ki_flags & IOCB_HIPRI)
-               bio_set_polled(bio, dio->iocb);
+               bio_set_polled(bio, dio->iocb, split);

         dio->submit.last_queue = bdev_get_queue(iomap->bdev);
         if (dio->dops && dio->dops->submit_io)
@@ -214,6 +214,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, 
loff_t length,
         int nr_pages, ret = 0;
         size_t copied = 0;
         size_t orig_count;
+       bool split = false;

         if ((pos | length | align) & ((1 << blkbits) - 1))
                 return -EINVAL;
@@ -309,7 +310,17 @@ iomap_dio_bio_actor(struct inode *inode, loff_t 
pos, loff_t length,
                 copied += n;

                 nr_pages = iov_iter_npages(dio->submit.iter, 
BIO_MAX_PAGES);
-               iomap_dio_submit_bio(dio, iomap, bio, pos);
+               /*
+                * The current dio needs to be split into multiple bios 
here.
+                * iopoll for split bio will cause subtle trouble such as
+                * hang when doing sync polling, while iopoll is initially
+                * for small size, latency sensitive IO. Thus disable iopoll
+                * if split needed.
+                */
+               if (nr_pages)
+                       split = true;
+
+               iomap_dio_submit_bio(dio, iomap, bio, pos, split);
                 pos += n;
         } while (nr_pages);

diff --git a/include/linux/bio.h b/include/linux/bio.h
index c6d765382926..21f772f98878 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -806,9 +806,11 @@ static inline int bio_integrity_add_page(struct bio 
*bio, struct page *page,
   * must be found by the caller. This is different than IRQ driven IO, 
where
   * it's safe to wait for IO to complete.
   */
-static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
+static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb, 
bool split)
  {
-       bio->bi_opf |= REQ_HIPRI;
+       if (!split)
+               bio->bi_opf |= REQ_HIPRI;
+
         if (!is_sync_kiocb(kiocb))
                 bio->bi_opf |= REQ_NOWAIT;
  }


After this patch, bio will be polled only one dio maps to one single bio.

Noted that this change applies to both sync and async IO, though async 
routine doesn't

suffer the hang described in this patch set. Since the performance gain 
of iopoll may be

trivial when one dio got split, also disable iopoll for async routine.


We need keep REQ_NOWAIT for async routine even when the dio split happened,

because io_uring doesn't expect blocking. Though the original REQ_NOWAIT

should gets from iocb->ki_flags & IOCB_NOWAIT. Currently iomap doesn't 
inherit

bio->bi_opf's REQ_NOWAIT from iocb->ki_flags's IOCB_NOWAI. This bug should

be fixed by 
https://lore.kernel.org/linux-fsdevel/1605685931-207023-1-git-send-email-haoxu@linux.alibaba.com/T/#t


Maybe we could include this fix (of missing inheritance of IOCB_NOWAI) 
into this patch

set and then refactor the fix I mentioned in this patch?
Christoph Hellwig Nov. 24, 2020, 11:25 a.m. UTC | #5
On Fri, Nov 20, 2020 at 06:06:54PM +0800, JeffleXu wrote:
> 
> On 11/20/20 1:55 AM, Christoph Hellwig wrote:
> > > diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> > > index 933f234d5bec..396ac0f91a43 100644
> > > --- a/fs/iomap/direct-io.c
> > > +++ b/fs/iomap/direct-io.c
> > > @@ -309,6 +309,16 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
> > >   		copied += n;
> > >   		nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
> > > +		/*
> > > +		 * The current dio needs to be split into multiple bios here.
> > > +		 * iopoll for split bio will cause subtle trouble such as
> > > +		 * hang when doing sync polling, while iopoll is initially
> > > +		 * for small size, latency sensitive IO. Thus disable iopoll
> > > +		 * if split needed.
> > > +		 */
> > > +		if (nr_pages)
> > > +			dio->iocb->ki_flags &= ~IOCB_HIPRI;
> > I think this is confusing two things.
> 
> Indeed there's two level of split concerning this issue when doing sync
> iopoll.
> 
> 
> The first is that one bio got split in block-core, and patch 1 of this patch
> set just fixes this.
> 
> 
> Second is that one dio got split into multiple bios in fs layer, and patch 2
> fixes this.
> 
> 
> >   One is that we don't handle
> > polling well when there are multiple bios.  For this I think we should
> > only call bio_set_polled when we know there is a single bio.
> 
> 
> How about the following patch:
> 
> 
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -60,12 +60,12 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)
> ??EXPORT_SYMBOL_GPL(iomap_dio_iopoll);
> 
> ??static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap
> *iomap,
> -???????????????????????????? struct bio *bio, loff_t pos)
> +???????????????????????????? struct bio *bio, loff_t pos, bool split)

This seems pretty messed up by your mailer and I have a hard time
reading it.  Can you resend it?
Jingbo Xu Nov. 25, 2020, 7:03 a.m. UTC | #6
Sorry for that, I will send a new version later.

On 11/24/20 7:25 PM, Christoph Hellwig wrote:
> On Fri, Nov 20, 2020 at 06:06:54PM +0800, JeffleXu wrote:
>>
>> On 11/20/20 1:55 AM, Christoph Hellwig wrote:
>>>> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
>>>> index 933f234d5bec..396ac0f91a43 100644
>>>> --- a/fs/iomap/direct-io.c
>>>> +++ b/fs/iomap/direct-io.c
>>>> @@ -309,6 +309,16 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
>>>>   		copied += n;
>>>>   		nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
>>>> +		/*
>>>> +		 * The current dio needs to be split into multiple bios here.
>>>> +		 * iopoll for split bio will cause subtle trouble such as
>>>> +		 * hang when doing sync polling, while iopoll is initially
>>>> +		 * for small size, latency sensitive IO. Thus disable iopoll
>>>> +		 * if split needed.
>>>> +		 */
>>>> +		if (nr_pages)
>>>> +			dio->iocb->ki_flags &= ~IOCB_HIPRI;
>>> I think this is confusing two things.
>>
>> Indeed there's two level of split concerning this issue when doing sync
>> iopoll.
>>
>>
>> The first is that one bio got split in block-core, and patch 1 of this patch
>> set just fixes this.
>>
>>
>> Second is that one dio got split into multiple bios in fs layer, and patch 2
>> fixes this.
>>
>>
>>>   One is that we don't handle
>>> polling well when there are multiple bios.  For this I think we should
>>> only call bio_set_polled when we know there is a single bio.
>>
>>
>> How about the following patch:
>>
>>
>> --- a/fs/iomap/direct-io.c
>> +++ b/fs/iomap/direct-io.c
>> @@ -60,12 +60,12 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)
>> ??EXPORT_SYMBOL_GPL(iomap_dio_iopoll);
>>
>> ??static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap
>> *iomap,
>> -???????????????????????????? struct bio *bio, loff_t pos)
>> +???????????????????????????? struct bio *bio, loff_t pos, bool split)
> 
> This seems pretty messed up by your mailer and I have a hard time
> reading it.  Can you resend it?
>
diff mbox series

Patch

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9e84b1928b94..ed3f46e8fa91 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -436,6 +436,15 @@  __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
 			break;
 		}
 
+		/*
+		 * The current dio needs to be split into multiple bios here.
+		 * iopoll for split bio will cause subtle trouble such as
+		 * hang when doing sync polling, while iopoll is initially
+		 * for small size, latency sensitive IO. Thus disable iopoll
+		 * if split needed.
+		 */
+		iocb->ki_flags &= ~IOCB_HIPRI;
+
 		if (!dio->multi_bio) {
 			/*
 			 * AIO needs an extra reference to ensure the dio
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 933f234d5bec..396ac0f91a43 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -309,6 +309,16 @@  iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
 		copied += n;
 
 		nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
+		/*
+		 * The current dio needs to be split into multiple bios here.
+		 * iopoll for split bio will cause subtle trouble such as
+		 * hang when doing sync polling, while iopoll is initially
+		 * for small size, latency sensitive IO. Thus disable iopoll
+		 * if split needed.
+		 */
+		if (nr_pages)
+			dio->iocb->ki_flags &= ~IOCB_HIPRI;
+
 		iomap_dio_submit_bio(dio, iomap, bio, pos);
 		pos += n;
 	} while (nr_pages);