[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3888331.1691773627@warthog.procyon.org.uk>
Date: Fri, 11 Aug 2023 18:07:07 +0100
From: David Howells <dhowells@...hat.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: dhowells@...hat.com, Alexander Viro <viro@...iv.linux.org.uk>,
Jens Axboe <axboe@...nel.dk>, Christoph Hellwig <hch@....de>,
Christian Brauner <christian@...uner.io>,
Matthew Wilcox <willy@...radead.org>, jlayton@...nel.org,
linux-block@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH] iov_iter: Convert iterate*() to inline funcs
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> I like this generally, the code generation deprovement worries me a
> bit, but from a quick look on a test-branch it didn't really look all
> that bad (but the changes are too big to usefully show up as asm
> diffs)
Hmmm... It seems that using if-if-if rather than switch() gets optimised
better in terms of .text space. The attached change makes things a bit
smaller (by 69 bytes).
David
---
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 8943ac25e202..f61474ec1c89 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -190,22 +190,18 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv,
if (unlikely(!len))
return 0;
- switch (iov_iter_type(iter)) {
- case ITER_UBUF:
+ if (likely(iter_is_ubuf(iter)))
return iterate_ubuf(iter, len, priv, NULL, ustep);
- case ITER_IOVEC:
+ if (likely(iter_is_iovec(iter)))
return iterate_iovec(iter, len, priv, NULL, ustep);
- case ITER_KVEC:
+ if (iov_iter_is_kvec(iter))
return iterate_kvec(iter, len, priv, NULL, step);
- case ITER_BVEC:
+ if (iov_iter_is_bvec(iter))
return iterate_bvec(iter, len, priv, NULL, step);
- case ITER_XARRAY:
+ if (iov_iter_is_xarray(iter))
return iterate_xarray(iter, len, priv, NULL, step);
- case ITER_DISCARD:
- iter->count -= len;
- return len;
- }
- return 0;
+ iter->count -= len;
+ return len;
}
static __always_inline
@@ -217,22 +213,18 @@ size_t iterate_and_advance_csum(struct iov_iter *iter, size_t len, void *priv,
if (unlikely(!len))
return 0;
- switch (iov_iter_type(iter)) {
- case ITER_UBUF:
+ if (likely(iter_is_ubuf(iter)))
return iterate_ubuf(iter, len, priv, csum, ustep);
- case ITER_IOVEC:
+ if (likely(iter_is_iovec(iter)))
return iterate_iovec(iter, len, priv, csum, ustep);
- case ITER_KVEC:
+ if (iov_iter_is_kvec(iter))
return iterate_kvec(iter, len, priv, csum, step);
- case ITER_BVEC:
+ if (iov_iter_is_bvec(iter))
return iterate_bvec(iter, len, priv, csum, step);
- case ITER_XARRAY:
+ if (iov_iter_is_xarray(iter))
return iterate_xarray(iter, len, priv, csum, step);
- case ITER_DISCARD:
- iter->count -= len;
- return len;
- }
- return 0;
+ iter->count -= len;
+ return len;
}
static size_t copy_to_user_iter(void __user *iter_to, size_t progress,
Powered by blists - more mailing lists