Re: [PATCH v1 6/6] block/iomap: don't copy bvec for direct IO

Pavel Begunkov
2020-12-15T01:19:40Z

On 15/12/2020 01:09, Dave Chinner wrote:
> On Tue, Dec 15, 2020 at 12:20:25AM +0000, Pavel Begunkov wrote:
>> The block layer spends quite a while in blkdev_direct_IO() to copy and
>> initialise bio's bvec. However, if we've already got a bvec in the input
>> iterator it might be reused in some cases, i.e. when new
>> ITER_BVEC_FLAG_FIXED flag is set. Simple tests show considerable
>> performance boost, and it also reduces memory footprint.
>>
>> Suggested-by: Matthew Wilcox <willy@infradead.org>
>> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
>> ---
>> Documentation/filesystems/porting.rst | 9 ++++
>> block/bio.c | 64 +++++++++++----------------
>> include/linux/bio.h | 3 ++
>> 3 files changed, 38 insertions(+), 38 deletions(-)
>
> This doesn't touch iomap code, so the title of the patch seems
> wrong...

yeah, should be bio.

>
>> +For bvec based itererators bio_iov_iter_get_pages() now doesn't copy bvecs but
>> +uses the one provided. Anyone issuing kiocb-I/O should ensure that the bvec and
>> +page references stay until I/O has completed, i.e. until ->ki_complete() has
>> +been called or returned with non -EIOCBQUEUED code.
>
> This is hard to follow. Perhaps:
>
> bio_iov_iter_get_pages() uses the bvecs provided for bvec based
> iterators rather than copying them. Hence anyone issuing kiocb based
> IO needs to ensure the bvecs and pages stay referenced until the
> submitted I/O is completed by a call to ->ki_complete() or returns
> with an error other than -EIOCBQUEUED.

Agree, that's easier to read, thanks

>
>> diff --git a/include/linux/bio.h b/include/linux/bio.h
>> index 2a9f3f0bbe0a..337f4280b639 100644
>> --- a/include/linux/bio.h
>> +++ b/include/linux/bio.h
>> @@ -444,6 +444,9 @@ static inline void bio_wouldblock_error(struct bio *bio)
>>
>> static inline int bio_iov_vecs_to_alloc(struct iov_iter *iter, int max_segs)
>> {
>> + /* reuse iter->bvec */
>> + if (iov_iter_is_bvec(iter))
>> + return 0;
>> return iov_iter_npages(iter, max_segs);
>
> Ah, I'm a blind idiot... :/
>
> Cheers,
>
> Dave.
>

--
Pavel Begunkov