Super TSO v3
Subsystems (4)
David S. Miller
maintainerPATCH 1/1 Super TSO v3
Ok, new version. This weekend has been productive.
I discoevered a performance anomaly with Linux receivers, cause by enormous stretch ACK generation, which you'll need to fix if you want to test this patch against Linux receivers.
When we do ucopy receive (ie. copying directly to userspace during tcp input processing) we attempt to delay the ACK until cleanup_rbuf() is invoked. Most of the time this technique works very well, and we emit one ACK advertising the largest window.
But this explodes if the ucopy prequeue is large enough. When the receiver is cpu limited and TSO frames are large, the receiver is inundated with ucopy processing, such that the ACK comes out very late. Often, this is so late that by the time the sender gets the ACK the window has emptied too much to be kept full by the sender.
The existing TSO code mostly avoided this by keeping the TSO packets no larger than 1/8 of the available window. But with the new code we can get much larger TSO frames.
The other major change now is that we do TSO deferral both at sendmsg()/sendpage() packet send time, as well as when processing ACKs to make progress in the write queue.
The guts of the logic is in tcp_tso_should_defer(). And when dealing with a TSO frame, tcp_write_xmit() calls this instead of tcp_nagle_test(). So you can view this deferral as a sort of "TSO Nagle".
In v2, there was some code that checked if in_flight was non-zero, to make sure we will get some ACKs back, but that is implicitly handled by the "1/tso_win_divisor" check.
Potential cleanups are of course still sprinkled all over. For example, __tcp_push_pending_frames() and __tcp_data_snd_check() are basically identical now.
_iff_ you test this code, please make sure the receiver bug fix is installed on any Linux systems you are using as the receiver in your testing. There are three attachments:
1) the 2.6.12-rcX Super TSO patch v3
2) the 2.6.12.rcX TCP receiver bug fix
3) the 2.4.30 TCP receiver bug fix
Enjoy.
include/linux/tcp.h renamed from include/linux/tcp.h.~1~ +4 -2
@@ -280,13 +280,15 @@ struct tcp_sock {__u32 snd_wnd;/* The window we expect to receive */ __u32 max_window;/* Maximal window ever seen from peer */ __u32 pmtu_cookie;/* Last pmtu seen by socket */ -__u32 mss_cache;/* Cached effective mss, not including SACKS */ -__u16 mss_cache_std;/* Like mss_cache, but without TSO */ +__u16 mss_cache;/* Cached effective mss, not including SACKS */ +__u16 xmit_size_goal;/* Goal for segmenting output packets */ +__u32 xmit_size_cache;/* Cache for keeping xmit_size_goal uptodate */ __u16 ext_header_len;/* Network protocol overhead (IP/IPv6 options) */ __u8 ca_state;/* State of fast-retransmit machine */ __u8 retransmits;/* Number of unrecovered RTO timeouts. */ __u16 advmss;/* Advertised MSS */ +__u16 deferred;/* Packets deferred for segmentation */ __u32 window_clamp;/* Maximal window to advertise */ __u32 rcv_ssthresh;/* Current window clamp */
include/net/sock.h renamed from include/net/sock.h.~1~ +5 -2
@@ -1130,13 +1130,16 @@ static inline void sk_stream_moderate_snstatic inline struct sk_buff *sk_stream_alloc_pskb (struct sock *sk,int size,int mem,int gfp) { -struct sk_buff *skb =alloc_skb (size + sk->sk_prot->max_header, gfp); +struct sk_buff *skb; +int hdr_len; + hdr_len =SKB_DATA_ALIGN (sk->sk_prot->max_header); + skb =alloc_skb (size + hdr_len, gfp);if (skb) { skb->truesize += mem;if (sk->sk_forward_alloc >= (int )skb->truesize ||sk_stream_mem_schedule (sk, skb->truesize,0 )) { -skb_reserve (skb, sk->sk_prot->max_header); +skb_reserve (skb, hdr_len);return skb; }__kfree_skb (skb);
include/net/tcp.h renamed from include/net/tcp.h.~1~ +26 -110
204 lines not on this page · raw message
net/ipv4/tcp.c renamed from net/ipv4/tcp.c.~1~ +17 -22
@@ -634,7 +634,7 @@ static ssize_t do_tcp_sendpages(struct s size_t psize, int flags) {struct tcp_sock *tp =tcp_sk (sk); -int mss_now; +int mss_now, size_goal;int err;ssize_t copied;long timeo =sock_sndtimeo (sk, flags &MSG_DONTWAIT );
@@ -647,6 +647,7 @@ static ssize_t do_tcp_sendpages(struct sclear_bit (SOCK_ASYNC_NOSPACE , &sk->sk_socket->flags); mss_now =tcp_current_mss (sk, !(flags&MSG_OOB )); + size_goal = tp->xmit_size_goal; copied =0 ; err = -EPIPE ;
@@ -660,7 +661,7 @@ static ssize_t do_tcp_sendpages(struct sint offset = poffset %PAGE_SIZE ;int size =min_t (size_t, psize,PAGE_SIZE - offset); -if (!sk->sk_send_head || (copy = mss_now - skb->len) <=0 ) { +if (!sk->sk_send_head || (copy = size_goal - skb->len) <=0 ) { new_segment:if (!sk_stream_memory_free (sk)) goto wait_for_sndbuf;
@@ -671,7 +672,7 @@ new_segment: goto wait_for_memory;skb_entail (sk, tp, skb); - copy = mss_now; + copy = size_goal; }if (copy > size)
@@ -712,7 +713,7 @@ new_segment:if (!(psize -= copy)) goto out; -if (skb->len != mss_now || (flags &MSG_OOB )) +if (skb->len != size_goal || (flags &MSG_OOB ))continue ;if (forced_push (tp)) {
@@ -732,6 +733,7 @@ wait_for_memory: goto do_error; mss_now =tcp_current_mss (sk, !(flags&MSG_OOB )); + size_goal = tp->xmit_size_goal; } out:
@@ -773,15 +775,11 @@ ssize_t tcp_sendpage(struct socket *sockstatic inline int select_size (struct sock *sk,struct tcp_sock *tp) { -int tmp = tp->mss_cache_std; +int tmp = tp->mss_cache; -if (sk->sk_route_caps &NETIF_F_SG ) { -int pgbreak =SKB_MAX_HEAD (MAX_TCP_HEADER ); +if (sk->sk_route_caps &NETIF_F_SG ) + tmp =0 ; -if (tmp >= pgbreak && - tmp <= pgbreak + (MAX_SKB_FRAGS -1 ) *PAGE_SIZE ) - tmp = pgbreak; - }return tmp; }
@@ -792,7 +790,7 @@ int tcp_sendmsg(struct kiocb *iocb, strustruct tcp_sock *tp =tcp_sk (sk);struct sk_buff *skb;int iovlen, flags; -int mss_now; +int mss_now, size_goal;int err, copied;long timeo;
@@ -811,6 +809,7 @@ int tcp_sendmsg(struct kiocb *iocb, struclear_bit (SOCK_ASYNC_NOSPACE , &sk->sk_socket->flags); mss_now =tcp_current_mss (sk, !(flags&MSG_OOB )); + size_goal = tp->xmit_size_goal;/* Ok commence sending. */ iovlen = msg->msg_iovlen;
@@ -833,7 +832,7 @@ int tcp_sendmsg(struct kiocb *iocb, stru skb = sk->sk_write_queue.prev;if (!sk->sk_send_head || - (copy = mss_now - skb->len) <=0 ) { + (copy = size_goal - skb->len) <=0 ) { new_segment:/* Allocate new segment. If the interface is SG,
@@ -856,7 +855,7 @@ new_segment: skb->ip_summed =CHECKSUM_HW ;skb_entail (sk, tp, skb); - copy = mss_now; + copy = size_goal; }/* Try to append data to the end of skb. */
@@ -891,11 +890,6 @@ new_segment:tcp_mark_push (tp, skb); goto new_segment; }else if (page) { -/* If page is cached, align -* offset to L1 cache boundary -*/ - off = (off +L1_CACHE_BYTES -1 ) & - ~(L1_CACHE_BYTES -1 );if (off ==PAGE_SIZE ) {put_page (page);TCP_PAGE (sk) = page =NULL ;
@@ -956,7 +950,7 @@ new_segment:if ((seglen -= copy) ==0 && iovlen ==0 ) goto out; -if (skb->len != mss_now || (flags &MSG_OOB )) +if (skb->len != size_goal || (flags &MSG_OOB ))continue ;if (forced_push (tp)) {
@@ -976,6 +970,7 @@ wait_for_memory: goto do_error; mss_now =tcp_current_mss (sk, !(flags&MSG_OOB )); + size_goal = tp->xmit_size_goal; } }
@@ -2135,7 +2130,7 @@ void tcp_get_info(struct sock *sk, struc info->tcpi_rto =jiffies_to_usecs (tp->rto); info->tcpi_ato =jiffies_to_usecs (tp->ack.ato); - info->tcpi_snd_mss = tp->mss_cache_std; + info->tcpi_snd_mss = tp->mss_cache; info->tcpi_rcv_mss = tp->ack.rcv_mss; info->tcpi_unacked = tp->packets_out;
@@ -2185,7 +2180,7 @@ int tcp_getsockopt(struct sock *sk, intswitch (optname) {case TCP_MAXSEG : - val = tp->mss_cache_std; + val = tp->mss_cache;if (!val && ((1 << sk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) val = tp->rx_opt.user_mss;break ;
net/ipv4/tcp_input.c renamed from net/ipv4/tcp_input.c.~1~ +21 -30
125 lines not on this page · raw message
net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c.~1~ +2 -1
@@ -2060,7 +2060,8 @@ static int tcp_v4_init_sock(struct sock*/ tp->snd_ssthresh =0x7fffffff ;/* Infinity */ tp->snd_cwnd_clamp = ~0 ; - tp->mss_cache_std = tp->mss_cache =536 ; + tp->mss_cache =536 ; + tp->xmit_size_cache = ~0 ; tp->reordering = sysctl_tcp_reordering;
net/ipv4/tcp_output.c renamed from net/ipv4/tcp_output.c.~1~ +441 -125
692 lines not on this page · raw message
net/ipv6/tcp_ipv6.c renamed from net/ipv6/tcp_ipv6.c.~1~ +2 -1
@@ -2021,7 +2021,8 @@ static int tcp_v6_init_sock(struct sock*/ tp->snd_ssthresh =0x7fffffff ; tp->snd_cwnd_clamp = ~0 ; - tp->mss_cache_std = tp->mss_cache =536 ; + tp->mss_cache =536 ; + tp->xmit_size_cache = ~0 ; tp->reordering = sysctl_tcp_reordering;
net/ipv4/tcp_input.c +1 -10
@@ -4355,16 +4355,7 @@ int tcp_rcv_established(struct sock *sk, goto no_ack; } -if (eaten) { -if (tcp_in_quickack_mode (tp)) { -tcp_send_ack (sk); - }else { -tcp_send_delayed_ack (sk); - } - }else { -__tcp_ack_snd_check (sk,0 ); - } - +__tcp_ack_snd_check (sk,0 ); no_ack:if (eaten)__kfree_skb (skb);
[TCP]: Fix stretch ACK performance killer when doing ucopy.
When we are doing ucopy, we try to defer the ACK generation to cleanup_rbuf(). This works most of the time very well, but if the ucopy prequeue is large, this ACKing behavior kills performance.
With TSO, it is possible to fill the prequeue so large that by the time the ACK is sent and gets back to the sender, most of the window has emptied of data and performance suffers significantly.
This behavior does help in some cases, so we should think about re-enabling this trick in the future, using some kind of limit in order to avoid the bug case.
net/ipv4/tcp_input.c renamed from net/ipv4/tcp_input.c.~1~ +1 -10
@@ -4243,16 +4243,7 @@ goto no_ack; } -if (eaten) { -if (tcp_in_quickack_mode (tp)) { -tcp_send_ack (sk); - }else { -tcp_send_delayed_ack (sk); - } - }else { -__tcp_ack_snd_check (sk,0 ); - } - +__tcp_ack_snd_check (sk,0 ); no_ack:if (eaten)__kfree_skb (skb);
Quoted 4 lines · David S. Miller
I discoevered a performance anomaly with Linux receivers, cause by enormous stretch ACK generation, which you'll need to fix if you want to test this patch against Linux receivers.
Are there non-Linux systems that have the same receive issue?
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtDavid S. Miller
maintainerFrom: Herbert Xu <[email protected]>
Date: Tue, 24 May 2005 07:34:38 +1000
Quoted 1 line
Are there non-Linux systems that have the same receive issue?
Some generate stretch ACKs for other reasons (miscalculation of MSS due to TCP Timestamps) but I doubt any other OS implements the Van Jacobson ucopy stuff we do, and also implement the same ACKing hack on top of that :-)
Quoted 5 lines · David S. Miller
The guts of the logic is in
tcp_tso_should_defer(). And when dealing with a TSO frame,tcp_write_xmit()calls this instead oftcp_nagle_test(). So you can view this deferral as a sort of "TSO Nagle".
Should we skip this step if the socket has Nagle turned off?
Also why are we doing this check in tcp_push_one? The only way we can get there is if the TSO goal has been reached or there is out-of-band stuff to send.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtDavid S. Miller
maintainerFrom: Herbert Xu <[email protected]>
Subject: Re: [PATCH] Super TSO v3
Date: Tue, 24 May 2005 10:32:08 +1000
Quoted 8 lines · David S. Miller
Quoted 5 lines
The guts of the logic is in
tcp_tso_should_defer(). And when dealing with a TSO frame,tcp_write_xmit()calls this instead oftcp_nagle_test(). So you can view this deferral as a sort of "TSO Nagle".Should we skip this step if the socket has Nagle turned off?
No, that Nagle is trying to achieve something different (optimize request/response type communication) compared to what we're doing here (optimizing the number of transmit calls per byte during a bulk transfer, without allowing the congestion window to empty too much).
Quoted 3 lines
Also why are we doing this check in
tcp_push_one? The only way we can get there is if the TSO goal has been reached or there is out-of-band stuff to send.
Good point, that copy of the test can be removed.
Quoted 8 lines · David S. Miller
Quoted 2 lines
Should we skip this step if the socket has Nagle turned off?
No, that Nagle is trying to achieve something different (optimize request/response type communication) compared to what we're doing here (optimizing the number of transmit calls per byte during a bulk transfer, without allowing the congestion window to empty too much).
True, the Nagle algorithm itself aims to do something different from this function. However, the act of turning Nagle off is an indication that the application wants to minimise the latency by sending things out ASAP. So we should either respect that here by not delaying the packets to increase the TSO size, or we'll need a new socket option to do that for TSO.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtDavid S. Miller
maintainerFrom: Herbert Xu <[email protected]>
Date: Tue, 24 May 2005 12:32:57 +1000
Quoted 6 lines
True, the Nagle algorithm itself aims to do something different from this function. However, the act of turning Nagle off is an indication that the application wants to minimise the latency by sending things out ASAP. So we should either respect that here by not delaying the packets to increase the TSO size, or we'll need a new socket option to do that for TSO.
Sure, we can check tp->nonagle to turn this deferring off.
But, I bet there are folks who want traditional Nagle turned off, yet TSO chunking enabled.
Quoted 12 lines · David S. Miller
From: Herbert Xu <[email protected]>
Date: Tue, 24 May 2005 12:32:57 +1000Quoted 6 lines
True, the Nagle algorithm itself aims to do something different from this function. However, the act of turning Nagle off is an indication that the application wants to minimise the latency by sending things out ASAP. So we should either respect that here by not delaying the packets to increase the TSO size, or we'll need a new socket option to do that for TSO.
Quoted 4 lines
Sure, we can check
tp->nonagleto turn this deferring off.But, I bet there are folks who want traditional Nagle turned off, yet TSO chunking enabled.
I'm not sure there will be very many of those. I would have thought the folks who turn-off Nagle are typically doing small sends. If they were not wanting to wait to aggregate their small sends into MSS segments, or wait for the RTT, I doubt thet are looking to wait to aggregate to something larger than the MSS.
rick jones
Quoted 3 lines · On Mon, 23 May 2005 12:19:43 -0700 (PDT) "David S. Miller"…
Ok, new version. This weekend has been productive.
I wonder if the TSO stuff would fix the performance problems with MacOSX and their broken delayed ack?
David S. Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Tue, 24 May 2005 16:42:19 -0700
Quoted 7 lines
Quoted 1 line · On Mon, 23 May 2005 12:19:43 -0700 (PDT) "David S. Miller"…
Ok, new version. This weekend has been productive.
I wonder if the TSO stuff would fix the performance problems with MacOSX and their broken delayed ack?
This is very possible, and people are free to test it out to verify :-)