tcp.c (c0371da6047abd261bc483c744dbc7d81a116172) | tcp.c (605ad7f184b60cfaacbc038aa6c55ee68dee3c89) |
---|---|
1/* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * Implementation of the Transmission Control Protocol(TCP). 7 * 8 * Authors: Ross Biro --- 821 unchanged lines hidden (view full) --- 830 } 831 return NULL; 832} 833 834static unsigned int tcp_xmit_size_goal(struct sock *sk, u32 mss_now, 835 int large_allowed) 836{ 837 struct tcp_sock *tp = tcp_sk(sk); | 1/* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * Implementation of the Transmission Control Protocol(TCP). 7 * 8 * Authors: Ross Biro --- 821 unchanged lines hidden (view full) --- 830 } 831 return NULL; 832} 833 834static unsigned int tcp_xmit_size_goal(struct sock *sk, u32 mss_now, 835 int large_allowed) 836{ 837 struct tcp_sock *tp = tcp_sk(sk); |
838 u32 xmit_size_goal, old_size_goal; | 838 u32 new_size_goal, size_goal, hlen; |
839 | 839 |
840 xmit_size_goal = mss_now; | 840 if (!large_allowed || !sk_can_gso(sk)) 841 return mss_now; |
841 | 842 |
842 if (large_allowed && sk_can_gso(sk)) { 843 u32 gso_size, hlen; | 843 /* Maybe we should/could use sk->sk_prot->max_header here ? */ 844 hlen = inet_csk(sk)->icsk_af_ops->net_header_len + 845 inet_csk(sk)->icsk_ext_hdr_len + 846 tp->tcp_header_len; |
844 | 847 |
845 /* Maybe we should/could use sk->sk_prot->max_header here ? */ 846 hlen = inet_csk(sk)->icsk_af_ops->net_header_len + 847 inet_csk(sk)->icsk_ext_hdr_len + 848 tp->tcp_header_len; | 848 new_size_goal = sk->sk_gso_max_size - 1 - hlen; 849 new_size_goal = tcp_bound_to_half_wnd(tp, new_size_goal); |
849 | 850 |
850 /* Goal is to send at least one packet per ms, 851 * not one big TSO packet every 100 ms. 852 * This preserves ACK clocking and is consistent 853 * with tcp_tso_should_defer() heuristic. 854 */ 855 gso_size = sk->sk_pacing_rate / (2 * MSEC_PER_SEC); 856 gso_size = max_t(u32, gso_size, 857 sysctl_tcp_min_tso_segs * mss_now); 858 859 xmit_size_goal = min_t(u32, gso_size, 860 sk->sk_gso_max_size - 1 - hlen); 861 862 xmit_size_goal = tcp_bound_to_half_wnd(tp, xmit_size_goal); 863 864 /* We try hard to avoid divides here */ 865 old_size_goal = tp->xmit_size_goal_segs * mss_now; 866 867 if (likely(old_size_goal <= xmit_size_goal && 868 old_size_goal + mss_now > xmit_size_goal)) { 869 xmit_size_goal = old_size_goal; 870 } else { 871 tp->xmit_size_goal_segs = 872 min_t(u16, xmit_size_goal / mss_now, 873 sk->sk_gso_max_segs); 874 xmit_size_goal = tp->xmit_size_goal_segs * mss_now; 875 } | 851 /* We try hard to avoid divides here */ 852 size_goal = tp->gso_segs * mss_now; 853 if (unlikely(new_size_goal < size_goal || 854 new_size_goal >= size_goal + mss_now)) { 855 tp->gso_segs = min_t(u16, new_size_goal / mss_now, 856 sk->sk_gso_max_segs); 857 size_goal = tp->gso_segs * mss_now; |
876 } 877 | 858 } 859 |
878 return max(xmit_size_goal, mss_now); | 860 return max(size_goal, mss_now); |
879} 880 881static int tcp_send_mss(struct sock *sk, int *size_goal, int flags) 882{ 883 int mss_now; 884 885 mss_now = tcp_current_mss(sk); 886 *size_goal = tcp_xmit_size_goal(sk, mss_now, !(flags & MSG_OOB)); --- 193 unchanged lines hidden (view full) --- 1080 *copied = tp->fastopen_req->copied; 1081 tcp_free_fastopen_req(tp); 1082 return err; 1083} 1084 1085int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 1086 size_t size) 1087{ | 861} 862 863static int tcp_send_mss(struct sock *sk, int *size_goal, int flags) 864{ 865 int mss_now; 866 867 mss_now = tcp_current_mss(sk); 868 *size_goal = tcp_xmit_size_goal(sk, mss_now, !(flags & MSG_OOB)); --- 193 unchanged lines hidden (view full) --- 1062 *copied = tp->fastopen_req->copied; 1063 tcp_free_fastopen_req(tp); 1064 return err; 1065} 1066 1067int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 1068 size_t size) 1069{ |
1088 const struct iovec *iov; | 1070 struct iovec *iov; |
1089 struct tcp_sock *tp = tcp_sk(sk); 1090 struct sk_buff *skb; 1091 int iovlen, flags, err, copied = 0; 1092 int mss_now = 0, size_goal, copied_syn = 0, offset = 0; 1093 bool sg; 1094 long timeo; 1095 1096 lock_sock(sk); --- 34 unchanged lines hidden (view full) --- 1131 } 1132 1133 /* This should be in poll */ 1134 clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); 1135 1136 mss_now = tcp_send_mss(sk, &size_goal, flags); 1137 1138 /* Ok commence sending. */ | 1071 struct tcp_sock *tp = tcp_sk(sk); 1072 struct sk_buff *skb; 1073 int iovlen, flags, err, copied = 0; 1074 int mss_now = 0, size_goal, copied_syn = 0, offset = 0; 1075 bool sg; 1076 long timeo; 1077 1078 lock_sock(sk); --- 34 unchanged lines hidden (view full) --- 1113 } 1114 1115 /* This should be in poll */ 1116 clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); 1117 1118 mss_now = tcp_send_mss(sk, &size_goal, flags); 1119 1120 /* Ok commence sending. */ |
1139 iovlen = msg->msg_iter.nr_segs; 1140 iov = msg->msg_iter.iov; | 1121 iovlen = msg->msg_iovlen; 1122 iov = msg->msg_iov; |
1141 copied = 0; 1142 1143 err = -EPIPE; 1144 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) 1145 goto out_err; 1146 1147 sg = !!(sk->sk_route_caps & NETIF_F_SG); 1148 --- 575 unchanged lines hidden (view full) --- 1724 1725 tcp_cleanup_rbuf(sk, copied); 1726 1727 if (!sysctl_tcp_low_latency && tp->ucopy.task == user_recv) { 1728 /* Install new reader */ 1729 if (!user_recv && !(flags & (MSG_TRUNC | MSG_PEEK))) { 1730 user_recv = current; 1731 tp->ucopy.task = user_recv; | 1123 copied = 0; 1124 1125 err = -EPIPE; 1126 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) 1127 goto out_err; 1128 1129 sg = !!(sk->sk_route_caps & NETIF_F_SG); 1130 --- 575 unchanged lines hidden (view full) --- 1706 1707 tcp_cleanup_rbuf(sk, copied); 1708 1709 if (!sysctl_tcp_low_latency && tp->ucopy.task == user_recv) { 1710 /* Install new reader */ 1711 if (!user_recv && !(flags & (MSG_TRUNC | MSG_PEEK))) { 1712 user_recv = current; 1713 tp->ucopy.task = user_recv; |
1732 tp->ucopy.msg = msg; | 1714 tp->ucopy.iov = msg->msg_iov; |
1733 } 1734 1735 tp->ucopy.len = len; 1736 1737 WARN_ON(tp->copied_seq != tp->rcv_nxt && 1738 !(flags & (MSG_PEEK | MSG_TRUNC))); 1739 1740 /* Ugly... If prequeue is not empty, we have to --- 1384 unchanged lines hidden --- | 1715 } 1716 1717 tp->ucopy.len = len; 1718 1719 WARN_ON(tp->copied_seq != tp->rcv_nxt && 1720 !(flags & (MSG_PEEK | MSG_TRUNC))); 1721 1722 /* Ugly... If prequeue is not empty, we have to --- 1384 unchanged lines hidden --- |