Skip to contentSkip to conversation

tcp: Add MSG_NEW_PACKET flag to indicate preferable packet boundaries

RFC In review Andreas Gruenbacher 2 participants 5 messages Jun 29, 2012 – Jul 2, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC 1/3 tcp: Add MSG_NEW_PACKET flag to indicate preferable packet boundaries

The MSG_NEW_PACKET flag indicates to sendmsg / sendpage that the message or page should be put into a new packet even when there is still room left in the previous packet.

In the tcp protocol, messages which are not sent immediately are queued. When more data is sent, it will be added to the last segment in that queue until that segment is "full" whenever possible; only then is a new segment added. Right now, there is no way to indicate when tcp should start a new segment. The new flag allows to control that.

---
 include/linux/socket.h |    1 +
 net/ipv4/tcp.c         |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/socket.h +1 -0
index 25d6322..be166de 100644
@@ -266,6 +266,7 @@ struct ucred {
 #define MSG_MORE	0x8000	/* Sender will send more */
 #define MSG_WAITFORONE	0x10000	/* recvmmsg(): block until 1+ packets avail */
 #define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */
+#define MSG_NEW_PACKET	0x40000	/* tcp: try to put message into a new packet */
 #define MSG_EOF         MSG_FIN
 
 #define MSG_CMSG_CLOEXEC 0x40000000	/* Set close_on_exit for file
net/ipv4/tcp.c +3 -2
index 3ba605f..148aebe 100644
@@ -854,7 +854,8 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffse
 		int size = min_t(size_t, psize, PAGE_SIZE - offset);
 		bool can_coalesce;
 
-		if (!tcp_send_head(sk) || (copy = size_goal - skb->len) <= 0) {
+		if (!tcp_send_head(sk) || (copy = size_goal - skb->len) <= 0 ||
+		    (flags & MSG_NEW_PACKET)) {
 new_segment:
 			if (!sk_stream_memory_free(sk))
 				goto wait_for_sndbuf;
@@ -1044,7 +1045,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 				copy = max - skb->len;
 			}
 
-			if (copy <= 0) {
+			if (copy <= 0 || (flags & MSG_NEW_PACKET)) {
 new_segment:
 				/* Allocate new segment. If the interface is SG,
 				 * allocate skb fitting to single page.
Signature · 1 line
1.7.10.2
#1 lore raw
Quoted 4 lines · Andreas Gruenbacher

The MSG_NEW_PACKET flag indicates to sendmsg / sendpage that the message or page should be put into a new packet even when there is still room left in the previous packet.

Quoted 8 lines

In the tcp protocol, messages which are not sent immediately are queued. When more data is sent, it will be added to the last segment in that queue until that segment is "full" whenever possible; only then is a new segment added. Right now, there is no way to indicate when tcp should start a new segment. The new flag allows to control that.

---

I don't understand how maintaining any message boundaries at sender can prevent any middlebox or the receiver to coalesce frames to any boundaries it prefers ?

#2 lore raw
Quoted 11 lines · Eric Dumazet
Quoted 10 lines · Andreas Gruenbacher

The MSG_NEW_PACKET flag indicates to sendmsg / sendpage that the message or page should be put into a new packet even when there is still room left in the previous packet.

In the tcp protocol, messages which are not sent immediately are queued. When more data is sent, it will be added to the last segment in that queue until that segment is "full" whenever possible; only then is a new segment added. Right now, there is no way to indicate when tcp should start a new segment. The new flag allows to control that.

Quoted 6 lines
Quoted 2 lines

---

I don't understand how maintaining any message boundaries at sender can prevent any middlebox or the receiver to coalesce frames to any boundaries it prefers ?

The primary use case is fast Gigabit (10 or more) Ethernet connections with jumbo frames and switches that support them. There, frames will go through unchanged and you can zero-copy receive all the time.

Not sure how well the approach scales to other kinds of connections; it may work often enough to be worth it. When things get distorted between the sender and the receiver and tcp_recvbio() fails, the data can still be copied out of the socket as before.

Andreas

#3 lore raw
Quoted 8 lines · Andreas Gruenbacher

The primary use case is fast Gigabit (10 or more) Ethernet connections with jumbo frames and switches that support them. There, frames will go through unchanged and you can zero-copy receive all the time.

Not sure how well the approach scales to other kinds of connections; it may work often enough to be worth it. When things get distorted between the sender and the receiver and tcp_recvbio() fails, the data can still be copied out of the socket as before.

If you have a packet loss, receiver can and will coalesce frames.

#4 lore raw
Quoted 6 lines · Eric Dumazet
Quoted 4 lines · Andreas Gruenbacher

The primary use case is fast Gigabit (10 or more) Ethernet connections with jumbo frames and switches that support them. There, frames will go through unchanged and you can zero-copy receive all the time.

Quoted 6 lines
Quoted 4 lines

Not sure how well the approach scales to other kinds of connections; it may work often enough to be worth it. When things get distorted between the sender and the receiver and tcp_recvbio() fails, the data can still be copied out of the socket as before.

If you have a packet loss, receiver can and will coalesce frames.

That's alright as long as we'll get "back to normal" eventually; the only effect will be that we'll copy data out of the socket receive buffers for a while. There will be extremely little packet loss on the kinds of networks that we want to use this on.

Thanks,
Andreas