From: Ming Lei <ming.lei@redhat.com>
To: Pavel Begunkov <asml.silence@gmail.com>
Cc: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@infradead.org>,
Matthew Wilcox <willy@infradead.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
"Darrick J . Wong" <darrick.wong@oracle.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Jonathan Corbet <corbet@lwn.net>,
linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
target-devel@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-doc@vger.kernel.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH v3 6/7] bio: add a helper calculating nr segments to alloc
Date: Mon, 11 Jan 2021 10:57:10 +0800 [thread overview]
Message-ID: <20210111025710.GG4147870@T590> (raw)
In-Reply-To: <cde94f6cc32bd8a899129575678c4195f7cb187b.1610170479.git.asml.silence@gmail.com>
On Sat, Jan 09, 2021 at 04:03:02PM +0000, Pavel Begunkov wrote:
> Add a helper function calculating the number of bvec segments we need to
> allocate to construct a bio. It doesn't change anything functionally,
> but will be used to not duplicate special cases in the future.
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
> fs/block_dev.c | 7 ++++---
> fs/iomap/direct-io.c | 9 ++++-----
> include/linux/bio.h | 10 ++++++++++
> 3 files changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 3b8963e228a1..6f5bd9950baf 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -416,7 +416,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
> dio->size += bio->bi_iter.bi_size;
> pos += bio->bi_iter.bi_size;
>
> - nr_pages = iov_iter_npages(iter, BIO_MAX_PAGES);
> + nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_PAGES);
> if (!nr_pages) {
> bool polled = false;
>
> @@ -481,9 +481,10 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
> {
> int nr_pages;
>
> - nr_pages = iov_iter_npages(iter, BIO_MAX_PAGES + 1);
> - if (!nr_pages)
> + if (!iov_iter_count(iter))
> return 0;
> +
> + nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_PAGES + 1);
> if (is_sync_kiocb(iocb) && nr_pages <= BIO_MAX_PAGES)
> return __blkdev_direct_IO_simple(iocb, iter, nr_pages);
>
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 933f234d5bec..ea1e8f696076 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -250,11 +250,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
> orig_count = iov_iter_count(dio->submit.iter);
> iov_iter_truncate(dio->submit.iter, length);
>
> - nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
> - if (nr_pages <= 0) {
> - ret = nr_pages;
> + if (!iov_iter_count(dio->submit.iter))
> goto out;
> - }
>
> if (need_zeroout) {
> /* zero out from the start of the block to the write offset */
> @@ -263,6 +260,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
> iomap_dio_zero(dio, iomap, pos - pad, pad);
> }
>
> + nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_PAGES);
> do {
> size_t n;
> if (dio->error) {
> @@ -308,7 +306,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
> dio->size += n;
> copied += n;
>
> - nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
> + nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter,
> + BIO_MAX_PAGES);
> iomap_dio_submit_bio(dio, iomap, bio, pos);
> pos += n;
> } while (nr_pages);
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index 1edda614f7ce..d8f9077c43ef 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -10,6 +10,7 @@
> #include <linux/ioprio.h>
> /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */
> #include <linux/blk_types.h>
> +#include <linux/uio.h>
>
> #define BIO_DEBUG
>
> @@ -441,6 +442,15 @@ static inline void bio_wouldblock_error(struct bio *bio)
> bio_endio(bio);
> }
>
> +/*
> + * Calculate number of bvec segments that should be allocated to fit data
> + * pointed by @iter.
> + */
> +static inline int bio_iov_vecs_to_alloc(struct iov_iter *iter, int max_segs)
> +{
> + return iov_iter_npages(iter, max_segs);
> +}
> +
> struct request_queue;
>
> extern int submit_bio_wait(struct bio *bio);
> --
> 2.24.0
>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
--
Ming
next prev parent reply other threads:[~2021-01-11 2:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-09 16:02 [PATCH v3 0/7] no-copy bvec Pavel Begunkov
2021-01-09 16:02 ` [PATCH v3 1/7] splice: don't generate zero-len segement bvecs Pavel Begunkov
2021-01-11 2:48 ` Ming Lei
2021-01-09 16:02 ` [PATCH v3 2/7] bvec/iter: disallow zero-length segment bvecs Pavel Begunkov
2021-01-11 2:49 ` Ming Lei
2021-01-09 16:02 ` [PATCH v3 3/7] block/psi: remove PSI annotations from direct IO Pavel Begunkov
2021-01-11 2:52 ` Ming Lei
2021-01-09 16:03 ` [PATCH v3 4/7] target/file: allocate the bvec array as part of struct target_core_file_cmd Pavel Begunkov
2021-01-11 2:53 ` Ming Lei
2021-01-09 16:03 ` [PATCH v3 5/7] iov_iter: optimise bvec iov_iter_advance() Pavel Begunkov
2021-01-11 2:55 ` Ming Lei
2021-01-09 16:03 ` [PATCH v3 6/7] bio: add a helper calculating nr segments to alloc Pavel Begunkov
2021-01-11 2:57 ` Ming Lei [this message]
2021-01-09 16:03 ` [PATCH v3 7/7] bio: don't copy bvec for direct IO Pavel Begunkov
2021-01-11 3:00 ` Ming Lei
2021-01-25 15:58 ` [PATCH v3 0/7] no-copy bvec Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210111025710.GG4147870@T590 \
--to=ming.lei@redhat.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=corbet@lwn.net \
--cc=darrick.wong@oracle.com \
--cc=hannes@cmpxchg.org \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=io-uring@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=target-devel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.