Skip to contentSkip to conversation

tcp: export drops counter to /proc/net/tcp{,6}

PATCH In review Stéphan Gorget 2 participants 3 messages Aug 18, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: export drops counter to /proc/net/tcp{,6}

Those counters are exported for raw and udp but not for tcp, though they are incremented.

An example where it is useful is chasing listen overflow. Listen overflow are counted as a global counter in LINUX_MIB_LISTENOVERFLOWS accessible in /proc/net/netstat but there is no way to find related drops in the information exported for tcp. With this patch it will make possible to correlate growth of LINUX_MIB_LISTENOVERFLOWS with growth of drops for a tcp socket.

This patch does it for /proc/net/tcp and /proc/net/tcp6, the drops counter is being incremented in function like tcp_listendrop() which would help surface error cases like listen overflow and track them to the correct socket.

That work has been done for raw sockets (/proc/net/raw and /proc/net/raw6) by Wang Chen in commit 33c732c36169 ("[IPV4]: Add raw drops counter.") and commit a92aa318b4b3 ("[IPV6]: Add raw6 drops counter.") and by Eric Dumazet for udp ones (/proc/net/udp and /proc/net/udp6) in commit cb61cb9b8b5e ("udp: sk_drops handling").

---
 Documentation/networking/proc_net_tcp.txt | 30 ++++++++++++++++--------------
 net/ipv4/tcp_ipv4.c                       |  5 +++--
 net/ipv6/tcp_ipv6.c                       |  7 ++++---
 3 files changed, 23 insertions(+), 19 deletions(-)
Documentation/networking/proc_net_tcp.txt +16 -14
index 4a79209..38bda94 100644
@@ -24,20 +24,22 @@ up into 3 parts because of the length of the line):
       |        |----------------------> receive-queue
       |-------------------------------> transmit-queue
 
-   1000        0 54165785 4 cd1e6040 25 4 27 3 -1
-    |          |    |     |    |     |  | |  | |--> slow start size threshold, 
-    |          |    |     |    |     |  | |  |      or -1 if the threshold
-    |          |    |     |    |     |  | |  |      is >= 0xFFFF
-    |          |    |     |    |     |  | |  |----> sending congestion window
-    |          |    |     |    |     |  | |-------> (ack.quick<<1)|ack.pingpong
-    |          |    |     |    |     |  |---------> Predicted tick of soft clock
-    |          |    |     |    |     |              (delayed ACK control data)
-    |          |    |     |    |     |------------> retransmit timeout
-    |          |    |     |    |------------------> location of socket in memory
-    |          |    |     |-----------------------> socket reference count
-    |          |    |-----------------------------> inode
-    |          |----------------------------------> unanswered 0-window probes
-    |---------------------------------------------> uid
+   1000        0 54165785 4 cd1e6040 25 4 27 3 -1 0
+    |          |    |     |    |     |  | |  | |  |--> number of drops
+    |          |    |     |    |     |  | |  | |-----> slow start size
+    |          |    |     |    |     |  | |  |         threshold, or -1 if the
+    |          |    |     |    |     |  | |  |         threshold is >= 0xFFFF
+    |          |    |     |    |     |  | |  |-------> sending congestion window
+    |          |    |     |    |     |  | |----------> (ack.quick<<1) |
+    |          |    |     |    |     |  |               ack.pingpong
+    |          |    |     |    |     |  |------------> Predicted tick of soft clock
+    |          |    |     |    |     |                 (delayed ACK control data)
+    |          |    |     |    |     |---------------> retransmit timeout
+    |          |    |     |    |---------------------> location of socket in memory
+    |          |    |     |--------------------------> socket reference count
+    |          |    |--------------------------------> inode
+    |          |-------------------------------------> unanswered 0-window probes
+    |------------------------------------------------> uid
 
 timer_active:
   0  no timer is pending
net/ipv4/tcp_ipv4.c +3 -2
index 5af8b80..173e20a 100644
@@ -2255,7 +2255,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
 		rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0);
 
 	seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
-			"%08X %5u %8d %lu %d %pK %lu %lu %u %u %d",
+			"%08X %5u %8d %lu %d %pK %lu %lu %u %u %d %d",
 		i, src, srcp, dest, destp, state,
 		tp->write_seq - tp->snd_una,
 		rx_queue,
@@ -2272,7 +2272,8 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
 		tp->snd_cwnd,
 		state == TCP_LISTEN ?
 		    fastopenq->max_qlen :
-		    (tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh));
+		    (tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh),
+		state == TCP_LISTEN ? atomic_read(&sk->sk_drops) : 0);
 }
 
 static void get_timewait4_sock(const struct inet_timewait_sock *tw,
net/ipv6/tcp_ipv6.c +4 -3
index d79a1af..1cd296a 100644
@@ -1795,8 +1795,8 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
 		rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0);
 
 	seq_printf(seq,
-		   "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
-		   "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %lu %lu %u %u %d\n",
+		   "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X %02X "
+		   "%08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %lu %lu %u %u %d %d\n",
 		   i,
 		   src->s6_addr32[0], src->s6_addr32[1],
 		   src->s6_addr32[2], src->s6_addr32[3], srcp,
@@ -1818,7 +1818,8 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
 		   tp->snd_cwnd,
 		   state == TCP_LISTEN ?
 			fastopenq->max_qlen :
-			(tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh)
+			(tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh),
+		   state == TCP_LISTEN ? atomic_read(&sp->sk_drops) : 0
 		   );
 }
 
Signature · 1 line
2.9.5
#1 lore raw
Quoted 9 lines · Stéphan Gorget

Those counters are exported for raw and udp but not for tcp, though they are incremented.

An example where it is useful is chasing listen overflow. Listen overflow are counted as a global counter in LINUX_MIB_LISTENOVERFLOWS accessible in /proc/net/netstat but there is no way to find related drops in the information exported for tcp. With this patch it will make possible to correlate growth of LINUX_MIB_LISTENOVERFLOWS with growth of drops for a tcp socket.

Hi Stéphan.

Eons ago, the decision was taken to declare /proc interface frozen.

In linux-4.7 I provided all the information you need using the modern inet_diag interface, [1]

Simply use iproute2/ss tool to access this information in a very efficient way (like filtering done in the kernel, instead having to parse a gigantic /proc output)

lpaa5:~# ss -tm state listening src :22
Recv-Q Send-Q Local Address:Port                 Peer Address:Port                
0      128             *:ssh                           *:*                    
	 skmem:(r0,rb8388608,t0,tb8388608,f0,w0,o0,bl0,d7)
0      128            :::ssh                          :::*                    
	 skmem:(r0,rb8388608,t0,tb8388608,f0,w0,o0,bl0,d0)

You can see here that the IPv4 listener for ssh had 7 drops.

Thanks.

[1] list of relevant commits.

commit 9caad864151e525929d323de96cad382da49c3b2

Author: Eric Dumazet <[email protected]>
Date:   Fri Apr 1 08:52:20 2016 -0700

tcp: increment sk_drops for listeners

Goal: packets dropped by a listener are accounted for.

This adds tcp_listendrop() helper, and clears sk_drops in sk_clone_lock() so that children do not inherit their parent drop count.

Note that we no longer increment LINUX_MIB_LISTENDROPS counter when sending a SYNCOOKIE, since the SYN packet generated a SYNACK. We already have a separate LINUX_MIB_SYNCOOKIESSENT

commit 532182cd610782db8c18230c2747626562032205

Author: Eric Dumazet <[email protected]>
Date:   Fri Apr 1 08:52:19 2016 -0700

tcp: increment sk_drops for dropped rx packets

Now ss can report sk_drops, we can instruct TCP to increment this per socket counter when it drops an incoming frame, to refine monitoring and debugging.

Following patch takes care of listeners drops.

commit 15239302edd46b184e758048253541fb211e315e

Author: Eric Dumazet <[email protected]>
Date:   Fri Apr 1 08:52:18 2016 -0700

sock_diag: add SK_MEMINFO_DROPS

Reporting sk_drops to user space was available for UDP sockets using /proc interface.

Add this to sock_diag, so that we can have the same information available to ss users, and we'll be able to add sk_drops indications for TCP sockets as well.

#2 lore raw
Quoted 11 lines · Eric Dumazet
Quoted 9 lines · Stéphan Gorget

Those counters are exported for raw and udp but not for tcp, though they are incremented.

An example where it is useful is chasing listen overflow. Listen overflow are counted as a global counter in LINUX_MIB_LISTENOVERFLOWS accessible in /proc/net/netstat but there is no way to find related drops in the information exported for tcp. With this patch it will make possible to correlate growth of LINUX_MIB_LISTENOVERFLOWS with growth of drops for a tcp socket.

Quoted 5 lines

Simply use iproute2/ss tool to access this information in a very efficient way (like filtering done in the kernel, instead having to parse a gigantic /proc output)

lpaa5:~# ss -tm state listening src :22

Thanks for the quick response, I'll use ss with those options that's exactly what I needed.