Skip to content

Commit c8856c0

Browse files
arjunroydavem330
authored andcommitted
tcp-zerocopy: Return inq along with tcp receive zerocopy.
This patchset is intended to reduce the number of extra system calls imposed by TCP receive zerocopy. For ping-pong RPC style workloads, this patchset has demonstrated a system call reduction of about 30% when coupled with userspace changes. For applications using edge-triggered epoll, returning inq along with the result of tcp receive zerocopy could remove the need to call recvmsg()=-EAGAIN after a successful zerocopy. Generally speaking, since normally we would need to perform a recvmsg() call for every successful small RPC read via TCP receive zerocopy, returning inq can reduce the number of system calls performed by approximately half. Signed-off-by: Arjun Roy <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Soheil Hassas Yeganeh <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8c8da5b commit c8856c0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

include/uapi/linux/tcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,6 @@ struct tcp_zerocopy_receive {
345345
__u64 address; /* in: address of mapping */
346346
__u32 length; /* in/out: number of bytes to map/mapped */
347347
__u32 recv_skip_hint; /* out: amount of bytes to skip */
348+
__u32 inq; /* out: amount of bytes in read queue */
348349
};
349350
#endif /* _UAPI_LINUX_TCP_H */

net/ipv4/tcp.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3667,13 +3667,26 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
36673667

36683668
if (get_user(len, optlen))
36693669
return -EFAULT;
3670-
if (len != sizeof(zc))
3670+
if (len < offsetofend(struct tcp_zerocopy_receive, length))
36713671
return -EINVAL;
3672+
if (len > sizeof(zc))
3673+
len = sizeof(zc);
36723674
if (copy_from_user(&zc, optval, len))
36733675
return -EFAULT;
36743676
lock_sock(sk);
36753677
err = tcp_zerocopy_receive(sk, &zc);
36763678
release_sock(sk);
3679+
switch (len) {
3680+
case sizeof(zc):
3681+
case offsetofend(struct tcp_zerocopy_receive, inq):
3682+
goto zerocopy_rcv_inq;
3683+
case offsetofend(struct tcp_zerocopy_receive, length):
3684+
default:
3685+
goto zerocopy_rcv_out;
3686+
}
3687+
zerocopy_rcv_inq:
3688+
zc.inq = tcp_inq_hint(sk);
3689+
zerocopy_rcv_out:
36773690
if (!err && copy_to_user(optval, &zc, len))
36783691
err = -EFAULT;
36793692
return err;

0 commit comments

Comments
 (0)