linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iov_iter: optimise iter type checking
@ 2020-11-21 14:37 Pavel Begunkov
  2020-12-06 16:01 ` Pavel Begunkov
  0 siblings, 1 reply; 16+ messages in thread
From: Pavel Begunkov @ 2020-11-21 14:37 UTC (permalink / raw)
  To: linux-fsdevel, Alexander Viro; +Cc: Jens Axboe, linux-kernel

The problem here is that iov_iter_is_*() helpers check types for
equality, but all iterate_* helpers do bitwise ands. This confuses
compilers, so even if some cases were handled separately with
iov_iter_is_*(), corresponding ifs in iterate*() right after are not
eliminated.

E.g. iov_iter_npages() first handles discards, but iterate_all_kinds()
still checks for discard iter type and generates unreachable code down
the line.

           text    data     bss     dec     hex filename
before:   24409     805       0   25214    627e lib/iov_iter.o
after:    23977     805       0   24782    60ce lib/iov_iter.o

Reviewed-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 include/linux/uio.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/uio.h b/include/linux/uio.h
index 72d88566694e..c5970b2d3307 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -57,27 +57,27 @@ static inline enum iter_type iov_iter_type(const struct iov_iter *i)
 
 static inline bool iter_is_iovec(const struct iov_iter *i)
 {
-	return iov_iter_type(i) == ITER_IOVEC;
+	return iov_iter_type(i) & ITER_IOVEC;
 }
 
 static inline bool iov_iter_is_kvec(const struct iov_iter *i)
 {
-	return iov_iter_type(i) == ITER_KVEC;
+	return iov_iter_type(i) & ITER_KVEC;
 }
 
 static inline bool iov_iter_is_bvec(const struct iov_iter *i)
 {
-	return iov_iter_type(i) == ITER_BVEC;
+	return iov_iter_type(i) & ITER_BVEC;
 }
 
 static inline bool iov_iter_is_pipe(const struct iov_iter *i)
 {
-	return iov_iter_type(i) == ITER_PIPE;
+	return iov_iter_type(i) & ITER_PIPE;
 }
 
 static inline bool iov_iter_is_discard(const struct iov_iter *i)
 {
-	return iov_iter_type(i) == ITER_DISCARD;
+	return iov_iter_type(i) & ITER_DISCARD;
 }
 
 static inline unsigned char iov_iter_rw(const struct iov_iter *i)
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-01-28 11:44 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-21 14:37 [PATCH] iov_iter: optimise iter type checking Pavel Begunkov
2020-12-06 16:01 ` Pavel Begunkov
2021-01-09 16:09   ` Pavel Begunkov
2021-01-09 17:03     ` Al Viro
2021-01-09 21:19       ` Pavel Begunkov
2021-01-09 21:49       ` David Laight
2021-01-09 22:11         ` Pavel Begunkov
2021-01-11  9:35           ` David Laight
2021-01-12 16:04             ` Pavel Begunkov
2021-01-16  5:18           ` Al Viro
2021-01-17 12:12             ` David Laight
2021-01-27 15:48             ` Pavel Begunkov
2021-01-27 16:28               ` David Laight
2021-01-27 18:30                 ` Al Viro
2021-01-27 18:31               ` Al Viro
2021-01-28 11:39                 ` Pavel Begunkov

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).