diff mbox series

[11/44] iov_iter_bvec_advance(): don't bother with bvec_iter

Message ID 20220622041552.737754-11-viro@zeniv.linux.org.uk (mailing list archive)
State New, archived
Headers show
Series [01/44] 9p: handling Rerror without copy_from_iter_full() | expand

Commit Message

Al Viro June 22, 2022, 4:15 a.m. UTC
do what we do for iovec/kvec; that ends up generating better code,
AFAICS.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 lib/iov_iter.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

Comments

Jeff Layton June 27, 2022, 6:48 p.m. UTC | #1
On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote:
> do what we do for iovec/kvec; that ends up generating better code,
> AFAICS.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  lib/iov_iter.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> index 8275b28e886b..93ceb13ec7b5 100644
> --- a/lib/iov_iter.c
> +++ b/lib/iov_iter.c
> @@ -870,17 +870,22 @@ static void pipe_advance(struct iov_iter *i, size_t size)
>  
>  static void iov_iter_bvec_advance(struct iov_iter *i, size_t size)
>  {
> -	struct bvec_iter bi;
> +	const struct bio_vec *bvec, *end;
>  
> -	bi.bi_size = i->count;
> -	bi.bi_bvec_done = i->iov_offset;
> -	bi.bi_idx = 0;
> -	bvec_iter_advance(i->bvec, &bi, size);
> +	if (!i->count)
> +		return;
> +	i->count -= size;
> +
> +	size += i->iov_offset;
>  
> -	i->bvec += bi.bi_idx;
> -	i->nr_segs -= bi.bi_idx;
> -	i->count = bi.bi_size;
> -	i->iov_offset = bi.bi_bvec_done;
> +	for (bvec = i->bvec, end = bvec + i->nr_segs; bvec < end; bvec++) {
> +		if (likely(size < bvec->bv_len))
> +			break;
> +		size -= bvec->bv_len;
> +	}
> +	i->iov_offset = size;
> +	i->nr_segs -= bvec - i->bvec;
> +	i->bvec = bvec;
>  }
>  
>  static void iov_iter_iovec_advance(struct iov_iter *i, size_t size)

Much simpler to follow, IMO...

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Christian Brauner June 28, 2022, 12:40 p.m. UTC | #2
On Wed, Jun 22, 2022 at 05:15:19AM +0100, Al Viro wrote:
> do what we do for iovec/kvec; that ends up generating better code,
> AFAICS.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---

Looks good to me,
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
diff mbox series

Patch

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 8275b28e886b..93ceb13ec7b5 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -870,17 +870,22 @@  static void pipe_advance(struct iov_iter *i, size_t size)
 
 static void iov_iter_bvec_advance(struct iov_iter *i, size_t size)
 {
-	struct bvec_iter bi;
+	const struct bio_vec *bvec, *end;
 
-	bi.bi_size = i->count;
-	bi.bi_bvec_done = i->iov_offset;
-	bi.bi_idx = 0;
-	bvec_iter_advance(i->bvec, &bi, size);
+	if (!i->count)
+		return;
+	i->count -= size;
+
+	size += i->iov_offset;
 
-	i->bvec += bi.bi_idx;
-	i->nr_segs -= bi.bi_idx;
-	i->count = bi.bi_size;
-	i->iov_offset = bi.bi_bvec_done;
+	for (bvec = i->bvec, end = bvec + i->nr_segs; bvec < end; bvec++) {
+		if (likely(size < bvec->bv_len))
+			break;
+		size -= bvec->bv_len;
+	}
+	i->iov_offset = size;
+	i->nr_segs -= bvec - i->bvec;
+	i->bvec = bvec;
 }
 
 static void iov_iter_iovec_advance(struct iov_iter *i, size_t size)