ITER_PIPE: helper for getting pipe buffer by index
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 14 Jun 2022 14:24:37 +0000 (10:24 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 19 Jul 2022 17:08:46 +0000 (13:08 -0400)
commitc4a5436c3ad9d9934bad3783656c4d392ad3d1d1
tree9c9d2dd350286392c878a95e48ff2fb26201ac33
parent9d9858865fb7d94726194a80019740b6977af16e
ITER_PIPE: helper for getting pipe buffer by index

pipe_buffer instances of a pipe are organized as a ring buffer,
with power-of-2 size.  Indices are kept *not* reduced modulo ring
size, so the buffer refered to by index N is
pipe->bufs[N & (pipe->ring_size - 1)].

Ring size can change over the lifetime of a pipe, but not while
the pipe is locked.  So for any iov_iter primitives it's a constant.
Original conversion of pipes to this layout went overboard trying
to microoptimize that - calculating pipe->ring_size - 1, storing
it in a local variable and using through the function.  In some
cases it might be warranted, but most of the times it only
obfuscates what's going on in there.

Introduce a helper (pipe_buf(pipe, N)) that would encapsulate
that and use it in the obvious cases.  More will follow...

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
lib/iov_iter.c