diff mbox series

[4/4] block: introduce mp_bvec_for_each_page() for iterating over page

Message ID 20190227124013.4828-5-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: optimize for single-page bvec workloads | expand

Commit Message

Ming Lei Feb. 27, 2019, 12:40 p.m. UTC
mp_bvec_for_each_segment() is a bit big for the iteration, so introduce
a light-weight helper for iterating over pages, then 32bytes stack
space can be saved.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio.c          | 7 +++----
 include/linux/bvec.h | 5 +++++
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig Feb. 28, 2019, 2:13 p.m. UTC | #1
On Wed, Feb 27, 2019 at 08:40:13PM +0800, Ming Lei wrote:
> mp_bvec_for_each_segment() is a bit big for the iteration, so introduce
> a light-weight helper for iterating over pages, then 32bytes stack
> space can be saved.

The version in Jens' tree seems to add this helper, but no actual
users..
Jens Axboe Feb. 28, 2019, 3:10 p.m. UTC | #2
On 2/28/19 7:13 AM, Christoph Hellwig wrote:
> On Wed, Feb 27, 2019 at 08:40:13PM +0800, Ming Lei wrote:
>> mp_bvec_for_each_segment() is a bit big for the iteration, so introduce
>> a light-weight helper for iterating over pages, then 32bytes stack
>> space can be saved.
> 
> The version in Jens' tree seems to add this helper, but no actual
> users..

io_uring uses it, which is based on the block branch.

But hopefully that too can go away, if the iov/bio no-ref stuff is
reviewed + merged...
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index eae8b754801d..7917535123df 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -849,8 +849,7 @@  static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter)
 	size = bio_add_page(bio, bv->bv_page, len,
 				bv->bv_offset + iter->iov_offset);
 	if (size == len) {
-		struct bvec_iter_all iter_all;
-		struct bio_vec *tmp;
+		struct page *pg;
 		int i;
 
 		/*
@@ -862,8 +861,8 @@  static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter)
 		 * get rid of the get here and the need to call
 		 * bio_release_pages() at IO completion time.
 		 */
-		mp_bvec_for_each_segment(tmp, bv, i, iter_all)
-			get_page(tmp->bv_page);
+		mp_bvec_for_each_page(pg, bv, i)
+			get_page(pg);
 		iov_iter_advance(iter, size);
 		return 0;
 	}
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 4376f683c08a..2c32e3e151a0 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -188,4 +188,9 @@  static inline void mp_bvec_last_segment(const struct bio_vec *bvec,
 	}
 }
 
+#define mp_bvec_for_each_page(pg, bv, i)				\
+	for (i = (bv)->bv_offset / PAGE_SIZE;				\
+		(i < (((bv)->bv_offset + (bv)->bv_len) / PAGE_SIZE)) && \
+		(pg = bvec_nth_page((bv)->bv_page, i)); i += 1)
+
 #endif /* __LINUX_BVEC_ITER_H */