]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv4/tcp_output.c
[TCP]: reduce tcp_output's indentation levels a bit
[linux-2.6-omap-h63xx.git] / net / ipv4 / tcp_output.c
index e5130a7fe181865f70476f402007d941b37af707..454cf84b6154f8152147feecf7110495ad186ddd 100644 (file)
@@ -61,27 +61,24 @@ int sysctl_tcp_base_mss __read_mostly = 512;
 /* By default, RFC2861 behavior.  */
 int sysctl_tcp_slow_start_after_idle __read_mostly = 1;
 
-static inline void tcp_packets_out_inc(struct sock *sk,
-                                      const struct sk_buff *skb)
+static void tcp_event_new_data_sent(struct sock *sk, struct sk_buff *skb)
 {
        struct tcp_sock *tp = tcp_sk(sk);
-       int orig = tp->packets_out;
+       unsigned int prior_packets = tp->packets_out;
+
+       tcp_advance_send_head(sk, skb);
+       tp->snd_nxt = TCP_SKB_CB(skb)->end_seq;
+
+       /* Don't override Nagle indefinately with F-RTO */
+       if (tp->frto_counter == 2)
+               tp->frto_counter = 3;
 
        tp->packets_out += tcp_skb_pcount(skb);
-       if (!orig)
+       if (!prior_packets)
                inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
                                          inet_csk(sk)->icsk_rto, TCP_RTO_MAX);
 }
 
-static void update_send_head(struct sock *sk, struct sk_buff *skb)
-{
-       struct tcp_sock *tp = tcp_sk(sk);
-
-       tcp_advance_send_head(sk, skb);
-       tp->snd_nxt = TCP_SKB_CB(skb)->end_seq;
-       tcp_packets_out_inc(sk, skb);
-}
-
 /* SND.NXT, if window was not shrunk.
  * If window has been shrunk, what should we make? It is not clear at all.
  * Using SND.UNA we will fail to open window, SND.NXT is out of window. :-(
@@ -92,10 +89,10 @@ static inline __u32 tcp_acceptable_seq(struct sock *sk)
 {
        struct tcp_sock *tp = tcp_sk(sk);
 
-       if (!before(tp->snd_una+tp->snd_wnd, tp->snd_nxt))
+       if (!before(tcp_wnd_end(tp), tp->snd_nxt))
                return tp->snd_nxt;
        else
-               return tp->snd_una+tp->snd_wnd;
+               return tcp_wnd_end(tp);
 }
 
 /* Calculate mss to advertise in SYN segment.
@@ -633,7 +630,8 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
        tp->write_seq = TCP_SKB_CB(skb)->end_seq;
        skb_header_release(skb);
        tcp_add_write_queue_tail(sk, skb);
-       sk_charge_skb(sk, skb);
+       sk->sk_wmem_queued += skb->truesize;
+       sk_mem_charge(sk, skb->truesize);
 }
 
 static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, unsigned int mss_now)
@@ -653,23 +651,18 @@ static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, unsigned
 }
 
 /* When a modification to fackets out becomes necessary, we need to check
- * skb is counted to fackets_out or not. Another important thing is to
- * tweak SACK fastpath hint too as it would overwrite all changes unless
- * hint is also changed.
+ * skb is counted to fackets_out or not.
  */
-static void tcp_adjust_fackets_out(struct tcp_sock *tp, struct sk_buff *skb,
+static void tcp_adjust_fackets_out(struct sock *sk, struct sk_buff *skb,
                                   int decr)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        if (!tp->sacked_out || tcp_is_reno(tp))
                return;
 
-       if (!before(tp->highest_sack, TCP_SKB_CB(skb)->seq))
+       if (after(tcp_highest_sack_seq(tp), TCP_SKB_CB(skb)->seq))
                tp->fackets_out -= decr;
-
-       /* cnt_hint is "off-by-one" compared with fackets_out (see sacktag) */
-       if (tp->fastpath_skb_hint != NULL &&
-           after(TCP_SKB_CB(tp->fastpath_skb_hint)->seq, TCP_SKB_CB(skb)->seq))
-               tp->fastpath_cnt_hint -= decr;
 }
 
 /* Function to create two new TCP segments.  Shrinks the given segment
@@ -702,7 +695,8 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
        if (buff == NULL)
                return -ENOMEM; /* We'll just try again later. */
 
-       sk_charge_skb(sk, buff);
+       sk->sk_wmem_queued += buff->truesize;
+       sk_mem_charge(sk, buff->truesize);
        nlen = skb->len - len - nsize;
        buff->truesize += nlen;
        skb->truesize -= nlen;
@@ -712,16 +706,11 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
        TCP_SKB_CB(buff)->end_seq = TCP_SKB_CB(skb)->end_seq;
        TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(buff)->seq;
 
-       if (tcp_is_sack(tp) && tp->sacked_out &&
-           (TCP_SKB_CB(skb)->seq == tp->highest_sack))
-               tp->highest_sack = TCP_SKB_CB(buff)->seq;
-
        /* PSH and FIN should only be set in the second packet. */
        flags = TCP_SKB_CB(skb)->flags;
        TCP_SKB_CB(skb)->flags = flags & ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH);
        TCP_SKB_CB(buff)->flags = flags;
        TCP_SKB_CB(buff)->sacked = TCP_SKB_CB(skb)->sacked;
-       TCP_SKB_CB(skb)->sacked &= ~TCPCB_AT_TAIL;
 
        if (!skb_shinfo(skb)->nr_frags && skb->ip_summed != CHECKSUM_PARTIAL) {
                /* Copy and checksum data tail into the new buffer. */
@@ -772,7 +761,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
                        tcp_dec_pcount_approx_int(&tp->sacked_out, diff);
                        tcp_verify_left_out(tp);
                }
-               tcp_adjust_fackets_out(tp, skb, diff);
+               tcp_adjust_fackets_out(sk, skb, diff);
        }
 
        /* Link BUFF into the send queue. */
@@ -830,7 +819,7 @@ int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len)
 
        skb->truesize        -= len;
        sk->sk_wmem_queued   -= len;
-       sk->sk_forward_alloc += len;
+       sk_mem_uncharge(sk, len);
        sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
 
        /* Any change of skb->len requires recalculation of tso
@@ -1022,13 +1011,29 @@ static void tcp_cwnd_validate(struct sock *sk)
        }
 }
 
-static unsigned int tcp_window_allows(struct tcp_sock *tp, struct sk_buff *skb, unsigned int mss_now, unsigned int cwnd)
+/* Returns the portion of skb which can be sent right away without
+ * introducing MSS oddities to segment boundaries. In rare cases where
+ * mss_now != mss_cache, we will request caller to create a small skb
+ * per input skb which could be mostly avoided here (if desired).
+ */
+static unsigned int tcp_mss_split_point(struct sock *sk, struct sk_buff *skb,
+                                       unsigned int mss_now,
+                                       unsigned int cwnd)
 {
-       u32 window, cwnd_len;
+       struct tcp_sock *tp = tcp_sk(sk);
+       u32 needed, window, cwnd_len;
 
-       window = (tp->snd_una + tp->snd_wnd - TCP_SKB_CB(skb)->seq);
+       window = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq;
        cwnd_len = mss_now * cwnd;
-       return min(window, cwnd_len);
+
+       if (likely(cwnd_len <= window && skb != tcp_write_queue_tail(sk)))
+               return cwnd_len;
+
+       if (skb == tcp_write_queue_tail(sk) && cwnd_len <= skb->len)
+               return cwnd_len;
+
+       needed = min(skb->len, window);
+       return needed - needed % mss_now;
 }
 
 /* Can at least one segment of SKB be sent right now, according to the
@@ -1128,7 +1133,7 @@ static inline int tcp_snd_wnd_test(struct tcp_sock *tp, struct sk_buff *skb, uns
        if (skb->len > cur_mss)
                end_seq = TCP_SKB_CB(skb)->seq + cur_mss;
 
-       return !after(end_seq, tp->snd_una + tp->snd_wnd);
+       return !after(end_seq, tcp_wnd_end(tp));
 }
 
 /* This checks if the data bearing packet SKB (usually tcp_send_head(sk))
@@ -1162,8 +1167,7 @@ int tcp_may_send_now(struct sock *sk)
        return (skb &&
                tcp_snd_test(sk, skb, tcp_current_mss(sk, 1),
                             (tcp_skb_is_last(sk, skb) ?
-                             TCP_NAGLE_PUSH :
-                             tp->nonagle)));
+                             tp->nonagle : TCP_NAGLE_PUSH)));
 }
 
 /* Trim TSO SKB to LEN bytes, put the remaining data into a new packet
@@ -1183,11 +1187,12 @@ static int tso_fragment(struct sock *sk, struct sk_buff *skb, unsigned int len,
        if (skb->len != skb->data_len)
                return tcp_fragment(sk, skb, len, mss_now);
 
-       buff = sk_stream_alloc_pskb(sk, 0, 0, GFP_ATOMIC);
+       buff = sk_stream_alloc_skb(sk, 0, GFP_ATOMIC);
        if (unlikely(buff == NULL))
                return -ENOMEM;
 
-       sk_charge_skb(sk, buff);
+       sk->sk_wmem_queued += buff->truesize;
+       sk_mem_charge(sk, buff->truesize);
        buff->truesize += nlen;
        skb->truesize -= nlen;
 
@@ -1236,7 +1241,8 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
                goto send_now;
 
        /* Defer for less than two clock ticks. */
-       if (!tp->tso_deferred && ((jiffies<<1)>>1) - (tp->tso_deferred>>1) > 1)
+       if (tp->tso_deferred &&
+           ((jiffies << 1) >> 1) - (tp->tso_deferred >> 1) > 1)
                goto send_now;
 
        in_flight = tcp_packets_in_flight(tp);
@@ -1244,7 +1250,7 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
        BUG_ON(tcp_skb_pcount(skb) <= 1 ||
               (tp->snd_cwnd <= in_flight));
 
-       send_win = (tp->snd_una + tp->snd_wnd) - TCP_SKB_CB(skb)->seq;
+       send_win = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq;
 
        /* From in_flight test above, we know that cwnd > in_flight.  */
        cong_win = (tp->snd_cwnd - in_flight) * tp->mss_cache;
@@ -1296,7 +1302,6 @@ static int tcp_mtu_probe(struct sock *sk)
        int len;
        int probe_size;
        int size_needed;
-       unsigned int pif;
        int copy;
        int mss_now;
 
@@ -1326,14 +1331,12 @@ static int tcp_mtu_probe(struct sock *sk)
 
        if (tp->snd_wnd < size_needed)
                return -1;
-       if (after(tp->snd_nxt + size_needed, tp->snd_una + tp->snd_wnd))
+       if (after(tp->snd_nxt + size_needed, tcp_wnd_end(tp)))
                return 0;
 
-       /* Do we need to wait to drain cwnd? */
-       pif = tcp_packets_in_flight(tp);
-       if (pif + 2 > tp->snd_cwnd) {
-               /* With no packets in flight, don't stall. */
-               if (pif == 0)
+       /* Do we need to wait to drain cwnd? With none in flight, don't stall */
+       if (tcp_packets_in_flight(tp) + 2 > tp->snd_cwnd) {
+               if (!tcp_packets_in_flight(tp))
                        return -1;
                else
                        return 0;
@@ -1342,10 +1345,10 @@ static int tcp_mtu_probe(struct sock *sk)
        /* We're allowed to probe.  Build it now. */
        if ((nskb = sk_stream_alloc_skb(sk, probe_size, GFP_ATOMIC)) == NULL)
                return -1;
-       sk_charge_skb(sk, nskb);
+       sk->sk_wmem_queued += nskb->truesize;
+       sk_mem_charge(sk, nskb->truesize);
 
        skb = tcp_send_head(sk);
-       tcp_insert_write_queue_before(nskb, skb, sk);
 
        TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(skb)->seq;
        TCP_SKB_CB(nskb)->end_seq = TCP_SKB_CB(skb)->seq + probe_size;
@@ -1354,10 +1357,10 @@ static int tcp_mtu_probe(struct sock *sk)
        nskb->csum = 0;
        nskb->ip_summed = skb->ip_summed;
 
-       len = 0;
-       while (len < probe_size) {
-               next = tcp_write_queue_next(sk, skb);
+       tcp_insert_write_queue_before(nskb, skb, sk);
 
+       len = 0;
+       tcp_for_write_queue_from_safe(skb, next, sk) {
                copy = min_t(int, skb->len, probe_size - len);
                if (nskb->ip_summed)
                        skb_copy_bits(skb, 0, skb_put(nskb, copy), copy);
@@ -1370,7 +1373,7 @@ static int tcp_mtu_probe(struct sock *sk)
                         * Throw it away. */
                        TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags;
                        tcp_unlink_write_queue(skb, sk);
-                       sk_stream_free_skb(sk, skb);
+                       sk_wmem_free_skb(sk, skb);
                } else {
                        TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags &
                                                   ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH);
@@ -1386,7 +1389,9 @@ static int tcp_mtu_probe(struct sock *sk)
                }
 
                len += copy;
-               skb = next;
+
+               if (len >= probe_size)
+                       break;
        }
        tcp_init_tso_segs(sk, nskb, nskb->len);
 
@@ -1397,7 +1402,7 @@ static int tcp_mtu_probe(struct sock *sk)
                /* Decrement cwnd here because we are sending
                * effectively two packets. */
                tp->snd_cwnd--;
-               update_send_head(sk, nskb);
+               tcp_event_new_data_sent(sk, nskb);
 
                icsk->icsk_mtup.probe_size = tcp_mss_to_mtu(sk, nskb->len);
                tp->mtu_probe.probe_seq_start = TCP_SKB_CB(nskb)->seq;
@@ -1465,17 +1470,9 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
                }
 
                limit = mss_now;
-               if (tso_segs > 1) {
-                       limit = tcp_window_allows(tp, skb,
-                                                 mss_now, cwnd_quota);
-
-                       if (skb->len < limit) {
-                               unsigned int trim = skb->len % mss_now;
-
-                               if (trim)
-                                       limit = skb->len - trim;
-                       }
-               }
+               if (tso_segs > 1)
+                       limit = tcp_mss_split_point(sk, skb, mss_now,
+                                                   cwnd_quota);
 
                if (skb->len > limit &&
                    unlikely(tso_fragment(sk, skb, limit, mss_now)))
@@ -1489,7 +1486,7 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
                /* Advance the send_head.  This one is sent out.
                 * This call will increment packets_out.
                 */
-               update_send_head(sk, skb);
+               tcp_event_new_data_sent(sk, skb);
 
                tcp_minshall_update(tp, mss_now, skb);
                sent_pkts++;
@@ -1522,7 +1519,6 @@ void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss,
  */
 void tcp_push_one(struct sock *sk, unsigned int mss_now)
 {
-       struct tcp_sock *tp = tcp_sk(sk);
        struct sk_buff *skb = tcp_send_head(sk);
        unsigned int tso_segs, cwnd_quota;
 
@@ -1537,17 +1533,9 @@ void tcp_push_one(struct sock *sk, unsigned int mss_now)
                BUG_ON(!tso_segs);
 
                limit = mss_now;
-               if (tso_segs > 1) {
-                       limit = tcp_window_allows(tp, skb,
-                                                 mss_now, cwnd_quota);
-
-                       if (skb->len < limit) {
-                               unsigned int trim = skb->len % mss_now;
-
-                               if (trim)
-                                       limit = skb->len - trim;
-                       }
-               }
+               if (tso_segs > 1)
+                       limit = tcp_mss_split_point(sk, skb, mss_now,
+                                                   cwnd_quota);
 
                if (skb->len > limit &&
                    unlikely(tso_fragment(sk, skb, limit, mss_now)))
@@ -1557,7 +1545,7 @@ void tcp_push_one(struct sock *sk, unsigned int mss_now)
                TCP_SKB_CB(skb)->when = tcp_time_stamp;
 
                if (likely(!tcp_transmit_skb(sk, skb, 1, sk->sk_allocation))) {
-                       update_send_head(sk, skb);
+                       tcp_event_new_data_sent(sk, skb);
                        tcp_cwnd_validate(sk);
                        return;
                }
@@ -1634,7 +1622,7 @@ u32 __tcp_select_window(struct sock *sk)
        if (mss > full_space)
                mss = full_space;
 
-       if (free_space < full_space/2) {
+       if (free_space < (full_space >> 1)) {
                icsk->icsk_ack.quick = 0;
 
                if (tcp_memory_pressure)
@@ -1673,7 +1661,7 @@ u32 __tcp_select_window(struct sock *sk)
                if (window <= free_space - mss || window > free_space)
                        window = (free_space/mss)*mss;
                else if (mss == full_space &&
-                        free_space > window + full_space/2)
+                        free_space > window + (full_space >> 1))
                        window = free_space;
        }
 
@@ -1685,82 +1673,77 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *skb, int m
 {
        struct tcp_sock *tp = tcp_sk(sk);
        struct sk_buff *next_skb = tcp_write_queue_next(sk, skb);
+       int skb_size, next_skb_size;
+       u16 flags;
 
        /* The first test we must make is that neither of these two
         * SKB's are still referenced by someone else.
         */
-       if (!skb_cloned(skb) && !skb_cloned(next_skb)) {
-               int skb_size = skb->len, next_skb_size = next_skb->len;
-               u16 flags = TCP_SKB_CB(skb)->flags;
+       if (skb_cloned(skb) || skb_cloned(next_skb))
+               return;
 
-               /* Also punt if next skb has been SACK'd. */
-               if (TCP_SKB_CB(next_skb)->sacked & TCPCB_SACKED_ACKED)
-                       return;
+       skb_size = skb->len;
+       next_skb_size = next_skb->len;
+       flags = TCP_SKB_CB(skb)->flags;
 
-               /* Next skb is out of window. */
-               if (after(TCP_SKB_CB(next_skb)->end_seq, tp->snd_una+tp->snd_wnd))
-                       return;
+       /* Also punt if next skb has been SACK'd. */
+       if (TCP_SKB_CB(next_skb)->sacked & TCPCB_SACKED_ACKED)
+               return;
 
-               /* Punt if not enough space exists in the first SKB for
-                * the data in the second, or the total combined payload
-                * would exceed the MSS.
-                */
-               if ((next_skb_size > skb_tailroom(skb)) ||
-                   ((skb_size + next_skb_size) > mss_now))
-                       return;
+       /* Next skb is out of window. */
+       if (after(TCP_SKB_CB(next_skb)->end_seq, tcp_wnd_end(tp)))
+               return;
 
-               BUG_ON(tcp_skb_pcount(skb) != 1 ||
-                      tcp_skb_pcount(next_skb) != 1);
+       /* Punt if not enough space exists in the first SKB for
+        * the data in the second, or the total combined payload
+        * would exceed the MSS.
+        */
+       if ((next_skb_size > skb_tailroom(skb)) ||
+           ((skb_size + next_skb_size) > mss_now))
+               return;
 
-               if (WARN_ON(tcp_is_sack(tp) && tp->sacked_out &&
-                   (TCP_SKB_CB(next_skb)->seq == tp->highest_sack)))
-                       return;
+       BUG_ON(tcp_skb_pcount(skb) != 1 || tcp_skb_pcount(next_skb) != 1);
 
-               /* Ok.  We will be able to collapse the packet. */
-               tcp_unlink_write_queue(next_skb, sk);
+       tcp_highest_sack_combine(sk, next_skb, skb);
 
-               skb_copy_from_linear_data(next_skb,
-                                         skb_put(skb, next_skb_size),
-                                         next_skb_size);
+       /* Ok.  We will be able to collapse the packet. */
+       tcp_unlink_write_queue(next_skb, sk);
 
-               if (next_skb->ip_summed == CHECKSUM_PARTIAL)
-                       skb->ip_summed = CHECKSUM_PARTIAL;
+       skb_copy_from_linear_data(next_skb, skb_put(skb, next_skb_size),
+                                 next_skb_size);
 
-               if (skb->ip_summed != CHECKSUM_PARTIAL)
-                       skb->csum = csum_block_add(skb->csum, next_skb->csum, skb_size);
+       if (next_skb->ip_summed == CHECKSUM_PARTIAL)
+               skb->ip_summed = CHECKSUM_PARTIAL;
 
-               /* Update sequence range on original skb. */
-               TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(next_skb)->end_seq;
+       if (skb->ip_summed != CHECKSUM_PARTIAL)
+               skb->csum = csum_block_add(skb->csum, next_skb->csum, skb_size);
 
-               /* Merge over control information. */
-               flags |= TCP_SKB_CB(next_skb)->flags; /* This moves PSH/FIN etc. over */
-               TCP_SKB_CB(skb)->flags = flags;
+       /* Update sequence range on original skb. */
+       TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(next_skb)->end_seq;
 
-               /* All done, get rid of second SKB and account for it so
-                * packet counting does not break.
-                */
-               TCP_SKB_CB(skb)->sacked |= TCP_SKB_CB(next_skb)->sacked&(TCPCB_EVER_RETRANS|TCPCB_AT_TAIL);
-               if (TCP_SKB_CB(next_skb)->sacked&TCPCB_SACKED_RETRANS)
-                       tp->retrans_out -= tcp_skb_pcount(next_skb);
-               if (TCP_SKB_CB(next_skb)->sacked&TCPCB_LOST)
-                       tp->lost_out -= tcp_skb_pcount(next_skb);
-               /* Reno case is special. Sigh... */
-               if (tcp_is_reno(tp) && tp->sacked_out)
-                       tcp_dec_pcount_approx(&tp->sacked_out, next_skb);
-
-               tcp_adjust_fackets_out(tp, next_skb, tcp_skb_pcount(next_skb));
-               tp->packets_out -= tcp_skb_pcount(next_skb);
-
-               /* changed transmit queue under us so clear hints */
-               tcp_clear_retrans_hints_partial(tp);
-               /* manually tune sacktag skb hint */
-               if (tp->fastpath_skb_hint == next_skb) {
-                       tp->fastpath_skb_hint = skb;
-                       tp->fastpath_cnt_hint -= tcp_skb_pcount(skb);
-               }
+       /* Merge over control information. */
+       flags |= TCP_SKB_CB(next_skb)->flags; /* This moves PSH/FIN etc. over */
+       TCP_SKB_CB(skb)->flags = flags;
 
-               sk_stream_free_skb(sk, next_skb);
-       }
+       /* All done, get rid of second SKB and account for it so
+        * packet counting does not break.
+        */
+       TCP_SKB_CB(skb)->sacked |= TCP_SKB_CB(next_skb)->sacked & TCPCB_EVER_RETRANS;
+       if (TCP_SKB_CB(next_skb)->sacked & TCPCB_SACKED_RETRANS)
+               tp->retrans_out -= tcp_skb_pcount(next_skb);
+       if (TCP_SKB_CB(next_skb)->sacked & TCPCB_LOST)
+               tp->lost_out -= tcp_skb_pcount(next_skb);
+       /* Reno case is special. Sigh... */
+       if (tcp_is_reno(tp) && tp->sacked_out)
+               tcp_dec_pcount_approx(&tp->sacked_out, next_skb);
+
+       tcp_adjust_fackets_out(sk, next_skb, tcp_skb_pcount(next_skb));
+       tp->packets_out -= tcp_skb_pcount(next_skb);
+
+       /* changed transmit queue under us so clear hints */
+       tcp_clear_retrans_hints_partial(tp);
+
+       sk_wmem_free_skb(sk, next_skb);
 }
 
 /* Do a simple retransmit without using the backoff mechanisms in
@@ -1849,7 +1832,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
         * case, when window is shrunk to zero. In this case
         * our retransmit serves as a zero window probe.
         */
-       if (!before(TCP_SKB_CB(skb)->seq, tp->snd_una+tp->snd_wnd)
+       if (!before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp))
            && TCP_SKB_CB(skb)->seq != tp->snd_una)
                return -EAGAIN;
 
@@ -2029,7 +2012,7 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
                        break;
                tp->forward_skb_hint = skb;
 
-               if (after(TCP_SKB_CB(skb)->seq, tp->highest_sack))
+               if (!before(TCP_SKB_CB(skb)->seq, tcp_highest_sack_seq(tp)))
                        break;
 
                if (tcp_packets_in_flight(tp) >= tp->snd_cwnd)
@@ -2154,8 +2137,9 @@ int tcp_send_synack(struct sock *sk)
                        tcp_unlink_write_queue(skb, sk);
                        skb_header_release(nskb);
                        __tcp_add_write_queue_head(sk, nskb);
-                       sk_stream_free_skb(sk, skb);
-                       sk_charge_skb(sk, nskb);
+                       sk_wmem_free_skb(sk, skb);
+                       sk->sk_wmem_queued += nskb->truesize;
+                       sk_mem_charge(sk, nskb->truesize);
                        skb = nskb;
                }
 
@@ -2358,7 +2342,8 @@ int tcp_connect(struct sock *sk)
        tp->retrans_stamp = TCP_SKB_CB(buff)->when;
        skb_header_release(buff);
        __tcp_add_write_queue_tail(sk, buff);
-       sk_charge_skb(sk, buff);
+       sk->sk_wmem_queued += buff->truesize;
+       sk_mem_charge(sk, buff->truesize);
        tp->packets_out += tcp_skb_pcount(buff);
        tcp_transmit_skb(sk, buff, 1, GFP_KERNEL);
 
@@ -2433,37 +2418,38 @@ void tcp_send_delayed_ack(struct sock *sk)
 /* This routine sends an ack and also updates the window. */
 void tcp_send_ack(struct sock *sk)
 {
-       /* If we have been reset, we may not send again. */
-       if (sk->sk_state != TCP_CLOSE) {
-               struct sk_buff *buff;
+       struct sk_buff *buff;
 
-               /* We are not putting this on the write queue, so
-                * tcp_transmit_skb() will set the ownership to this
-                * sock.
-                */
-               buff = alloc_skb(MAX_TCP_HEADER, GFP_ATOMIC);
-               if (buff == NULL) {
-                       inet_csk_schedule_ack(sk);
-                       inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN;
-                       inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
-                                                 TCP_DELACK_MAX, TCP_RTO_MAX);
-                       return;
-               }
+       /* If we have been reset, we may not send again. */
+       if (sk->sk_state == TCP_CLOSE)
+               return;
 
-               /* Reserve space for headers and prepare control bits. */
-               skb_reserve(buff, MAX_TCP_HEADER);
-               buff->csum = 0;
-               TCP_SKB_CB(buff)->flags = TCPCB_FLAG_ACK;
-               TCP_SKB_CB(buff)->sacked = 0;
-               skb_shinfo(buff)->gso_segs = 1;
-               skb_shinfo(buff)->gso_size = 0;
-               skb_shinfo(buff)->gso_type = 0;
-
-               /* Send it off, this clears delayed acks for us. */
-               TCP_SKB_CB(buff)->seq = TCP_SKB_CB(buff)->end_seq = tcp_acceptable_seq(sk);
-               TCP_SKB_CB(buff)->when = tcp_time_stamp;
-               tcp_transmit_skb(sk, buff, 0, GFP_ATOMIC);
+       /* We are not putting this on the write queue, so
+        * tcp_transmit_skb() will set the ownership to this
+        * sock.
+        */
+       buff = alloc_skb(MAX_TCP_HEADER, GFP_ATOMIC);
+       if (buff == NULL) {
+               inet_csk_schedule_ack(sk);
+               inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN;
+               inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
+                                         TCP_DELACK_MAX, TCP_RTO_MAX);
+               return;
        }
+
+       /* Reserve space for headers and prepare control bits. */
+       skb_reserve(buff, MAX_TCP_HEADER);
+       buff->csum = 0;
+       TCP_SKB_CB(buff)->flags = TCPCB_FLAG_ACK;
+       TCP_SKB_CB(buff)->sacked = 0;
+       skb_shinfo(buff)->gso_segs = 1;
+       skb_shinfo(buff)->gso_size = 0;
+       skb_shinfo(buff)->gso_type = 0;
+
+       /* Send it off, this clears delayed acks for us. */
+       TCP_SKB_CB(buff)->seq = TCP_SKB_CB(buff)->end_seq = tcp_acceptable_seq(sk);
+       TCP_SKB_CB(buff)->when = tcp_time_stamp;
+       tcp_transmit_skb(sk, buff, 0, GFP_ATOMIC);
 }
 
 /* This routine sends a packet with an out of date sequence
@@ -2491,7 +2477,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent)
        skb_reserve(skb, MAX_TCP_HEADER);
        skb->csum = 0;
        TCP_SKB_CB(skb)->flags = TCPCB_FLAG_ACK;
-       TCP_SKB_CB(skb)->sacked = urgent;
+       TCP_SKB_CB(skb)->sacked = 0;
        skb_shinfo(skb)->gso_segs = 1;
        skb_shinfo(skb)->gso_size = 0;
        skb_shinfo(skb)->gso_type = 0;
@@ -2508,47 +2494,46 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent)
 
 int tcp_write_wakeup(struct sock *sk)
 {
-       if (sk->sk_state != TCP_CLOSE) {
-               struct tcp_sock *tp = tcp_sk(sk);
-               struct sk_buff *skb;
-
-               if ((skb = tcp_send_head(sk)) != NULL &&
-                   before(TCP_SKB_CB(skb)->seq, tp->snd_una+tp->snd_wnd)) {
-                       int err;
-                       unsigned int mss = tcp_current_mss(sk, 0);
-                       unsigned int seg_size = tp->snd_una+tp->snd_wnd-TCP_SKB_CB(skb)->seq;
-
-                       if (before(tp->pushed_seq, TCP_SKB_CB(skb)->end_seq))
-                               tp->pushed_seq = TCP_SKB_CB(skb)->end_seq;
-
-                       /* We are probing the opening of a window
-                        * but the window size is != 0
-                        * must have been a result SWS avoidance ( sender )
-                        */
-                       if (seg_size < TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq ||
-                           skb->len > mss) {
-                               seg_size = min(seg_size, mss);
-                               TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH;
-                               if (tcp_fragment(sk, skb, seg_size, mss))
-                                       return -1;
-                       } else if (!tcp_skb_pcount(skb))
-                               tcp_set_skb_tso_segs(sk, skb, mss);
+       struct tcp_sock *tp = tcp_sk(sk);
+       struct sk_buff *skb;
+
+       if (sk->sk_state == TCP_CLOSE)
+               return -1;
 
+       if ((skb = tcp_send_head(sk)) != NULL &&
+           before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp))) {
+               int err;
+               unsigned int mss = tcp_current_mss(sk, 0);
+               unsigned int seg_size = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq;
+
+               if (before(tp->pushed_seq, TCP_SKB_CB(skb)->end_seq))
+                       tp->pushed_seq = TCP_SKB_CB(skb)->end_seq;
+
+               /* We are probing the opening of a window
+                * but the window size is != 0
+                * must have been a result SWS avoidance ( sender )
+                */
+               if (seg_size < TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq ||
+                   skb->len > mss) {
+                       seg_size = min(seg_size, mss);
                        TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH;
-                       TCP_SKB_CB(skb)->when = tcp_time_stamp;
-                       err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
-                       if (!err) {
-                               update_send_head(sk, skb);
-                       }
-                       return err;
-               } else {
-                       if (tp->urg_mode &&
-                           between(tp->snd_up, tp->snd_una+1, tp->snd_una+0xFFFF))
-                               tcp_xmit_probe_skb(sk, TCPCB_URG);
-                       return tcp_xmit_probe_skb(sk, 0);
-               }
+                       if (tcp_fragment(sk, skb, seg_size, mss))
+                               return -1;
+               } else if (!tcp_skb_pcount(skb))
+                       tcp_set_skb_tso_segs(sk, skb, mss);
+
+               TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH;
+               TCP_SKB_CB(skb)->when = tcp_time_stamp;
+               err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
+               if (!err)
+                       tcp_event_new_data_sent(sk, skb);
+               return err;
+       } else {
+               if (tp->urg_mode &&
+                   between(tp->snd_up, tp->snd_una + 1, tp->snd_una + 0xFFFF))
+                       tcp_xmit_probe_skb(sk, 1);
+               return tcp_xmit_probe_skb(sk, 0);
        }
-       return -1;
 }
 
 /* A window probe timeout has occurred.  If window is not closed send