net/tcp: optimise locking for blocking splice
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 23 Jun 2023 12:38:55 +0000 (13:38 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 24 Jun 2023 22:24:01 +0000 (15:24 -0700)
Even when tcp_splice_read() reads all it was asked for, for blocking
sockets it'll release and immediately regrab the socket lock, loop
around and break on the while check.

Check tss.len right after we adjust it, and return if we're done.
That saves us one release_sock(); lock_sock(); pair per successful
blocking splice read.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/80736a2cc6d478c383ea565ba825eaf4d1abd876.1687523671.git.asml.silence@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/tcp.c

index 71b42eef9dbf527098963bc03deecf55042e2021..d56edc2c885fc5cc8c8df6a5d30a98def7484f3b 100644 (file)
@@ -839,7 +839,7 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
                tss.len -= ret;
                spliced += ret;
 
-               if (!timeo)
+               if (!tss.len || !timeo)
                        break;
                release_sock(sk);
                lock_sock(sk);