Skip to contentSkip to conversation

tcp: Add TCP_INFO counter for packets received out-of-order

PATCH Eric Dumazet 2 participants 2 messages Sep 9, 2019 – Sep 10, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 38 lines · Thomas Higdon

For receive-heavy cases on the server-side, we want to track the connection quality for individual client IPs. This counter, similar to the existing system-wide TCPOFOQueue counter in /proc/net/netstat, tracks out-of-order packet reception. By providing this counter in TCP_INFO, it will allow understanding to what degree receive-heavy sockets are experiencing out-of-order delivery and packet drops indicating congestion.

Please note that this is similar to the counter in NetBSD TCP_INFO, and has the same name.

---
 include/linux/tcp.h      | 2 ++
 include/uapi/linux/tcp.h | 2 ++
 net/ipv4/tcp.c           | 1 +
 net/ipv4/tcp_input.c     | 1 +
 4 files changed, 6 insertions(+)
include/linux/tcp.h +2 -0
index f3a85a7fb4b1..a01dc78218f1 100644
@@ -393,6 +393,8 @@ struct tcp_sock {
         */
        struct request_sock *fastopen_rsk;
        u32     *saved_syn;
+
+       u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
 };
 
 enum tsq_enum {
include/uapi/linux/tcp.h +0 -0
index b3564f85a762..20237987ccc8 100644

include/uapi/linux/tcp.h struct tcp_info { · line 274

Quoted 5 lines
include/uapi/linux/tcp.h +2 -0
@@ -270,6 +270,8 @@ struct tcp_info {
        __u64   tcpi_bytes_retrans;  /* RFC4898 tcpEStatsPerfOctetsRetrans */
        __u32   tcpi_dsack_dups;     /* RFC4898 tcpEStatsStackDSACKDups */
        __u32   tcpi_reord_seen;     /* reordering events seen */
+
+       __u32   tcpi_rcv_ooopack;    /* Out-of-order packets received */

This is problematic : you create a 32bit hole in this structure that we will never be able to fill.

We need to add another metric here so that the whole 64bit space is used.

Quoted 20 lines
include/uapi/linux/tcp.h +0 -0
 };
 
 /* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
net/ipv4/tcp.c +1 -0
index 94df48bcecc2..d4386f054f18 100644
@@ -3295,6 +3295,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
        info->tcpi_bytes_retrans = tp->bytes_retrans;
        info->tcpi_dsack_dups = tp->dsack_dups;
        info->tcpi_reord_seen = tp->reord_seen;
+       info->tcpi_rcv_ooopack = tp->rcv_ooopack;
        unlock_sock_fast(sk, slow);
 }
 EXPORT_SYMBOL_GPL(tcp_get_info);
net/ipv4/tcp_input.c +0 -0
index 706cbb3b2986..2774680c5d05 100644

net/ipv4/tcp_input.c static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) · line 4558

Quoted 4 lines
net/ipv4/tcp_input.c +1 -0
@@ -4555,6 +4555,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
        tp->pred_flags = 0;
        inet_csk_schedule_ack(sk);
 
+       tp->rcv_ooopack++;

We count skbs or we count segments ?

(GRO might have aggregated multiple segments)

net/ipv4/tcp_input.c static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) · line 4561

Quoted 3 lines
net/ipv4/tcp_input.c +0 -0
        NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPOFOQUEUE);
        seq = TCP_SKB_CB(skb)->seq;
        end_seq = TCP_SKB_CB(skb)->end_seq;

You forgot to clear the field in tcp_disconnect()

#2 lore raw
Quoted 15 lines · Eric Dumazet

include/uapi/linux/tcp.h struct tcp_info { · line 274

Quoted 10 lines · Thomas Higdon
include/uapi/linux/tcp.h +2 -0
index b3564f85a762..20237987ccc8 100644
@@ -270,6 +270,8 @@ struct tcp_info {
        __u64   tcpi_bytes_retrans;  /* RFC4898 tcpEStatsPerfOctetsRetrans */
        __u32   tcpi_dsack_dups;     /* RFC4898 tcpEStatsStackDSACKDups */
        __u32   tcpi_reord_seen;     /* reordering events seen */
+
+       __u32   tcpi_rcv_ooopack;    /* Out-of-order packets received */

This is problematic : you create a 32bit hole in this structure that we will never be able to fill.

Quoted 1 line

We need to add another metric here so that the whole 64bit space is used.

I don't have another metric to add currently. Perhaps I could first place a '__u32 _reserved' member so that someone else may replace it with a 32-bit member in the future. Unless there is a canonical way to do this? I couldn't find any prior examples.

Quoted 8 lines
Quoted 8 lines
net/ipv4/tcp_input.c +0 -0
index 706cbb3b2986..2774680c5d05 100644
@@ -4555,6 +4555,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
        tp->pred_flags = 0;
        inet_csk_schedule_ack(sk);
 
Quoted 5 lines

net/ipv4/tcp_input.c static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) · line 4558

Quoted 1 line
net/ipv4/tcp_input.c +1 -0
+       tp->rcv_ooopack++;

We count skbs or we count segments ?

(GRO might have aggregated multiple segments)

Let's count segments -- I will copy the technique of tcp_segs_in(), which checks the maximum of 1 and gso_segs from the lower layer. Interestingly, on my development machine, which uses the virtio-net driver, when LRO is enabled, gso_segs is always zero, even when an aggregated segment is passed up the stack. I guess this may be a problem with virtio-net? It still seems that using gso_segs here is the correct solution.