net: tcp: add mib counters to track zero window transitions
Subsystems (3)
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
@@ -259,6 +259,9 @@ enumLINUX_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
@@ -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
@@ -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
David Miller
maintainerFrom: 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
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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?
Quoted 16 lines · David Miller
From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100Quoted 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.
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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 17 lines · Eric Dumazet
Quoted 16 lines · David Miller
From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100Quoted 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.
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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
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 +0100Quoted 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.
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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_STATSinstead ofNET_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
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 +0100Quoted 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.
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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_STATSinstead ofNET_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.
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 oftcp_select_window) also uses_BHwhich is why it ended up intcp_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.
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 +0100Quoted 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.
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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_STATSinstead ofNET_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 oftcp_select_window) also uses_BHwhich is why it ended up intcp_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
Sorry...
Quoted 6 lines · Hannes Frederic Sowa
NET_STATSonly 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_BHpostfixes have the opposite meaning of the bottom
s/bottom$/locking/
Quoted 4 lines
_bhpostfixes.Basically always safe is
_STATSand if we are sure we can omit the bh disable call because we only call the function from bh, we can use_STATS_BHcalls.
Should read mails again before sending. ;)
Quoted 10 lines · Hannes Frederic Sowa
NET_STATSonly 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_BHpostfixes have the opposite meaning of the bottom_bhpostfixes.Basically always safe is
_STATSand if we are sure we can omit the bh disable call because we only call the function from bh, we can use_STATS_BHcalls.
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.
David Miller
maintainerFrom: 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
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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.
Quoted 16 lines · David Miller
From: Florian Westphal <[email protected]>
Date: Mon, 17 Feb 2014 22:57:48 +0100Quoted 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.
Suggested-by Eric Dumazet <[email protected]>Signed-off-by Florian Westphal <[email protected]>---
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.
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.
PATCH 1/1 net: tcp: use NET_INC_STATS()
In reply to Eric DumazetFrom: 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()
--- net/ipv4/tcp_output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_output.c +2 -2
@@ -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);
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_HOSTQUEUESimmediately.
Thanks Eric. I'll send v2 of the patch in a few minutes.
Re: [PATCH] net: tcp: use NET_INC_STATS()
In reply to Eric DumazetFrom: 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_HOSTQUEUEScan only be incremented intcp_transmit_skb()from softirq (incoming message or timer activation), it is better to useNET_INC_STATS()instead ofNET_INC_STATS_BH()astcp_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()Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks Eric.