Skip to contentSkip to conversation

mptcp: attempt skb coalescing when moving skbs to mptcp rx queue

PATCH In review Florian Westphal 2 participants 3 messages May 25, 2020

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author
#0 lore raw

PATCH 1/1 mptcp: attempt skb coalescing when moving skbs to mptcp rx queue

We can try to coalesce the skbs we take from the subflows rx queue with the tail of the mptcp rx queue.

If successful, the skb head can be discarded early.

We can also free the skb extensions, we do not access them after this so no need to hold on to them.

Only caveat: do not built too fat skbs. They are only free'd once userspace has read all data.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +24 -2
index d868b3d921fd..ab4a712b2529 100644
@@ -144,12 +144,34 @@ static void __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
 			     unsigned int offset, size_t copy_len)
 {
 	struct sock *sk = (struct sock *)msk;
+	struct sk_buff *tail;
 
 	__skb_unlink(skb, &ssk->sk_receive_queue);
-	skb_set_owner_r(skb, sk);
-	__skb_queue_tail(&sk->sk_receive_queue, skb);
 
+	skb_ext_reset(skb);
+	skb_orphan(skb);
 	msk->ack_seq += copy_len;
+
+	tail = skb_peek_tail(&sk->sk_receive_queue);
+	if (offset == 0 && tail) {
+		bool fragstolen;
+		int delta;
+
+		/* don't coalesce when tail is already fat.
+		 * skbs are only free'd once all of the data was
+		 * copied to userspace.
+		 */
+		if (tail->len < GSO_MAX_SIZE &&
+		    skb_try_coalesce(tail, skb, &fragstolen, &delta)) {
+			kfree_skb_partial(skb, fragstolen);
+			atomic_add(delta, &sk->sk_rmem_alloc);
+			sk_mem_charge(sk, delta);
+			return;
+		}
+	}
+
+	skb_set_owner_r(skb, sk);
+	__skb_queue_tail(&sk->sk_receive_queue, skb);
 	MPTCP_SKB_CB(skb)->offset = offset;
 }
 
Signature · 1 line
2.26.2
#1 lore raw
Quoted 10 lines · Florian Westphal

We can try to coalesce the skbs we take from the subflows rx queue with the tail of the mptcp rx queue.

If successful, the skb head can be discarded early.

We can also free the skb extensions, we do not access them after this so no need to hold on to them.

Only caveat: do not built too fat skbs. They are only free'd once userspace has read all data.

To share IRC thoughts here:

It looks like TCP allows skb to grow above GSO_MAX_SIZE and frees them only when user-space read all the data. Could we relax this constraint, too?

skb_try_coalesce() will still somehow bound the skb size to MAX_SKB_FRAGS * <something [PAGE_SIZE ?!?]>

Cheers,

Paolo

author
#2 lore raw
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · Florian Westphal

We can try to coalesce the skbs we take from the subflows rx queue with the tail of the mptcp rx queue.

If successful, the skb head can be discarded early.

We can also free the skb extensions, we do not access them after this so no need to hold on to them.

Quoted 8 lines
Quoted 2 lines

Only caveat: do not built too fat skbs. They are only free'd once userspace has read all data.

To share IRC thoughts here:

It looks like TCP allows skb to grow above GSO_MAX_SIZE and frees them only when user-space read all the data. Could we relax this constraint, too?

Yes, but I saw skbs of up ~320kb Truesize, which i considered too much. I will remove the comment and the contraint in v2.