aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp.c
diff options
context:
space:
mode:
authorMartin KaFai Lau <kafai@fb.com>2016-04-25 17:44:48 -0400
committerDavid S. Miller <davem@davemloft.net>2016-04-28 16:14:18 -0400
commitc134ecb87817ce70fd62b2dc48bb079c44fc08df (patch)
tree53328726428d98baa71257d393764ce7013be11b /net/ipv4/tcp.c
parent2a9e8438a29c00432ae14eaceb088b965f8ac290 (diff)
tcp: Make use of MSG_EOR in tcp_sendmsg
This patch adds an eor bit to the TCP_SKB_CB. When MSG_EOR is passed to tcp_sendmsg, the eor bit will be set at the skb containing the last byte of the userland's msg. The eor bit will prevent data from appending to that skb in the future. The change in do_tcp_sendpages is to honor the eor set during the previous tcp_sendmsg(MSG_EOR) call. This patch handles the tcp_sendmsg case. The followup patches will handle other skb coalescing and fragment cases. One potential use case is to use MSG_EOR with SOF_TIMESTAMPING_TX_ACK to get a more accurate TCP ack timestamping on application protocol with multiple outgoing response messages (e.g. HTTP2). Packetdrill script for testing: ~~~~~~ +0 `sysctl -q -w net.ipv4.tcp_min_tso_segs=10` +0 `sysctl -q -w net.ipv4.tcp_no_metrics_save=1` +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 +0 bind(3, ..., ...) = 0 +0 listen(3, 1) = 0 0.100 < S 0:0(0) win 32792 <mss 1460,sackOK,nop,nop,nop,wscale 7> 0.100 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 7> 0.200 < . 1:1(0) ack 1 win 257 0.200 accept(3, ..., ...) = 4 +0 setsockopt(4, SOL_TCP, TCP_NODELAY, [1], 4) = 0 0.200 write(4, ..., 14600) = 14600 0.200 sendto(4, ..., 730, MSG_EOR, ..., ...) = 730 0.200 sendto(4, ..., 730, MSG_EOR, ..., ...) = 730 0.200 > . 1:7301(7300) ack 1 0.200 > P. 7301:14601(7300) ack 1 0.300 < . 1:1(0) ack 14601 win 257 0.300 > P. 14601:15331(730) ack 1 0.300 > P. 15331:16061(730) ack 1 0.400 < . 1:1(0) ack 16061 win 257 0.400 close(4) = 0 0.400 > F. 16061:16061(0) ack 1 0.400 < F. 1:1(0) ack 16062 win 257 0.400 > . 16062:16062(0) ack 2 Signed-off-by: Martin KaFai Lau <kafai@fb.com> Cc: Eric Dumazet <edumazet@google.com> Cc: Neal Cardwell <ncardwell@google.com> Cc: Soheil Hassas Yeganeh <soheil@google.com> Cc: Willem de Bruijn <willemb@google.com> Cc: Yuchung Cheng <ycheng@google.com> Suggested-by: Eric Dumazet <edumazet@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r--net/ipv4/tcp.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 91993782a947..cb4d1cabb42c 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -909,7 +909,8 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
909 int copy, i; 909 int copy, i;
910 bool can_coalesce; 910 bool can_coalesce;
911 911
912 if (!tcp_send_head(sk) || (copy = size_goal - skb->len) <= 0) { 912 if (!tcp_send_head(sk) || (copy = size_goal - skb->len) <= 0 ||
913 !tcp_skb_can_collapse_to(skb)) {
913new_segment: 914new_segment:
914 if (!sk_stream_memory_free(sk)) 915 if (!sk_stream_memory_free(sk))
915 goto wait_for_sndbuf; 916 goto wait_for_sndbuf;
@@ -1157,7 +1158,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
1157 copy = max - skb->len; 1158 copy = max - skb->len;
1158 } 1159 }
1159 1160
1160 if (copy <= 0) { 1161 if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) {
1161new_segment: 1162new_segment:
1162 /* Allocate new segment. If the interface is SG, 1163 /* Allocate new segment. If the interface is SG,
1163 * allocate skb fitting to single page. 1164 * allocate skb fitting to single page.
@@ -1251,6 +1252,8 @@ new_segment:
1251 copied += copy; 1252 copied += copy;
1252 if (!msg_data_left(msg)) { 1253 if (!msg_data_left(msg)) {
1253 tcp_tx_timestamp(sk, sockc.tsflags, skb); 1254 tcp_tx_timestamp(sk, sockc.tsflags, skb);
1255 if (unlikely(flags & MSG_EOR))
1256 TCP_SKB_CB(skb)->eor = 1;
1254 goto out; 1257 goto out;
1255 } 1258 }
1256 1259