[PATCH mptcp-next v2 06/12] mptcp: factor out a basic skb coalesce helper

Paolo Abeni posted 12 patches 3 weeks, 1 day ago
There is a newer version of this series
[PATCH mptcp-next v2 06/12] mptcp: factor out a basic skb coalesce helper
Posted by Paolo Abeni 3 weeks, 1 day ago
The upcoming patch will introduced backlog processing for MPTCP
socket, and we want to leverage coalescing in such data path.

Factor out the relevant bits not touching memory accounting to
deal with such use-case.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 net/mptcp/protocol.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 19b5b925e2acc..66ad9a38a6082 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -142,22 +142,34 @@ static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
 	__kfree_skb(skb);
 }
 
-static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
-			       struct sk_buff *from)
+static int __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
+				struct sk_buff *from, bool *fragstolen)
 {
-	bool fragstolen;
+	int limit = READ_ONCE(sk->sk_rcvbuf);
 	int delta;
 
 	if (unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
 	    MPTCP_SKB_CB(from)->offset ||
-	    ((to->len + from->len) > (sk->sk_rcvbuf >> 3)) ||
-	    !skb_try_coalesce(to, from, &fragstolen, &delta))
-		return false;
+	    ((to->len + from->len) > (limit >> 3)) ||
+	    !skb_try_coalesce(to, from, fragstolen, &delta))
+		return 0;
 
 	pr_debug("colesced seq %llx into %llx new len %d new end seq %llx\n",
 		 MPTCP_SKB_CB(from)->map_seq, MPTCP_SKB_CB(to)->map_seq,
 		 to->len, MPTCP_SKB_CB(from)->end_seq);
 	MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
+	return delta;
+}
+
+static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
+			       struct sk_buff *from)
+{
+	bool fragstolen;
+	int delta;
+
+	delta = __mptcp_try_coalesce(sk, to, from, &fragstolen);
+	if (!delta)
+		return false;
 
 	/* note the fwd memory can reach a negative value after accounting
 	 * for the delta, but the later skb free will restore a non
-- 
2.51.0
Re: [PATCH mptcp-next v2 06/12] mptcp: factor out a basic skb coalesce helper
Posted by Matthieu Baerts 3 weeks ago
Hi Paolo,

On 18/09/2025 19:14, Paolo Abeni wrote:
> The upcoming patch will introduced backlog processing for MPTCP
> socket, and we want to leverage coalescing in such data path.
> 
> Factor out the relevant bits not touching memory accounting to
> deal with such use-case.
> 
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
>  net/mptcp/protocol.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 19b5b925e2acc..66ad9a38a6082 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -142,22 +142,34 @@ static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
>  	__kfree_skb(skb);
>  }
>  
> -static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
> -			       struct sk_buff *from)
> +static int __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
> +				struct sk_buff *from, bool *fragstolen)
>  {
> -	bool fragstolen;
> +	int limit = READ_ONCE(sk->sk_rcvbuf);
>  	int delta;
>  
>  	if (unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
>  	    MPTCP_SKB_CB(from)->offset ||
> -	    ((to->len + from->len) > (sk->sk_rcvbuf >> 3)) ||
> -	    !skb_try_coalesce(to, from, &fragstolen, &delta))
> -		return false;
> +	    ((to->len + from->len) > (limit >> 3)) ||
> +	    !skb_try_coalesce(to, from, fragstolen, &delta))
> +		return 0;
>  
>  	pr_debug("colesced seq %llx into %llx new len %d new end seq %llx\n",
>  		 MPTCP_SKB_CB(from)->map_seq, MPTCP_SKB_CB(to)->map_seq,
>  		 to->len, MPTCP_SKB_CB(from)->end_seq);
>  	MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
> +	return delta;
> +}
> +
> +static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
> +			       struct sk_buff *from)
> +{
> +	bool fragstolen;
> +	int delta;
> +
> +	delta = __mptcp_try_coalesce(sk, to, from, &fragstolen);
> +	if (!delta)
> +		return false;

Small idea: should __mptcp_try_coalesce() returns a bool, and take a
pointer to delta? Similar to what skb_try_coalesce() is doing then.
Here, you will then have:

  if (!__mptcp_try_coalesce(sk, to, from, &fragstolen, &delta))
      return false;

But that's a detail, if you prefer your version, I'm fine with it:

Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.