Re: [PATCH v2 1/2] iov_iter: optimise iov_iter_npages for bvec

From: Matthew Wilcox
Date: Fri Nov 20 2020 - 08:13:58 EST


On Fri, Nov 20, 2020 at 01:00:37PM +0000, Pavel Begunkov wrote:
> On 20/11/2020 12:39, Matthew Wilcox wrote:
> > On Fri, Nov 20, 2020 at 08:14:29AM +0000, Christoph Hellwig wrote:
> >> On Fri, Nov 20, 2020 at 02:54:57AM +0000, Matthew Wilcox wrote:
> >>> On Fri, Nov 20, 2020 at 02:25:08AM +0000, Pavel Begunkov wrote:
> >>>> On 20/11/2020 02:22, Ming Lei wrote:
> >>>>> iov_iter_npages(bvec) still can be improved a bit by the following way:
> >>>>
> >>>> Yep, was doing exactly that, +a couple of other places that are in my way.
> >>>
> >>> Are you optimising the right thing here? Assuming you're looking at
> >>> the one in do_blockdev_direct_IO(), wouldn't we be better off figuring
> >>> out how to copy the bvecs directly from the iov_iter into the bio
> >>> rather than calling dio_bio_add_page() for each page?
> >>
> >> Which is most effectively done by stopping to to use *blockdev_direct_IO
> >> and switching to iomap instead :)
> >
> > But iomap still calls iov_iter_npages(). So maybe we need something like
> > this ...
>
> Yep, all that are not mutually exclusive optimisations.
> Why `return 1`? It seems to be used later in bio_alloc(nr_pages)

because 0 means "no pages". It does no harm to allocate one biovec
that we then don't use.

> > - nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
> > + nr_pages = bio_iov_iter_npages(dio->submit.iter);
> > if (nr_pages <= 0) {
^^^^^^^^^^^^^

> > - nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
> > + nr_pages = bio_iov_iter_npages(dio->submit.iter);
> > iomap_dio_submit_bio(dio, iomap, bio, pos);
> > pos += n;
> > } while (nr_pages);
^^^^^^^^