* [PATCH V2 0/2] block: add bio_iov_iter_nvecs for figuring out nr_vecs
@ 2020-12-03 2:29 Ming Lei
2020-12-03 2:29 ` [PATCH V2 1/2] " Ming Lei
2020-12-03 2:29 ` [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs Ming Lei
0 siblings, 2 replies; 7+ messages in thread
From: Ming Lei @ 2020-12-03 2:29 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Ming Lei, Pavel Begunkov, Christoph Hellwig,
Matthew Wilcox, linux-fsdevel
Hi,
Add add bio_iov_iter_nvecs for figuring out nr_vecs, so that we can
avoid iov_iter_npages() for bvec iter.
V2:
- split out renaming part into one patch
Ming Lei (2):
block: add bio_iov_iter_nvecs for figuring out nr_vecs
block: rename the local variable for holding return value of
bio_iov_iter_nvecs
fs/block_dev.c | 30 +++++++++++++++---------------
fs/iomap/direct-io.c | 14 +++++++-------
include/linux/bio.h | 10 ++++++++++
3 files changed, 32 insertions(+), 22 deletions(-)
Cc: Pavel Begunkov <asml.silence@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org
--
2.28.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH V2 1/2] block: add bio_iov_iter_nvecs for figuring out nr_vecs
2020-12-03 2:29 [PATCH V2 0/2] block: add bio_iov_iter_nvecs for figuring out nr_vecs Ming Lei
@ 2020-12-03 2:29 ` Ming Lei
2020-12-03 6:46 ` Hannes Reinecke
2020-12-09 8:31 ` Christoph Hellwig
2020-12-03 2:29 ` [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs Ming Lei
1 sibling, 2 replies; 7+ messages in thread
From: Ming Lei @ 2020-12-03 2:29 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Ming Lei, Pavel Begunkov, Christoph Hellwig,
Matthew Wilcox, linux-fsdevel
Pavel reported that iov_iter_npages is a bit heavy in case of bvec
iter.
Turns out it isn't necessary to iterate every page in the bvec iter,
and we call iov_iter_npages() just for figuring out how many bio
vecs need to be allocated. And we can simply map each vector in bvec iter
to bio's vec, so just return iter->nr_segs from bio_iov_iter_nvecs() for
bvec iter.
This patch is based on Mathew's post:
https://lore.kernel.org/linux-block/20201120123931.GN29991@casper.infradead.org/
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Christoph Hellwig <hch@infradead.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
fs/block_dev.c | 4 ++--
fs/iomap/direct-io.c | 4 ++--
include/linux/bio.h | 10 ++++++++++
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9e56ee1f2652..fbcc900229af 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -417,7 +417,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_iter_nvecs(iter, BIO_MAX_PAGES);
if (!nr_pages) {
bool polled = false;
@@ -482,7 +482,7 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
{
int nr_pages;
- nr_pages = iov_iter_npages(iter, BIO_MAX_PAGES + 1);
+ nr_pages = bio_iov_iter_nvecs(iter, BIO_MAX_PAGES + 1);
if (!nr_pages)
return 0;
if (is_sync_kiocb(iocb) && nr_pages <= BIO_MAX_PAGES)
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 933f234d5bec..0635469e811a 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -250,7 +250,7 @@ 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);
+ nr_pages = bio_iov_iter_nvecs(dio->submit.iter, BIO_MAX_PAGES);
if (nr_pages <= 0) {
ret = nr_pages;
goto out;
@@ -308,7 +308,7 @@ 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_iter_nvecs(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..8a7f44006f65 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
@@ -820,4 +821,13 @@ static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
bio->bi_opf |= REQ_NOWAIT;
}
+static inline int bio_iov_iter_nvecs(const struct iov_iter *i, int maxvecs)
+{
+ if (!iov_iter_count(i))
+ return 0;
+ if (iov_iter_is_bvec(i))
+ return min_t(int, maxvecs, i->nr_segs);
+ return iov_iter_npages(i, maxvecs);
+}
+
#endif /* __LINUX_BIO_H */
--
2.28.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs
2020-12-03 2:29 [PATCH V2 0/2] block: add bio_iov_iter_nvecs for figuring out nr_vecs Ming Lei
2020-12-03 2:29 ` [PATCH V2 1/2] " Ming Lei
@ 2020-12-03 2:29 ` Ming Lei
2020-12-03 6:47 ` Hannes Reinecke
2020-12-09 8:32 ` Christoph Hellwig
1 sibling, 2 replies; 7+ messages in thread
From: Ming Lei @ 2020-12-03 2:29 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Ming Lei, Pavel Begunkov, Christoph Hellwig,
Matthew Wilcox, linux-fsdevel
Now the local variable for holding return value of bio_iov_iter_nvecs is
'nr_pages', which is a bit misleading, and the actual meaning is number
of bio vectors, and it is also used for this way.
So rename the local variable, and no function change.
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Christoph Hellwig <hch@infradead.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
fs/block_dev.c | 30 +++++++++++++++---------------
fs/iomap/direct-io.c | 14 +++++++-------
2 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index fbcc900229af..d699f3af1a09 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -215,7 +215,7 @@ static void blkdev_bio_end_io_simple(struct bio *bio)
static ssize_t
__blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
- int nr_pages)
+ int nr_vecs)
{
struct file *file = iocb->ki_filp;
struct block_device *bdev = I_BDEV(bdev_file_inode(file));
@@ -230,16 +230,16 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
(bdev_logical_block_size(bdev) - 1))
return -EINVAL;
- if (nr_pages <= DIO_INLINE_BIO_VECS)
+ if (nr_vecs <= DIO_INLINE_BIO_VECS)
vecs = inline_vecs;
else {
- vecs = kmalloc_array(nr_pages, sizeof(struct bio_vec),
+ vecs = kmalloc_array(nr_vecs, sizeof(struct bio_vec),
GFP_KERNEL);
if (!vecs)
return -ENOMEM;
}
- bio_init(&bio, vecs, nr_pages);
+ bio_init(&bio, vecs, nr_vecs);
bio_set_dev(&bio, bdev);
bio.bi_iter.bi_sector = pos >> 9;
bio.bi_write_hint = iocb->ki_hint;
@@ -350,7 +350,7 @@ static void blkdev_bio_end_io(struct bio *bio)
}
static ssize_t
-__blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
+__blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_vecs)
{
struct file *file = iocb->ki_filp;
struct inode *inode = bdev_file_inode(file);
@@ -368,7 +368,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
(bdev_logical_block_size(bdev) - 1))
return -EINVAL;
- bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, &blkdev_dio_pool);
+ bio = bio_alloc_bioset(GFP_KERNEL, nr_vecs, &blkdev_dio_pool);
dio = container_of(bio, struct blkdev_dio, bio);
dio->is_sync = is_sync = is_sync_kiocb(iocb);
@@ -417,8 +417,8 @@ __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 = bio_iov_iter_nvecs(iter, BIO_MAX_PAGES);
- if (!nr_pages) {
+ nr_vecs = bio_iov_iter_nvecs(iter, BIO_MAX_PAGES);
+ if (!nr_vecs) {
bool polled = false;
if (iocb->ki_flags & IOCB_HIPRI) {
@@ -448,7 +448,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
}
submit_bio(bio);
- bio = bio_alloc(GFP_KERNEL, nr_pages);
+ bio = bio_alloc(GFP_KERNEL, nr_vecs);
}
if (!is_poll)
@@ -480,15 +480,15 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
static ssize_t
blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
{
- int nr_pages;
+ int nr_vecs;
- nr_pages = bio_iov_iter_nvecs(iter, BIO_MAX_PAGES + 1);
- if (!nr_pages)
+ nr_vecs = bio_iov_iter_nvecs(iter, BIO_MAX_PAGES + 1);
+ if (!nr_vecs)
return 0;
- if (is_sync_kiocb(iocb) && nr_pages <= BIO_MAX_PAGES)
- return __blkdev_direct_IO_simple(iocb, iter, nr_pages);
+ if (is_sync_kiocb(iocb) && nr_vecs <= BIO_MAX_PAGES)
+ return __blkdev_direct_IO_simple(iocb, iter, nr_vecs);
- return __blkdev_direct_IO(iocb, iter, min(nr_pages, BIO_MAX_PAGES));
+ return __blkdev_direct_IO(iocb, iter, min(nr_vecs, BIO_MAX_PAGES));
}
static __init int blkdev_init(void)
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 0635469e811a..cc779ecc8144 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -211,7 +211,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
struct bio *bio;
bool need_zeroout = false;
bool use_fua = false;
- int nr_pages, ret = 0;
+ int nr_vecs, ret = 0;
size_t copied = 0;
size_t orig_count;
@@ -250,9 +250,9 @@ 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 = bio_iov_iter_nvecs(dio->submit.iter, BIO_MAX_PAGES);
- if (nr_pages <= 0) {
- ret = nr_pages;
+ nr_vecs = bio_iov_iter_nvecs(dio->submit.iter, BIO_MAX_PAGES);
+ if (nr_vecs <= 0) {
+ ret = nr_vecs;
goto out;
}
@@ -271,7 +271,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
goto out;
}
- bio = bio_alloc(GFP_KERNEL, nr_pages);
+ bio = bio_alloc(GFP_KERNEL, nr_vecs);
bio_set_dev(bio, iomap->bdev);
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
bio->bi_write_hint = dio->iocb->ki_hint;
@@ -308,10 +308,10 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
dio->size += n;
copied += n;
- nr_pages = bio_iov_iter_nvecs(dio->submit.iter, BIO_MAX_PAGES);
+ nr_vecs = bio_iov_iter_nvecs(dio->submit.iter, BIO_MAX_PAGES);
iomap_dio_submit_bio(dio, iomap, bio, pos);
pos += n;
- } while (nr_pages);
+ } while (nr_vecs);
/*
* We need to zeroout the tail of a sub-block write if the extent type
--
2.28.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/2] block: add bio_iov_iter_nvecs for figuring out nr_vecs
2020-12-03 2:29 ` [PATCH V2 1/2] " Ming Lei
@ 2020-12-03 6:46 ` Hannes Reinecke
2020-12-09 8:31 ` Christoph Hellwig
1 sibling, 0 replies; 7+ messages in thread
From: Hannes Reinecke @ 2020-12-03 6:46 UTC (permalink / raw)
To: Ming Lei, Jens Axboe
Cc: linux-block, Pavel Begunkov, Christoph Hellwig, Matthew Wilcox,
linux-fsdevel
On 12/3/20 3:29 AM, Ming Lei wrote:
> Pavel reported that iov_iter_npages is a bit heavy in case of bvec
> iter.
>
> Turns out it isn't necessary to iterate every page in the bvec iter,
> and we call iov_iter_npages() just for figuring out how many bio
> vecs need to be allocated. And we can simply map each vector in bvec iter
> to bio's vec, so just return iter->nr_segs from bio_iov_iter_nvecs() for
> bvec iter.
>
> This patch is based on Mathew's post:
>
> https://lore.kernel.org/linux-block/20201120123931.GN29991@casper.infradead.org/
>
> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
> Reviewed-by: Christoph Hellwig <hch@infradead.org>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: linux-fsdevel@vger.kernel.org
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> fs/block_dev.c | 4 ++--
> fs/iomap/direct-io.c | 4 ++--
> include/linux/bio.h | 10 ++++++++++
> 3 files changed, 14 insertions(+), 4 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs
2020-12-03 2:29 ` [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs Ming Lei
@ 2020-12-03 6:47 ` Hannes Reinecke
2020-12-09 8:32 ` Christoph Hellwig
1 sibling, 0 replies; 7+ messages in thread
From: Hannes Reinecke @ 2020-12-03 6:47 UTC (permalink / raw)
To: Ming Lei, Jens Axboe
Cc: linux-block, Pavel Begunkov, Christoph Hellwig, Matthew Wilcox,
linux-fsdevel
On 12/3/20 3:29 AM, Ming Lei wrote:
> Now the local variable for holding return value of bio_iov_iter_nvecs is
> 'nr_pages', which is a bit misleading, and the actual meaning is number
> of bio vectors, and it is also used for this way.
>
> So rename the local variable, and no function change.
>
> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
> Reviewed-by: Christoph Hellwig <hch@infradead.org>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: linux-fsdevel@vger.kernel.org
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> fs/block_dev.c | 30 +++++++++++++++---------------
> fs/iomap/direct-io.c | 14 +++++++-------
> 2 files changed, 22 insertions(+), 22 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/2] block: add bio_iov_iter_nvecs for figuring out nr_vecs
2020-12-03 2:29 ` [PATCH V2 1/2] " Ming Lei
2020-12-03 6:46 ` Hannes Reinecke
@ 2020-12-09 8:31 ` Christoph Hellwig
1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-12-09 8:31 UTC (permalink / raw)
To: Ming Lei
Cc: Jens Axboe, linux-block, Pavel Begunkov, Christoph Hellwig,
Matthew Wilcox, linux-fsdevel
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs
2020-12-03 2:29 ` [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs Ming Lei
2020-12-03 6:47 ` Hannes Reinecke
@ 2020-12-09 8:32 ` Christoph Hellwig
1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-12-09 8:32 UTC (permalink / raw)
To: Ming Lei
Cc: Jens Axboe, linux-block, Pavel Begunkov, Christoph Hellwig,
Matthew Wilcox, linux-fsdevel
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-12-09 8:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 2:29 [PATCH V2 0/2] block: add bio_iov_iter_nvecs for figuring out nr_vecs Ming Lei
2020-12-03 2:29 ` [PATCH V2 1/2] " Ming Lei
2020-12-03 6:46 ` Hannes Reinecke
2020-12-09 8:31 ` Christoph Hellwig
2020-12-03 2:29 ` [PATCH V2 2/2] block: rename the local variable for holding return value of bio_iov_iter_nvecs Ming Lei
2020-12-03 6:47 ` Hannes Reinecke
2020-12-09 8:32 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).