Skip to contentSkip to conversation

net: tcp: add mib counters to track zero window transitions

PATCH Superseded Florian Westphal 4 participants 16 messages Feb 17, 2014 – Feb 26, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: tcp: add mib counters to track zero window transitions

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

---
Eric, is this what you had in mind?

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

Thanks,
Florian

 include/uapi/linux/snmp.h |  3 +++
 net/ipv4/proc.c           |  3 +++
 net/ipv4/tcp_output.c     | 13 ++++++++++++-
 3 files changed, 18 insertions(+), 1 deletion(-)
include/uapi/linux/snmp.h +3 -0
index bbaba22..6404eed 100644
@@ -259,6 +259,9 @@ enum
 	LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES, /* TCPSpuriousRtxHostQueues */
 	LINUX_MIB_BUSYPOLLRXPACKETS,		/* BusyPollRxPackets */
 	LINUX_MIB_TCPAUTOCORKING,		/* TCPAutoCorking */
+	LINUX_MIB_TCPFROMZEROWINDOWADV,		/* TCPFromZeroWindowAdv */
+	LINUX_MIB_TCPTOZEROWINDOWADV,		/* TCPToZeroWindowAdv */
+	LINUX_MIB_TCPWANTZEROWINDOW,		/* TCPWantZeroWindow */
 	__LINUX_MIB_MAX
 };
 
net/ipv4/proc.c +3 -0
index a6c8a80..542d414 100644
@@ -280,6 +280,9 @@ static const struct snmp_mib snmp4_net_list[] = {
 	SNMP_MIB_ITEM("TCPSpuriousRtxHostQueues", LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES),
 	SNMP_MIB_ITEM("BusyPollRxPackets", LINUX_MIB_BUSYPOLLRXPACKETS),
 	SNMP_MIB_ITEM("TCPAutoCorking", LINUX_MIB_TCPAUTOCORKING),
+	SNMP_MIB_ITEM("TCPFromZeroWindowAdv", LINUX_MIB_TCPFROMZEROWINDOWADV),
+	SNMP_MIB_ITEM("TCPToZeroWindowAdv", LINUX_MIB_TCPTOZEROWINDOWADV),
+	SNMP_MIB_ITEM("TCPWantZeroWindow", LINUX_MIB_TCPWANTZEROWINDOW),
 	SNMP_MIB_SENTINEL
 };
 
net/ipv4/tcp_output.c +12 -1
index 48414fc..e8d6f14 100644
@@ -269,6 +269,7 @@ EXPORT_SYMBOL(tcp_select_initial_window);
 static u16 tcp_select_window(struct sock *sk)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
+	u32 old_win = tp->rcv_wnd;
 	u32 cur_win = tcp_receive_window(tp);
 	u32 new_win = __tcp_select_window(sk);
 
@@ -281,6 +282,9 @@ static u16 tcp_select_window(struct sock *sk)
 		 *
 		 * Relax Will Robinson.
 		 */
+		if (new_win == 0)
+			NET_INC_STATS_BH(sock_net(sk),
+					 LINUX_MIB_TCPWANTZEROWINDOW);
 		new_win = ALIGN(cur_win, 1 << tp->rx_opt.rcv_wscale);
 	}
 	tp->rcv_wnd = new_win;
@@ -298,8 +302,15 @@ static u16 tcp_select_window(struct sock *sk)
 	new_win >>= tp->rx_opt.rcv_wscale;
 
 	/* If we advertise zero window, disable fast path. */
-	if (new_win == 0)
+	if (new_win == 0) {
 		tp->pred_flags = 0;
+		if (old_win)
+			NET_INC_STATS_BH(sock_net(sk),
+					 LINUX_MIB_TCPTOZEROWINDOWADV);
+	} else if (old_win == 0) {
+		NET_INC_STATS_BH(sock_net(sk),
+				 LINUX_MIB_TCPFROMZEROWINDOWADV);
+	}
 
 	return new_win;
 }
Signature · 1 line
1.8.1.5
maintainer
#1 lore raw

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 8 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

Quoted 7 lines

---
Eric, is this what you had in mind?

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

Eric, ping?

#2 lore raw
Quoted 16 lines · David Miller

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 13 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

---
Eric, is this what you had in mind?

Quoted 4 lines
Quoted 2 lines

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

Eric, ping?

Thanks, I missed this patch. Let me think about it, thanks !

#3 lore raw
Quoted 17 lines · Eric Dumazet
Quoted 16 lines · David Miller

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 13 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

---
Eric, is this what you had in mind?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

Eric, ping?

Thanks, I missed this patch. Let me think about it, thanks !

We need NET_INC_STATS instead of NET_INC_STATS_BH, no?

Greetings,

Hannes

#4 lore raw
Quoted 18 lines · Hannes Frederic Sowa
Quoted 17 lines · Eric Dumazet
Quoted 16 lines · David Miller

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 13 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

---
Eric, is this what you had in mind?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

Eric, ping?

Thanks, I missed this patch. Let me think about it, thanks !

We need NET_INC_STATS instead of NET_INC_STATS_BH, no?

Ok, not strictly needed but just to keep the style, as tcp_select_window can be called from both, bh and process context.

Greetings,

Hannes

#5 lore raw
In reply to Hannes Frederic Sowa
Quoted 18 lines · Hannes Frederic Sowa
Quoted 17 lines · Eric Dumazet
Quoted 16 lines · David Miller

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 13 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

---
Eric, is this what you had in mind?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

Eric, ping?

Thanks, I missed this patch. Let me think about it, thanks !

We need NET_INC_STATS instead of NET_INC_STATS_BH, no?

sure, I can send v2 but I'll wait for (n)ack from Eric first before considering it.

tcp_transmit_skb (caller of tcp_select_window) also uses _BH which is why it ended up in tcp_select_window.

#6 lore raw
Quoted 5 lines · Florian Westphal

sure, I can send v2 but I'll wait for (n)ack from Eric first before considering it.

tcp_transmit_skb (caller of tcp_select_window) also uses _BH which is why it ended up in tcp_select_window.

Yes, it seems the NET_INC_STATS_BH() in tcp_transmit_skb() should really be a NET_INC_STATS(), even if it currently doesn't matter, even on 32bit arches.

#7 lore raw
In reply to Florian Westphal
Quoted 26 lines · Florian Westphal
Quoted 25 lines · Hannes Frederic Sowa
Quoted 23 lines · Eric Dumazet
Quoted 16 lines · David Miller

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 13 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

---
Eric, is this what you had in mind?

Quoted 4 lines
Quoted 2 lines

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

Eric, ping?

Thanks, I missed this patch. Let me think about it, thanks !

Quoted 7 lines
Quoted 1 line

We need NET_INC_STATS instead of NET_INC_STATS_BH, no?

sure, I can send v2 but I'll wait for (n)ack from Eric first before considering it.

tcp_transmit_skb (caller of tcp_select_window) also uses _BH which is why it ended up in tcp_select_window.

NET_STATS only use 32 bit counter and thus need not be protected with a seqlock on 32 bit platforms. As such, it does not matter, but e.g. the IP counter are prone to deadlocks if used with wrong postfix because of 64 bit counter thus protected by seqlock.

A pitty that the _STATS_BH postfixes have the opposite meaning of the bottom _bh postfixes.

Basically always safe is _STATS and if we are sure we can omit the bh disable call because we only call the function from bh, we can use _STATS_BH calls.

Greetings,

Hannnes

#8 lore raw

Sorry...

Quoted 6 lines · Hannes Frederic Sowa

NET_STATS only use 32 bit counter and thus need not be protected with a seqlock on 32 bit platforms. As such, it does not matter, but e.g. the IP counter are prone to deadlocks if used with wrong postfix because of 64 bit counter thus protected by seqlock.

A pitty that the _STATS_BH postfixes have the opposite meaning of the bottom

s/bottom$/locking/

Quoted 4 lines

_bh postfixes.

Basically always safe is _STATS and if we are sure we can omit the bh disable call because we only call the function from bh, we can use _STATS_BH calls.

Should read mails again before sending. ;)

#9 lore raw
In reply to Hannes Frederic Sowa
Quoted 10 lines · Hannes Frederic Sowa

NET_STATS only use 32 bit counter and thus need not be protected with a seqlock on 32 bit platforms. As such, it does not matter, but e.g. the IP counter are prone to deadlocks if used with wrong postfix because of 64 bit counter thus protected by seqlock.

A pitty that the _STATS_BH postfixes have the opposite meaning of the bottom _bh postfixes.

Basically always safe is _STATS and if we are sure we can omit the bh disable call because we only call the function from bh, we can use _STATS_BH calls.

Using __this_cpu_inc() is not safe in preemptable contexts.

Sure, x86 doesn't care, but other arches might.

Fortunately LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES can be incremented only for a retransmit, and they should always happen from BH.

Better avoid the confusion for this ultra rare case, I'll send a patch.

maintainer
#12 lore raw
In reply to Florian Westphal

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 8 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

Quoted 7 lines

---
Eric, is this what you had in mind?

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

What is happening with this patch? The discussion just died out.

#13 lore raw
Quoted 16 lines · David Miller

From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100

Quoted 13 lines

Three counters are added:
- one to track when we went from non-zero to zero window
- one to track the reverse
- one counter incremented when we want to announce zero window.

The latter is added because it can show cases where we want to close the window but can't because we would shrink window.

---
Eric, is this what you had in mind?

Quoted 4 lines
Quoted 2 lines

I re-ran my 'slow-sender-with-reader-that-does-not-drain-socket' scenario and, as expected, only TCPWANTZEROWINDOW increases.

What is happening with this patch? The discussion just died out.

I guess Eric is busy with TCP usec timer resolution changes. You can mark the patch as defered if you want; I can re-send it for 3.16 if needed.

#14 lore raw
Quoted 7 lines · Florian Westphal
Quoted 1 line · David Miller

What is happening with this patch? The discussion just died out.

I guess Eric is busy with TCP usec timer resolution changes. You can mark the patch as defered if you want; I can re-send it for 3.16 if needed.

Well, I was waiting you resend it using Hannes feedback ;)

That is using NET_INC_STATS() instead of NET_INC_STATS_BH()

I am sending the cleanup for LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES immediately.

#10 lore raw

PATCH 1/1 net: tcp: use NET_INC_STATS()

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>

While LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES can only be incremented in tcp_transmit_skb() from softirq (incoming message or timer activation), it is better to use NET_INC_STATS() instead of NET_INC_STATS_BH() as tcp_transmit_skb() can be called from process context.

This will avoid copy/paste confusion when/if we want to add other SNMP counters in tcp_transmit_skb()

Cc Hannes Frederic Sowa <[email protected]>
Cc Florian Westphal <[email protected]>
---
 net/ipv4/tcp_output.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_output.c +2 -2
index 09805817627b..d718482fd11c 100644
@@ -864,8 +864,8 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
 
 		if (unlikely(skb->fclone == SKB_FCLONE_ORIG &&
 			     fclone->fclone == SKB_FCLONE_CLONE))
-			NET_INC_STATS_BH(sock_net(sk),
-					 LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES);
+			NET_INC_STATS(sock_net(sk),
+				      LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES);
 
 		if (unlikely(skb_cloned(skb)))
 			skb = pskb_copy(skb, gfp_mask);
#15 lore raw
In reply to Eric Dumazet
Quoted 10 lines · Eric Dumazet
Quoted 7 lines · Florian Westphal
Quoted 1 line · David Miller

What is happening with this patch? The discussion just died out.

I guess Eric is busy with TCP usec timer resolution changes. You can mark the patch as defered if you want; I can re-send it for 3.16 if needed.

Well, I was waiting you resend it using Hannes feedback ;)

Heh. I was waiting for you to tell me wheter you reject the general
intention of the patch. Classic deadlock :)

Quoted 2 lines

I am sending the cleanup for LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES immediately.

Thanks Eric. I'll send v2 of the patch in a few minutes.

maintainer Applied
#11 lore raw

Re: [PATCH] net: tcp: use NET_INC_STATS()

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Tue, 25 Feb 2014 04:31:03 -0800

Quoted 8 lines

From: Eric Dumazet <[email protected]>

While LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES can only be incremented in tcp_transmit_skb() from softirq (incoming message or timer activation), it is better to use NET_INC_STATS() instead of NET_INC_STATS_BH() as tcp_transmit_skb() can be called from process context.

Quoted 4 lines

This will avoid copy/paste confusion when/if we want to add other SNMP counters in tcp_transmit_skb()

Applied, thanks Eric.