Skip to contentSkip to conversation

mptcp: rx path refactor

PATCH In review Paolo Abeni 4 participants 18 messages Dec 6, 2024 – Dec 30, 2024

Subsystems (4)
lore
Share & tools
lore

Paolo Abeni

author maintainer
#0 lore raw

v2 cover mptcp: rx path refactor

This is a batch of changes I had sitting in my local tree for a while. Why another refactor you may ask? Two main resons:

- currently the mptcp RX path introduces quite a bit of 'exceptional' accounting/locking processing WRT to plain TCP, adding up to the implementation complexity in a misurable way
- the performance gap WRT plain TCP for single subflow connections is quite measurable.

The present refactor addresses both the above items: most of the additional complexity is dropped, and single stream performances increase measurably - from 55Gbps to 71Gbps in my loopback test. As a reference, plain TCP is around 84Gps on the same host.

The above comes to a price: the patch are invasive, even in subtle ways:
the chance of destabilizing the implementation is real (ence the additional, intentional '-next' into the subj).

In any case keeping the patch hidden for longer was not going to do any good, so here we are.

Changes from v1:
- fixed several data stream corruption and wake-up misses due to multi subflows races
- added patches 1-3 mainly to address the above
- added an additional follow-up patch (patch 7) with more cleanup

Paolo Abeni (7):
mptcp: prevent excessive coalescing on receive
tcp: fix recvbuffer adjust on sleeping rcvmsg
mptcp: don't always assume copied data in mptcp_cleanup_rbuf()
mptcp: consolidate subflow cleanup
mptcp: move the whole rx path under msk socket lock protection
mptcp: cleanup mem accounting.
net: dismiss sk_forward_alloc_get()

 include/net/sock.h   |  13 ---
 net/core/sock.c      |   2 +-
 net/ipv4/af_inet.c   |   2 +-
 net/ipv4/inet_diag.c |   2 +-
 net/mptcp/fastopen.c |   4 +-
 net/mptcp/protocol.c | 259 +++++++++++++------------------------------
 net/mptcp/protocol.h |   6 +-
 net/mptcp/subflow.c  |  33 +++---
 net/sched/em_meta.c  |   2 +-
 9 files changed, 104 insertions(+), 219 deletions(-)
Signature · 1 line
2.45.2
author maintainer
#1 lore raw

PATCH v2 1/7 mptcp: prevent excessive coalescing on receive

Currently the skb size after coalescing is only limited by the skb layout (the skb must not carry frag_list). A single coalesced skb covering several MSS can potentially fill completely the receive buffer. In such a case, the snd win will zero until the receive buffer will be empty again, affecting tput badly.

---
No fixes tag because the problem is not very visible in practice currently, but will be apparent after the rx refactor. Still I hope this could affect positively the simlut flows self-tests

---
 net/mptcp/protocol.c | 1 +
 1 file changed, 1 insertion(+)
net/mptcp/protocol.c +1 -0
index f768aa4473fb..fd9593f85a98 100644
@@ -136,6 +136,7 @@ static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
 	int delta;
 
 	if (MPTCP_SKB_CB(from)->offset ||
+	    ((to->len + from->len) > (sk->sk_rcvbuf >> 3)) ||
 	    !skb_try_coalesce(to, from, &fragstolen, &delta))
 		return false;
 
Signature · 1 line
2.45.2
author maintainer
#6 lore raw

PATCH v2 2/7 tcp: fix recvbuffer adjust on sleeping rcvmsg

In reply to Paolo Abeni

If the recvmsg() blocks after receiving some data - i.e. due to SO_RCVLOWAT - the MPTCP code will attempt multiple times to adjust the receive buffer size, wrongly accounting every time the cumulative of received data - instead of accounting only for the delta.

Address the issue moving mptcp_rcv_space_adjust just after the data reception and passing it only the just received bytes.

This also remove an unneeded difference between the TCP and MPTCP RX code path implementation.

Fixes 581302298524 ("mptcp: error out earlier on disconnect")

---
Not strictly related to the refactor, found while investigating the CI failure

---
 net/mptcp/protocol.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +3 -3
index fd9593f85a98..bca8c2c046c3 100644
@@ -1940,6 +1940,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	goto out;
 }
 
+static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied);
+
 static int __mptcp_recvmsg_mskq(struct mptcp_sock *msk,
 				struct msghdr *msg,
 				size_t len, int flags,
@@ -1993,6 +1995,7 @@ static int __mptcp_recvmsg_mskq(struct mptcp_sock *msk,
 			break;
 	}
 
+	mptcp_rcv_space_adjust(msk, copied);
 	return copied;
 }
 
@@ -2269,7 +2272,6 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		}
 
 		pr_debug("block timeout %ld\n", timeo);
-		mptcp_rcv_space_adjust(msk, copied);
 		err = sk_wait_data(sk, &timeo, NULL);
 		if (err < 0) {
 			err = copied ? : err;
@@ -2277,8 +2279,6 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		}
 	}
 
-	mptcp_rcv_space_adjust(msk, copied);
-
 out_err:
 	if (cmsg_flags && copied >= 0) {
 		if (cmsg_flags & MPTCP_CMSG_TS)
Signature · 1 line
2.45.2
author maintainer
#7 lore raw

PATCH v2 3/7 mptcp: don't always assume copied data in mptcp_cleanup_rbuf()

In reply to Paolo Abeni

Under some corner cases the MPTCP protocol can end-up invoking mptcp_cleanup_rbuf() when no data has been copied, but such helper assumes the opposite condition.

Explicitly drop such assumption and performs the costly call only when strictly needed - before releasing the msk socket lock.

Fixes fd8976790a6c ("mptcp: be careful on MPTCP-level ack.")
---
 net/mptcp/protocol.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
net/mptcp/protocol.c +9 -9
index bca8c2c046c3..690614816749 100644
@@ -529,13 +529,13 @@ static void mptcp_send_ack(struct mptcp_sock *msk)
 		mptcp_subflow_send_ack(mptcp_subflow_tcp_sock(subflow));
 }
 
-static void mptcp_subflow_cleanup_rbuf(struct sock *ssk)
+static void mptcp_subflow_cleanup_rbuf(struct sock *ssk, int copied)
 {
 	bool slow;
 
 	slow = lock_sock_fast(ssk);
 	if (tcp_can_send_ack(ssk))
-		tcp_cleanup_rbuf(ssk, 1);
+		tcp_cleanup_rbuf(ssk, copied);
 	unlock_sock_fast(ssk, slow);
 }
 
@@ -552,7 +552,7 @@ static bool mptcp_subflow_could_cleanup(const struct sock *ssk, bool rx_empty)
 			      (ICSK_ACK_PUSHED2 | ICSK_ACK_PUSHED)));
 }
 
-static void mptcp_cleanup_rbuf(struct mptcp_sock *msk)
+static void mptcp_cleanup_rbuf(struct mptcp_sock *msk, int copied)
 {
 	int old_space = READ_ONCE(msk->old_wspace);
 	struct mptcp_subflow_context *subflow;
@@ -560,14 +560,14 @@ static void mptcp_cleanup_rbuf(struct mptcp_sock *msk)
 	int space =  __mptcp_space(sk);
 	bool cleanup, rx_empty;
 
-	cleanup = (space > 0) && (space >= (old_space << 1));
-	rx_empty = !__mptcp_rmem(sk);
+	cleanup = (space > 0) && (space >= (old_space << 1)) && copied;
+	rx_empty = !__mptcp_rmem(sk) && copied;
 
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 
 		if (cleanup || mptcp_subflow_could_cleanup(ssk, rx_empty))
-			mptcp_subflow_cleanup_rbuf(ssk);
+			mptcp_subflow_cleanup_rbuf(ssk, copied);
 	}
 }
 
@@ -2221,9 +2221,6 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 
 		copied += bytes_read;
 
-		/* be sure to advertise window change */
-		mptcp_cleanup_rbuf(msk);
-
 		if (skb_queue_empty(&msk->receive_queue) && __mptcp_move_skbs(msk))
 			continue;
 
@@ -2272,6 +2269,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		}
 
 		pr_debug("block timeout %ld\n", timeo);
+		mptcp_cleanup_rbuf(msk, copied);
 		err = sk_wait_data(sk, &timeo, NULL);
 		if (err < 0) {
 			err = copied ? : err;
@@ -2279,6 +2277,8 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		}
 	}
 
+	mptcp_cleanup_rbuf(msk, copied);
+
 out_err:
 	if (cmsg_flags && copied >= 0) {
 		if (cmsg_flags & MPTCP_CMSG_TS)
Signature · 1 line
2.45.2
author maintainer
#8 lore raw

PATCH v2 4/7 mptcp: consolidate subflow cleanup

In reply to Paolo Abeni

Consolidate all the cleanup actions requiring the worker in a single helper and ensure the dummy data fin creation for fallback socket is performed only when the tcp rx queue is empty.

There are no functional changes intended, but this will simplify the next patch, when the tcp rx queue spooling could be delayed at release_cb time.

---
 net/mptcp/subflow.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)
net/mptcp/subflow.c +18 -15
index fd021cf8286e..2926bdf88e42 100644
@@ -1271,7 +1271,12 @@ static void mptcp_subflow_discard_data(struct sock *ssk, struct sk_buff *skb,
 		subflow->map_valid = 0;
 }
 
-/* sched mptcp worker to remove the subflow if no more data is pending */
+static bool subflow_is_done(const struct sock *sk)
+{
+	return sk->sk_shutdown & RCV_SHUTDOWN || sk->sk_state == TCP_CLOSE;
+}
+
+/* sched mptcp worker for subflow cleanup if no more data is pending */
 static void subflow_sched_work_if_closed(struct mptcp_sock *msk, struct sock *ssk)
 {
 	struct sock *sk = (struct sock *)msk;
@@ -1281,8 +1286,18 @@ static void subflow_sched_work_if_closed(struct mptcp_sock *msk, struct sock *ss
 		    inet_sk_state_load(sk) != TCP_ESTABLISHED)))
 		return;
 
-	if (skb_queue_empty(&ssk->sk_receive_queue) &&
-	    !test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
+	if (!skb_queue_empty(&ssk->sk_receive_queue))
+		return;
+
+	if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
+		mptcp_schedule_work(sk);
+
+	/* when the fallback subflow closes the rx side, trigger a 'dummy'
+	 * ingress data fin, so that the msk state will follow along
+	 */
+	if (__mptcp_check_fallback(msk) && subflow_is_done(ssk) &&
+	    msk->first == ssk &&
+	    mptcp_update_rcv_data_fin(msk, READ_ONCE(msk->ack_seq), true))
 		mptcp_schedule_work(sk);
 }
 
@@ -1842,11 +1857,6 @@ static void __subflow_state_change(struct sock *sk)
 	rcu_read_unlock();
 }
 
-static bool subflow_is_done(const struct sock *sk)
-{
-	return sk->sk_shutdown & RCV_SHUTDOWN || sk->sk_state == TCP_CLOSE;
-}
-
 static void subflow_state_change(struct sock *sk)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
@@ -1873,13 +1883,6 @@ static void subflow_state_change(struct sock *sk)
 		subflow_error_report(sk);
 
 	subflow_sched_work_if_closed(mptcp_sk(parent), sk);
-
-	/* when the fallback subflow closes the rx side, trigger a 'dummy'
-	 * ingress data fin, so that the msk state will follow along
-	 */
-	if (__mptcp_check_fallback(msk) && subflow_is_done(sk) && msk->first == sk &&
-	    mptcp_update_rcv_data_fin(msk, READ_ONCE(msk->ack_seq), true))
-		mptcp_schedule_work(parent);
 }
 
 void mptcp_subflow_queue_clean(struct sock *listener_sk, struct sock *listener_ssk)
Signature · 1 line
2.45.2
author maintainer
#9 lore raw

PATCH v2 5/7 mptcp: move the whole rx path under msk socket lock protection

In reply to Paolo Abeni

After commit c2e6048fa1cf ("mptcp: fix race in release_cb") we can move the whole MPTCP rx path under the socket lock leveraging the release_cb.

We can drop a bunch of spin_lock pairs in the receive functions, use a single receive queue and invoke __mptcp_move_skbs only when subflows ask for it.

This will allow more cleanup in the next patch.

Some changes are worth specific mention:

The msk rcvbuf update now always happens under both the msk and the subflow socket lock: we can drop a bunch of ONCE annotation and consolidate the checks.

When the skbs move is delayed at msk release callback time, even the msk rcvbuf update is delayed; additionally take care of such action in __mptcp_move_skbs().

---
v1 -> v2:
- cleanup && fixup msk sk_rcvbuf update
- fix missed wakeup due to bad placed __mptcp_move_skbs(); move it form __mptcp_recvmsg_mskq into mptcp_recvmsg()
- added missing '\n' in debug message format string
- keep 'snd_una' && friends update under the mptcp data lock

---
 net/mptcp/fastopen.c |   2 +
 net/mptcp/protocol.c | 123 ++++++++++++++++++++-----------------------
 net/mptcp/protocol.h |   2 +-
 3 files changed, 61 insertions(+), 66 deletions(-)
net/mptcp/fastopen.c +2 -0
index a29ff901df75..fb945c0d50bf 100644
@@ -49,6 +49,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
 	MPTCP_SKB_CB(skb)->has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
 
 	mptcp_data_lock(sk);
+	DEBUG_NET_WARN_ON_ONCE(sock_owned_by_user_nocheck(sk));
 
 	mptcp_set_owner_r(skb, sk);
 	__skb_queue_tail(&sk->sk_receive_queue, skb);
@@ -65,6 +66,7 @@ void __mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflo
 	struct sock *sk = (struct sock *)msk;
 	struct sk_buff *skb;
 
+	DEBUG_NET_WARN_ON_ONCE(sock_owned_by_user_nocheck(sk));
 	skb = skb_peek_tail(&sk->sk_receive_queue);
 	if (skb) {
 		WARN_ON_ONCE(MPTCP_SKB_CB(skb)->end_seq);
net/mptcp/protocol.c +58 -65

266 lines not on this page · raw message

net/mptcp/protocol.h +1 -1
index b4c72a73594f..ad940cc1f26f 100644
@@ -124,6 +124,7 @@
 #define MPTCP_FLUSH_JOIN_LIST	5
 #define MPTCP_SYNC_STATE	6
 #define MPTCP_SYNC_SNDBUF	7
+#define MPTCP_DEQUEUE		8
 
 struct mptcp_skb_cb {
 	u64 map_seq;
@@ -322,7 +323,6 @@ struct mptcp_sock {
 	struct work_struct work;
 	struct sk_buff  *ooo_last_skb;
 	struct rb_root  out_of_order_queue;
-	struct sk_buff_head receive_queue;
 	struct list_head conn_list;
 	struct list_head rtx_queue;
 	struct mptcp_data_frag *first_pending;
Signature · 1 line
2.45.2
author maintainer
#10 lore raw

PATCH v2 6/7 mptcp: cleanup mem accounting.

In reply to Paolo Abeni

After the previous patch, updating sk_forward_memory is cheap and we can drop a lot of complexity from the MPTCP memory acconting, removing the custom fwd mem allocations for rmem.

---
v1 -> v2:
- keep 'snd_una' and recovery-related fields under the msk data lock
- dropped unneeded code in __mptcp_move_skbs()

---
 net/mptcp/fastopen.c |   2 +-
 net/mptcp/protocol.c | 115 +++----------------------------------------
 net/mptcp/protocol.h |   4 +-
 3 files changed, 10 insertions(+), 111 deletions(-)
net/mptcp/fastopen.c +1 -1
index fb945c0d50bf..b0f1dddfb143 100644
@@ -51,7 +51,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
 	mptcp_data_lock(sk);
 	DEBUG_NET_WARN_ON_ONCE(sock_owned_by_user_nocheck(sk));
 
-	mptcp_set_owner_r(skb, sk);
+	skb_set_owner_r(skb, sk);
 	__skb_queue_tail(&sk->sk_receive_queue, skb);
 	mptcp_sk(sk)->bytes_received += skb->len;
 
net/mptcp/protocol.c +8 -107

212 lines not on this page · raw message

net/mptcp/protocol.h +1 -3
index ad940cc1f26f..a0d46b69746d 100644
@@ -278,7 +278,6 @@ struct mptcp_sock {
 	u64		rcv_data_fin_seq;
 	u64		bytes_retrans;
 	u64		bytes_consumed;
-	int		rmem_fwd_alloc;
 	int		snd_burst;
 	int		old_wspace;
 	u64		recovery_snd_nxt;	/* in recovery mode accept up to this seq;
@@ -293,7 +292,6 @@ struct mptcp_sock {
 	u32		last_ack_recv;
 	unsigned long	timer_ival;
 	u32		token;
-	int		rmem_released;
 	unsigned long	flags;
 	unsigned long	cb_flags;
 	bool		recovery;		/* closing subflow write queue reinjected */
@@ -384,7 +382,7 @@ static inline void msk_owned_by_me(const struct mptcp_sock *msk)
  */
 static inline int __mptcp_rmem(const struct sock *sk)
 {
-	return atomic_read(&sk->sk_rmem_alloc) - READ_ONCE(mptcp_sk(sk)->rmem_released);
+	return atomic_read(&sk->sk_rmem_alloc);
 }
 
 static inline int mptcp_win_from_space(const struct sock *sk, int space)
Signature · 1 line
2.45.2
author maintainer
#13 lore raw

PATCH v2 7/7 net: dismiss sk_forward_alloc_get()

In reply to Paolo Abeni

After the previous patch we can remove the forward_alloc_get proto callback, basically reverting commit 292e6077b040 ("net: introduce sk_forward_alloc_get()") and commit 66d58f046c9d ("net: use sk_forward_alloc_get() in sk_get_meminfo()").

---
 include/net/sock.h   | 13 -------------
 net/core/sock.c      |  2 +-
 net/ipv4/af_inet.c   |  2 +-
 net/ipv4/inet_diag.c |  2 +-
 net/sched/em_meta.c  |  2 +-
 5 files changed, 4 insertions(+), 17 deletions(-)
include/net/sock.h +0 -13
index 7464e9f9f47c..a5c28a4f0263 100644
@@ -1283,10 +1283,6 @@ struct proto {
 	unsigned int		inuse_idx;
 #endif
 
-#if IS_ENABLED(CONFIG_MPTCP)
-	int			(*forward_alloc_get)(const struct sock *sk);
-#endif
-
 	bool			(*stream_memory_free)(const struct sock *sk, int wake);
 	bool			(*sock_is_readable)(struct sock *sk);
 	/* Memory pressure */
@@ -1347,15 +1343,6 @@ int sock_load_diag_module(int family, int protocol);
 
 INDIRECT_CALLABLE_DECLARE(bool tcp_stream_memory_free(const struct sock *sk, int wake));
 
-static inline int sk_forward_alloc_get(const struct sock *sk)
-{
-#if IS_ENABLED(CONFIG_MPTCP)
-	if (sk->sk_prot->forward_alloc_get)
-		return sk->sk_prot->forward_alloc_get(sk);
-#endif
-	return READ_ONCE(sk->sk_forward_alloc);
-}
-
 static inline bool __sk_stream_memory_free(const struct sock *sk, int wake)
 {
 	if (READ_ONCE(sk->sk_wmem_queued) >= READ_ONCE(sk->sk_sndbuf))
net/core/sock.c +1 -1
index 74729d20cd00..06b732604bf2 100644
@@ -3858,7 +3858,7 @@ void sk_get_meminfo(const struct sock *sk, u32 *mem)
 	mem[SK_MEMINFO_RCVBUF] = READ_ONCE(sk->sk_rcvbuf);
 	mem[SK_MEMINFO_WMEM_ALLOC] = sk_wmem_alloc_get(sk);
 	mem[SK_MEMINFO_SNDBUF] = READ_ONCE(sk->sk_sndbuf);
-	mem[SK_MEMINFO_FWD_ALLOC] = sk_forward_alloc_get(sk);
+	mem[SK_MEMINFO_FWD_ALLOC] = READ_ONCE(sk->sk_forward_alloc);
 	mem[SK_MEMINFO_WMEM_QUEUED] = READ_ONCE(sk->sk_wmem_queued);
 	mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc);
 	mem[SK_MEMINFO_BACKLOG] = READ_ONCE(sk->sk_backlog.len);
net/ipv4/af_inet.c +1 -1
index 8095e82de808..a460ef3a2b0b 100644
@@ -153,7 +153,7 @@ void inet_sock_destruct(struct sock *sk)
 	WARN_ON_ONCE(atomic_read(&sk->sk_rmem_alloc));
 	WARN_ON_ONCE(refcount_read(&sk->sk_wmem_alloc));
 	WARN_ON_ONCE(sk->sk_wmem_queued);
-	WARN_ON_ONCE(sk_forward_alloc_get(sk));
+	WARN_ON_ONCE(sk->sk_forward_alloc);
 
 	kfree(rcu_dereference_protected(inet->inet_opt, 1));
 	dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
net/ipv4/inet_diag.c +1 -1
index 321acc8abf17..efe2a085cf68 100644
@@ -282,7 +282,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 		struct inet_diag_meminfo minfo = {
 			.idiag_rmem = sk_rmem_alloc_get(sk),
 			.idiag_wmem = READ_ONCE(sk->sk_wmem_queued),
-			.idiag_fmem = sk_forward_alloc_get(sk),
+			.idiag_fmem = READ_ONCE(sk->sk_forward_alloc),
 			.idiag_tmem = sk_wmem_alloc_get(sk),
 		};
 
net/sched/em_meta.c +1 -1
index 8996c73c9779..3f2e707a11d1 100644
@@ -460,7 +460,7 @@ META_COLLECTOR(int_sk_fwd_alloc)
 		*err = -1;
 		return;
 	}
-	dst->value = sk_forward_alloc_get(sk);
+	dst->value = READ_ONCE(sk->sk_forward_alloc);
 }
 
 META_COLLECTOR(int_sk_sndbuf)
Signature · 1 line
2.45.2
#14 lore raw
In reply to Paolo Abeni

Hi Paolo,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/12198751082

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/1c3b9857b5b4
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=915337

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

author maintainer
#15 lore raw
In reply to Paolo Abeni
Quoted 4 lines · Paolo Abeni

The present refactor addresses both the above items: most of the additional complexity is dropped, and single stream performances increase measurably - from 55Gbps to 71Gbps in my loopback test. As a reference, plain TCP is around 84Gps on the same host.

I forgot to update this section.

I did some additional test with multiple links, differences vs the existing codebase is within the noise range.

Disclaimer: tests over multiple veth pairs, with RPS to use multiple cores for the forwarding. This is a somewhat decent approximation of a real setup with multiple H/W links but I still have to try the latter.

I think the issue reported by the CI in the previous iteration should be addressed here - or at least this iteration addresses the closest problem I was able to reproduce locally.

I'm not aware of any standing issue, but I would bet a few coins this is not bug-free.

Paolo

maintainer
#11 lore raw

Re: [PATCH mptcp-next v2 6/7] mptcp: cleanup mem accounting.

In reply to Paolo Abeni
Quoted 37 lines · Paolo Abeni

After the previous patch, updating sk_forward_memory is cheap and we can drop a lot of complexity from the MPTCP memory acconting, removing the custom fwd mem allocations for rmem.

---
v1 -> v2:
- keep 'snd_una' and recovery-related fields under the msk data lock
- dropped unneeded code in __mptcp_move_skbs()
---

net/mptcp/fastopen.c |   2 +-
net/mptcp/protocol.c | 115 +++----------------------------------------
net/mptcp/protocol.h |   4 +-
3 files changed, 10 insertions(+), 111 deletions(-)
net/mptcp/protocol.h +0 -2
index ad940cc1f26f..a0d46b69746d 100644
@@ -278,7 +278,6 @@ struct mptcp_sock {
 	u64		rcv_data_fin_seq;
 	u64		bytes_retrans;
 	u64		bytes_consumed;
-	int		rmem_fwd_alloc;
 	int		snd_burst;
 	int		old_wspace;
 	u64		recovery_snd_nxt;	/* in recovery mode accept up to this seq;
@@ -293,7 +292,6 @@ struct mptcp_sock {
 	u32		last_ack_recv;
 	unsigned long	timer_ival;
 	u32		token;
-	int		rmem_released;
 	unsigned long	flags;
 	unsigned long	cb_flags;
 	bool		recovery;		/* closing subflow write queue reinjected */

net/mptcp/protocol.h static inline void msk_owned_by_me(const struct mptcp_sock *msk) · line 386

Quoted 6 lines
net/mptcp/protocol.h +1 -1
@@ -384,7 +382,7 @@ static inline void msk_owned_by_me(const struct mptcp_sock *msk)
 */
 static inline int __mptcp_rmem(const struct sock *sk)
 {
-	return atomic_read(&sk->sk_rmem_alloc) - READ_ONCE(mptcp_sk(sk)->rmem_released);
+	return atomic_read(&sk->sk_rmem_alloc);
 }

Hi Paolo -

Minor change: this helper is now exactly the same as sk_rmem_alloc_get(), so use that existing helper instead.

Thats actually the only suggestion I have for v2! Good to delete code and improve performance. I also think the release_cb approach on rx is a good idea because it could be further leveraged to help with redundant schedulers (our main problem there was trying to trigger sends on other subflows when we couldn't acquire the msk lock).

- Mat

Quoted 7 lines
net/mptcp/protocol.h +0 -0
 static inline int mptcp_win_from_space(const struct sock *sk, int space)
Signature · 1 line
2.45.2
author maintainer
#12 lore raw

Re: [PATCH mptcp-next v2 6/7] mptcp: cleanup mem accounting.

Hi,

Quoted 2 lines · Mat Martineau

Minor change: this helper is now exactly the same as sk_rmem_alloc_get(), so use that existing helper instead.

If there are no strong opinion against that, I think it would be preferrable to do the removal in a separate patch. In fact, I have 2 more follow-up patches doing the __mptcp_rmem() removal and some micro-optimization/cleanup for __mptcp_move_skb().

Cheers,

Paolo

maintainer
#2 lore raw

Re: [PATCH mptcp-next v2 1/7] mptcp: prevent excessive coalescing on receive

In reply to Paolo Abeni

Hi Paolo,

Quoted 5 lines · Paolo Abeni

Currently the skb size after coalescing is only limited by the skb layout (the skb must not carry frag_list). A single coalesced skb covering several MSS can potentially fill completely the receive buffer. In such a case, the snd win will zero until the receive buffer will be empty again, affecting tput badly.

Good idea! Thank you for having looked at this!

Quoted 5 lines

---
No fixes tag because the problem is not very visible in practice currently, but will be apparent after the rx refactor. Still I hope this could affect positively the simlut flows self-tests

The modification looks safe enough to me: it should not make thing worst.

If it helps, a Fixes tag can be added and next to the 'Cc: stable' tag, we can ask to backport this patch after a few weeks, no? e.g.

Cc <[email protected]> # after -rc6

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer Reviewed-by on the v2 series
#16 lore raw
In reply to Paolo Abeni
Quoted 9 lines · Paolo Abeni

This is a batch of changes I had sitting in my local tree for a while. Why another refactor you may ask? Two main resons:

- currently the mptcp RX path introduces quite a bit of 'exceptional' accounting/locking processing WRT to plain TCP, adding up to the implementation complexity in a misurable way
- the performance gap WRT plain TCP for single subflow connections is quite measurable.

Quoted 5 lines

The present refactor addresses both the above items: most of the additional complexity is dropped, and single stream performances increase measurably - from 55Gbps to 71Gbps in my loopback test. As a reference, plain TCP is around 84Gps on the same host.

Hi Paolo -

Thanks for the v2 and for sharing the performance numbers - great to see such a dramatic improvement in throughput!

Quoted 4 lines

The above comes to a price: the patch are invasive, even in subtle ways:
the chance of destabilizing the implementation is real (ence the additional, intentional '-next' into the subj).

I think we will also need to be extra careful about monitoring stable tree backports that modify the affected functions. But to me the simplifications and performance fixes are worth it.

It will help to get this in to the export branch for further testing!

Quoted 34 lines

In any case keeping the patch hidden for longer was not going to do any good, so here we are.

Changes from v1:
- fixed several data stream corruption and wake-up misses due to multi subflows races
- added patches 1-3 mainly to address the above
- added an additional follow-up patch (patch 7) with more cleanup

Paolo Abeni (7):
mptcp: prevent excessive coalescing on receive
tcp: fix recvbuffer adjust on sleeping rcvmsg
mptcp: don't always assume copied data in mptcp_cleanup_rbuf()
mptcp: consolidate subflow cleanup
mptcp: move the whole rx path under msk socket lock protection
mptcp: cleanup mem accounting.
net: dismiss sk_forward_alloc_get()

include/net/sock.h   |  13 ---
net/core/sock.c      |   2 +-
net/ipv4/af_inet.c   |   2 +-
net/ipv4/inet_diag.c |   2 +-
net/mptcp/fastopen.c |   4 +-
net/mptcp/protocol.c | 259 +++++++++++++------------------------------
net/mptcp/protocol.h |   6 +-
net/mptcp/subflow.c  |  33 +++---
net/sched/em_meta.c  |   2 +-
9 files changed, 104 insertions(+), 219 deletions(-)
Signature · 1 line
2.45.2
maintainer
#3 lore raw

Re: [PATCH mptcp-next v2 1/7] mptcp: prevent excessive coalescing on receive

In reply to Matthieu Baerts

Hi Paolo,

Quoted 11 lines · Matthieu Baerts

Hi Paolo,

Quoted 5 lines · Paolo Abeni

Currently the skb size after coalescing is only limited by the skb layout (the skb must not carry frag_list). A single coalesced skb covering several MSS can potentially fill completely the receive buffer. In such a case, the snd win will zero until the receive buffer will be empty again, affecting tput badly.

Good idea! Thank you for having looked at this!

Quoted 7 lines
Quoted 5 lines

---
No fixes tag because the problem is not very visible in practice currently, but will be apparent after the rx refactor. Still I hope this could affect positively the simlut flows self-tests

The modification looks safe enough to me: it should not make thing worst.

Do you still prefer not targetting -net for this patch here? Or is it OK to do so and add a Fixes tag?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#17 lore raw
In reply to Paolo Abeni

Hi Paolo, Mat,

Quoted 14 lines · Paolo Abeni

This is a batch of changes I had sitting in my local tree for a while. Why another refactor you may ask? Two main resons:

- currently the mptcp RX path introduces quite a bit of 'exceptional' accounting/locking processing WRT to plain TCP, adding up to the implementation complexity in a misurable way
- the performance gap WRT plain TCP for single subflow connections is quite measurable.

The present refactor addresses both the above items: most of the additional complexity is dropped, and single stream performances increase measurably - from 55Gbps to 71Gbps in my loopback test. As a reference, plain TCP is around 84Gps on the same host.

Quoted 6 lines

The above comes to a price: the patch are invasive, even in subtle ways:
the chance of destabilizing the implementation is real (ence the additional, intentional '-next' into the subj).

In any case keeping the patch hidden for longer was not going to do any good, so here we are.

Thank you for the patches and the reviews!

Patches 2 and 3 are now in the "fixes for net", while the others are in "feat. for next". I think patch 1 can go to "Fixes for net", any objections?

New patches for t/upstream-net and t/upstream:
- d443f83de23d: mptcp: fix recvbuffer adjust on sleeping rcvmsg
- 11d4943d66ee: mptcp: don't always assume copied data in mptcp_cleanup_rbuf()
- Results: 3a0f411ba1c5..2116e71814b7 (export-net)
- Results: df3193ae83eb..953b0d388720 (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/047c2f99575350d9971b6257f96ce5f734f0186a/checks

New patches for t/upstream:
- 972d8a5b7f20: mptcp: prevent excessive coalescing on receive
- 0b0a25a24d21: mptcp: consolidate subflow cleanup
- 533bb69f1b0d: mptcp: move the whole rx path under msk socket lock protection
- c5d13b230497: mptcp: cleanup mem accounting
- a564b9923a94: net: dismiss sk_forward_alloc_get()
- Results: 953b0d388720..9213903d77ba (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/6aae9c8bd8361dd90a7def87459ca0173915c56c/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#4 lore raw

Re: [PATCH mptcp-next v2 1/7] mptcp: prevent excessive coalescing on receive

In reply to Matthieu Baerts
Quoted 16 lines · Matthieu Baerts
Quoted 15 lines · Matthieu Baerts
Quoted 5 lines · Paolo Abeni

Currently the skb size after coalescing is only limited by the skb layout (the skb must not carry frag_list). A single coalesced skb covering several MSS can potentially fill completely the receive buffer. In such a case, the snd win will zero until the receive buffer will be empty again, affecting tput badly.

Good idea! Thank you for having looked at this!

Quoted 5 lines

---
No fixes tag because the problem is not very visible in practice currently, but will be apparent after the rx refactor. Still I hope this could affect positively the simlut flows self-tests

Quoted 4 lines
Quoted 1 line

The modification looks safe enough to me: it should not make thing worst.

Do you still prefer not targetting -net for this patch here? Or is it OK to do so and add a Fixes tag?

Whatever is easier to do in practice works for me. Perhaps monitoring the simult_flows ST flakes could give an idea - if that get more stable/less unstable we should possibly target 'net'.

Cheers,

Paolo

maintainer
#5 lore raw

Re: [PATCH mptcp-next v2 1/7] mptcp: prevent excessive coalescing on receive

Quoted 17 lines · Paolo Abeni
Quoted 16 lines · Matthieu Baerts
Quoted 15 lines · Matthieu Baerts
Quoted 5 lines · Paolo Abeni

Currently the skb size after coalescing is only limited by the skb layout (the skb must not carry frag_list). A single coalesced skb covering several MSS can potentially fill completely the receive buffer. In such a case, the snd win will zero until the receive buffer will be empty again, affecting tput badly.

Good idea! Thank you for having looked at this!

Quoted 5 lines

---
No fixes tag because the problem is not very visible in practice currently, but will be apparent after the rx refactor. Still I hope this could affect positively the simlut flows self-tests

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

The modification looks safe enough to me: it should not make thing worst.

Do you still prefer not targetting -net for this patch here? Or is it OK to do so and add a Fixes tag?

Whatever is easier to do in practice works for me. Perhaps monitoring the simult_flows ST flakes could give an idea - if that get more stable/less unstable we should possibly target 'net'.

Thank you for your reply!

It looks OK so far. I just sent this patch to netdev, so we can also get some tests over there. I will monitor if it helps on NIPA as well.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.