tcp: add 4 new stats
Subsystems (3)
v2 cover tcp: add 4 new stats
From: Wei Wang <[email protected]>
This patch series adds 3 RFC4898 stats:
1. tcpEStatsPerfHCDataOctetsOut
2. tcpEStatsPerfOctetsRetrans
3. tcpEStatsStackDSACKDups
and an addtional stat to record the number of data packet reordering events seen:
4. tcp_reord_seen
Together with the existing stats, application can use them to measure the retransmission rate in bytes, exclude spurious retransmissions reflected by DSACK, and keep track of the reordering events on live connections.
In particular the networks with different MTUs make bytes-based loss stats more useful. Google servers have been using these stats for many years to instrument transport and network performance.
Note: The first patch is a refactor to add a helper to calculate opt_stats size in order to make later changes cleaner.
Wei Wang (5):
tcp: add a helper to calculate size of opt_stats
tcp: add data bytes sent stats
tcp: add data bytes retransmitted stats
tcp: add dsack blocks received stats
tcp: add stat of data packet reordering events
include/linux/tcp.h | 13 ++++++++++-- include/uapi/linux/tcp.h | 10 ++++++++- net/ipv4/tcp.c | 46 +++++++++++++++++++++++++++++++++++++--- net/ipv4/tcp_input.c | 4 +++- net/ipv4/tcp_output.c | 2 ++ net/ipv4/tcp_recovery.c | 2 +- 6 files changed, 69 insertions(+), 8 deletions(-)
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
PATCH v2 1/5 tcp: add a helper to calculate size of opt_stats
From: Wei Wang <[email protected]>
This is to refactor the calculation of the size of opt_stats to a helper function to make the code cleaner and easier for later changes.
--- net/ipv4/tcp.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
net/ipv4/tcp.c +24 -3
@@ -3205,6 +3205,29 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) }EXPORT_SYMBOL_GPL (tcp_get_info); +static size_t tcp_opt_stats_get_size (void ) +{ +return +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BUSY */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_RWND_LIMITED */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_SNDBUF_LIMITED */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_DATA_SEGS_OUT */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_TOTAL_RETRANS */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_PACING_RATE */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_DELIVERY_RATE */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_SND_CWND */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_REORDERING */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_MIN_RTT */ +nla_total_size (sizeof (u8)) +/* TCP_NLA_RECUR_RETRANS */ +nla_total_size (sizeof (u8)) +/* TCP_NLA_DELIVERY_RATE_APP_LMT */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_SNDQ_SIZE */ +nla_total_size (sizeof (u8)) +/* TCP_NLA_CA_STATE */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_SND_SSTHRESH */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_DELIVERED */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_DELIVERED_CE */ +0 ; +} +struct sk_buff *tcp_get_timestamping_opt_stats (const struct sock *sk) {const struct tcp_sock *tp =tcp_sk (sk);
@@ -3213,9 +3236,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk)u64 rate64;u32 rate; - stats =alloc_skb (7 *nla_total_size_64bit (sizeof (u64)) + -7 *nla_total_size (sizeof (u32)) + -3 *nla_total_size (sizeof (u8)),GFP_ATOMIC ); + stats =alloc_skb (tcp_opt_stats_get_size (),GFP_ATOMIC );if (!stats)return NULL ;
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
PATCH v2 2/5 tcp: add data bytes sent stats
From: Wei Wang <[email protected]>
Introduce a new TCP stat to record the number of bytes sent (RFC4898 tcpEStatsPerfHCDataOctetsOut) and expose it in both tcp_info (TCP_INFO) and opt_stats (SOF_TIMESTAMPING_OPT_STATS).
--- include/linux/tcp.h | 3 +++ include/uapi/linux/tcp.h | 4 +++- net/ipv4/tcp.c | 6 ++++++ net/ipv4/tcp_output.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-)
include/linux/tcp.h +3 -0
@@ -181,6 +181,9 @@ struct tcp_sock {u32 data_segs_out;/* RFC4898 tcpEStatsPerfDataSegsOut * total number of data segments sent. */ +u64 bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut +* total number of data bytes sent. +*/ u64 bytes_acked;/* RFC4898 tcpEStatsAppHCThruOctetsAcked * sum(delta(snd_una)), or how many bytes * were acked.
include/uapi/linux/tcp.h +3 -1
@@ -235,6 +235,8 @@ struct tcp_info {__u32 tcpi_delivered;__u32 tcpi_delivered_ce; + +__u64 tcpi_bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut */ };/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
@@ -257,7 +259,7 @@ enum {TCP_NLA_SND_SSTHRESH ,/* Slow start size threshold */ TCP_NLA_DELIVERED ,/* Data pkts delivered incl. out-of-order */ TCP_NLA_DELIVERED_CE ,/* Like above but only ones w/ CE marks */ - + TCP_NLA_BYTES_SENT, /* Data bytes sent including retransmission */ };/* for TCP_MD5SIG socket option */
net/ipv4/tcp.c +6 -0
@@ -2594,6 +2594,7 @@ int tcp_disconnect(struct sock *sk, int flags) sk->sk_rx_dst =NULL ;tcp_saved_syn_free (tp); tp->compressed_ack =0 ; + tp->bytes_sent =0 ;/* Clean up fastopen related fields */ tcp_free_fastopen_req (tp);
@@ -3201,6 +3202,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) info->tcpi_delivery_rate = rate64; info->tcpi_delivered = tp->delivered; info->tcpi_delivered_ce = tp->delivered_ce; + info->tcpi_bytes_sent = tp->bytes_sent;unlock_sock_fast (sk, slow); }EXPORT_SYMBOL_GPL (tcp_get_info);
@@ -3225,6 +3227,7 @@ static size_t tcp_opt_stats_get_size(void)nla_total_size (sizeof (u32)) +/* TCP_NLA_SND_SSTHRESH */ nla_total_size (sizeof (u32)) +/* TCP_NLA_DELIVERED */ nla_total_size (sizeof (u32)) +/* TCP_NLA_DELIVERED_CE */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BYTES_SENT */ 0 ; }
@@ -3272,6 +3275,9 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk)nla_put_u32 (stats,TCP_NLA_SNDQ_SIZE , tp->write_seq - tp->snd_una);nla_put_u8 (stats,TCP_NLA_CA_STATE ,inet_csk (sk)->icsk_ca_state); +nla_put_u64_64bit (stats,TCP_NLA_BYTES_SENT , tp->bytes_sent, +TCP_NLA_PAD ); +return stats; }
net/ipv4/tcp_output.c +1 -0
@@ -1136,6 +1136,7 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,if (skb->len != tcp_header_size) {tcp_event_data_sent (tp, sk); tp->data_segs_out +=tcp_skb_pcount (skb); + tp->bytes_sent += skb->len - tcp_header_size;tcp_internal_pacing (sk, skb); }
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
PATCH v2 3/5 tcp: add data bytes retransmitted stats
From: Wei Wang <[email protected]>
Introduce a new TCP stat to record the number of bytes retransmitted (RFC4898 tcpEStatsPerfOctetsRetrans) and expose it in both tcp_info (TCP_INFO) and opt_stats (SOF_TIMESTAMPING_OPT_STATS).
--- include/linux/tcp.h | 3 +++ include/uapi/linux/tcp.h | 2 ++ net/ipv4/tcp.c | 5 +++++ net/ipv4/tcp_output.c | 1 + 4 files changed, 11 insertions(+)
include/linux/tcp.h +3 -0
@@ -333,6 +333,9 @@ struct tcp_sock {* the first SYN. */ u32 undo_marker;/* snd_una upon a new recovery episode. */ int undo_retrans;/* number of undoable retransmissions. */ +u64 bytes_retrans;/* RFC4898 tcpEStatsPerfOctetsRetrans +* Total data bytes retransmitted +*/ u32 total_retrans;/* Total retransmits for entire connection */ u32 urg_seq;/* Seq of received urgent pointer */
include/uapi/linux/tcp.h +2 -0
@@ -237,6 +237,7 @@ struct tcp_info {__u32 tcpi_delivered_ce;__u64 tcpi_bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut */ +__u64 tcpi_bytes_retrans;/* RFC4898 tcpEStatsPerfOctetsRetrans */ };/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
@@ -260,6 +261,7 @@ enum {TCP_NLA_DELIVERED ,/* Data pkts delivered incl. out-of-order */ TCP_NLA_DELIVERED_CE ,/* Like above but only ones w/ CE marks */ TCP_NLA_BYTES_SENT ,/* Data bytes sent including retransmission */ + TCP_NLA_BYTES_RETRANS, /* Data bytes retransmitted */ };/* for TCP_MD5SIG socket option */
net/ipv4/tcp.c +5 -0
@@ -2595,6 +2595,7 @@ int tcp_disconnect(struct sock *sk, int flags)tcp_saved_syn_free (tp); tp->compressed_ack =0 ; tp->bytes_sent =0 ; + tp->bytes_retrans =0 ;/* Clean up fastopen related fields */ tcp_free_fastopen_req (tp);
@@ -3203,6 +3204,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) info->tcpi_delivered = tp->delivered; info->tcpi_delivered_ce = tp->delivered_ce; info->tcpi_bytes_sent = tp->bytes_sent; + info->tcpi_bytes_retrans = tp->bytes_retrans;unlock_sock_fast (sk, slow); }EXPORT_SYMBOL_GPL (tcp_get_info);
@@ -3228,6 +3230,7 @@ static size_t tcp_opt_stats_get_size(void)nla_total_size (sizeof (u32)) +/* TCP_NLA_DELIVERED */ nla_total_size (sizeof (u32)) +/* TCP_NLA_DELIVERED_CE */ nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BYTES_SENT */ +nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BYTES_RETRANS */ 0 ; }
@@ -3277,6 +3280,8 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk)nla_put_u64_64bit (stats,TCP_NLA_BYTES_SENT , tp->bytes_sent,TCP_NLA_PAD ); +nla_put_u64_64bit (stats,TCP_NLA_BYTES_RETRANS , tp->bytes_retrans, +TCP_NLA_PAD );return stats; }
net/ipv4/tcp_output.c +1 -0
@@ -2871,6 +2871,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_SYN )__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPSYNRETRANS ); tp->total_retrans += segs; + tp->bytes_retrans += skb->len;/* make sure skb->data is aligned on arches that require it * and check if ack-trimming & collapsing extended the headroom
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
PATCH v2 4/5 tcp: add dsack blocks received stats
From: Wei Wang <[email protected]>
Introduce a new TCP stat to record the number of DSACK blocks received (RFC4989 tcpEStatsStackDSACKDups) and expose it in both tcp_info (TCP_INFO) and opt_stats (SOF_TIMESTAMPING_OPT_STATS).
--- include/linux/tcp.h | 3 +++ include/uapi/linux/tcp.h | 2 ++ net/ipv4/tcp.c | 4 ++++ net/ipv4/tcp_input.c | 1 + 4 files changed, 10 insertions(+)
include/linux/tcp.h +3 -0
@@ -188,6 +188,9 @@ struct tcp_sock {* sum(delta(snd_una)), or how many bytes * were acked. */ +u32 dsack_dups;/* RFC4898 tcpEStatsStackDSACKDups +* total number of DSACK blocks received +*/ u32 snd_una;/* First byte we want an ack for */ u32 snd_sml;/* Last byte of the most recently transmitted small packet */ u32 rcv_tstamp;/* timestamp of last received ACK (for keepalives) */
include/uapi/linux/tcp.h +2 -0
@@ -238,6 +238,7 @@ struct tcp_info {__u64 tcpi_bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut */ __u64 tcpi_bytes_retrans;/* RFC4898 tcpEStatsPerfOctetsRetrans */ +__u32 tcpi_dsack_dups;/* RFC4898 tcpEStatsStackDSACKDups */ };/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
@@ -262,6 +263,7 @@ enum {TCP_NLA_DELIVERED_CE ,/* Like above but only ones w/ CE marks */ TCP_NLA_BYTES_SENT ,/* Data bytes sent including retransmission */ TCP_NLA_BYTES_RETRANS ,/* Data bytes retransmitted */ + TCP_NLA_DSACK_DUPS, /* DSACK blocks received */ };/* for TCP_MD5SIG socket option */
net/ipv4/tcp.c +4 -0
@@ -2596,6 +2596,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->compressed_ack =0 ; tp->bytes_sent =0 ; tp->bytes_retrans =0 ; + tp->dsack_dups =0 ;/* Clean up fastopen related fields */ tcp_free_fastopen_req (tp);
@@ -3205,6 +3206,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) info->tcpi_delivered_ce = tp->delivered_ce; info->tcpi_bytes_sent = tp->bytes_sent; info->tcpi_bytes_retrans = tp->bytes_retrans; + info->tcpi_dsack_dups = tp->dsack_dups;unlock_sock_fast (sk, slow); }EXPORT_SYMBOL_GPL (tcp_get_info);
@@ -3231,6 +3233,7 @@ static size_t tcp_opt_stats_get_size(void)nla_total_size (sizeof (u32)) +/* TCP_NLA_DELIVERED_CE */ nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BYTES_SENT */ nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BYTES_RETRANS */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_DSACK_DUPS */ 0 ; }
@@ -3282,6 +3285,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk) TCP_NLA_PAD);nla_put_u64_64bit (stats,TCP_NLA_BYTES_RETRANS , tp->bytes_retrans,TCP_NLA_PAD ); +nla_put_u32 (stats,TCP_NLA_DSACK_DUPS , tp->dsack_dups);return stats; }
net/ipv4/tcp_input.c +1 -0
@@ -874,6 +874,7 @@ static void tcp_dsack_seen(struct tcp_sock *tp) { tp->rx_opt.sack_ok |=TCP_DSACK_SEEN ; tp->rack.dsack_seen =1 ; + tp->dsack_dups++; }/* It's reordering when higher sequence was delivered (i.e. sacked) before
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
PATCH v2 5/5 tcp: add stat of data packet reordering events
From: Wei Wang <[email protected]>
Introduce a new TCP stats to record the number of reordering events seen and expose it in both tcp_info (TCP_INFO) and opt_stats (SOF_TIMESTAMPING_OPT_STATS).
Application can use this stats to track the frequency of the reordering events in addition to the existing reordering stats which tracks the magnitude of the latest reordering event.
Note: this new stats tracks reordering events triggered by ACKs, which could often be fewer than the actual number of packets being delivered out-of-order.
--- include/linux/tcp.h | 4 ++-- include/uapi/linux/tcp.h | 2 ++ net/ipv4/tcp.c | 4 ++++ net/ipv4/tcp_input.c | 3 ++- net/ipv4/tcp_recovery.c | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-)
include/linux/tcp.h +2 -2
@@ -220,8 +220,7 @@ struct tcp_sock {#define TCP_RACK_RECOVERY_THRESH 16 u8 reo_wnd_persist:5, /* No. of recovery since last adj */ dsack_seen:1, /* Whether DSACK seen after last adj */ - advanced:1, /* mstamp advanced since last lost marking */ - reord:1; /* reordering detected */ + advanced:1; /* mstamp advanced since last lost marking */ } rack;u16 advmss;/* Advertised MSS */ u8 compressed_ack;
@@ -267,6 +266,7 @@ struct tcp_sock {u8 ecn_flags;/* ECN status bits. */ u8 keepalive_probes;/* num of allowed keep alive probes */ u32 reordering;/* Packet reordering metric. */ +u32 reord_seen;/* number of data packet reordering events */ u32 snd_up;/* Urgent pointer */ /*
include/uapi/linux/tcp.h +2 -0
@@ -239,6 +239,7 @@ struct tcp_info {__u64 tcpi_bytes_sent;/* RFC4898 tcpEStatsPerfHCDataOctetsOut */ __u64 tcpi_bytes_retrans;/* RFC4898 tcpEStatsPerfOctetsRetrans */ __u32 tcpi_dsack_dups;/* RFC4898 tcpEStatsStackDSACKDups */ +__u32 tcpi_reord_seen;/* reordering events seen */ };/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
@@ -264,6 +265,7 @@ enum {TCP_NLA_BYTES_SENT ,/* Data bytes sent including retransmission */ TCP_NLA_BYTES_RETRANS ,/* Data bytes retransmitted */ TCP_NLA_DSACK_DUPS ,/* DSACK blocks received */ + TCP_NLA_REORD_SEEN, /* reordering events seen */ };/* for TCP_MD5SIG socket option */
net/ipv4/tcp.c +4 -0
@@ -2597,6 +2597,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->bytes_sent =0 ; tp->bytes_retrans =0 ; tp->dsack_dups =0 ; + tp->reord_seen =0 ;/* Clean up fastopen related fields */ tcp_free_fastopen_req (tp);
@@ -3207,6 +3208,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) info->tcpi_bytes_sent = tp->bytes_sent; info->tcpi_bytes_retrans = tp->bytes_retrans; info->tcpi_dsack_dups = tp->dsack_dups; + info->tcpi_reord_seen = tp->reord_seen;unlock_sock_fast (sk, slow); }EXPORT_SYMBOL_GPL (tcp_get_info);
@@ -3234,6 +3236,7 @@ static size_t tcp_opt_stats_get_size(void)nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BYTES_SENT */ nla_total_size_64bit (sizeof (u64)) +/* TCP_NLA_BYTES_RETRANS */ nla_total_size (sizeof (u32)) +/* TCP_NLA_DSACK_DUPS */ +nla_total_size (sizeof (u32)) +/* TCP_NLA_REORD_SEEN */ 0 ; }
@@ -3286,6 +3289,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk)nla_put_u64_64bit (stats,TCP_NLA_BYTES_RETRANS , tp->bytes_retrans,TCP_NLA_PAD );nla_put_u32 (stats,TCP_NLA_DSACK_DUPS , tp->dsack_dups); +nla_put_u32 (stats,TCP_NLA_REORD_SEEN , tp->reord_seen);return stats; }
net/ipv4/tcp_input.c +2 -1
@@ -906,8 +906,8 @@ static void tcp_check_sack_reordering(struct sock *sk, const u32 low_seq, sock_net(sk)->ipv4.sysctl_tcp_max_reordering); } - tp->rack.reord =1 ;/* This exciting event is worth to be remembered. 8) */ + tp->reord_seen++;NET_INC_STATS (sock_net (sk), ts ?LINUX_MIB_TCPTSREORDER :LINUX_MIB_TCPSACKREORDER ); }
@@ -1871,6 +1871,7 @@ static void tcp_check_reno_reordering(struct sock *sk, const int addend) tp->reordering =min_t (u32, tp->packets_out + addend,sock_net (sk)->ipv4.sysctl_tcp_max_reordering); + tp->reord_seen++;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPRENOREORDER ); }
net/ipv4/tcp_recovery.c +1 -1
@@ -25,7 +25,7 @@ static u32 tcp_rack_reo_wnd(const struct sock *sk) {struct tcp_sock *tp =tcp_sk (sk); -if (!tp->rack.reord) { +if (!tp->reord_seen) {/* If reordering has not been observed, be aggressive during * the recovery or starting the recovery by DUPACK threshold. */
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
David Miller
maintainerFrom: Wei Wang <[email protected]>
Date: Tue, 31 Jul 2018 17:46:19 -0700
Quoted 18 lines
From: Wei Wang <[email protected]>
This patch series adds 3 RFC4898 stats:
1. tcpEStatsPerfHCDataOctetsOut
2. tcpEStatsPerfOctetsRetrans
3. tcpEStatsStackDSACKDups
and an addtional stat to record the number of data packet reordering events seen:
4.tcp_reord_seenTogether with the existing stats, application can use them to measure the retransmission rate in bytes, exclude spurious retransmissions reflected by DSACK, and keep track of the reordering events on live connections.
In particular the networks with different MTUs make bytes-based loss stats more useful. Google servers have been using these stats for many years to instrument transport and network performance.
Quoted 2 lines
Note: The first patch is a refactor to add a helper to calculate
opt_statssize in order to make later changes cleaner.
Series applied, thank you.