[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <a6838ca891ccff2c2407d9232ccd2a46fa3f8989.1684501922.git.asml.silence@gmail.com>
Date: Fri, 19 May 2023 14:33:04 +0100
From: Pavel Begunkov <asml.silence@...il.com>
To: netdev@...r.kernel.org,
edumazet@...gle.com,
davem@...emloft.net,
dsahern@...nel.org,
pabeni@...hat.com,
kuba@...nel.org
Cc: Pavel Begunkov <asml.silence@...il.com>
Subject: [PATCH net-next 1/2] net/tcp: optimise locking for blocking splice
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@...il.com>
---
net/ipv4/tcp.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 4d6392c16b7a..bf7627f37e69 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -789,13 +789,15 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
*/
if (unlikely(*ppos))
return -ESPIPE;
+ if (unlikely(!tss.len))
+ return 0;
ret = spliced = 0;
lock_sock(sk);
timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
- while (tss.len) {
+ while (true) {
ret = __tcp_splice_read(sk, &tss);
if (ret < 0)
break;
@@ -835,10 +837,10 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
}
continue;
}
- tss.len -= ret;
spliced += ret;
+ tss.len -= ret;
- if (!timeo)
+ if (!tss.len || !timeo)
break;
release_sock(sk);
lock_sock(sk);
--
2.40.0
Powered by blists - more mailing lists