mptcp: receive path improvement
Subsystems (3)
Paolo Abeni
maintainerv3 cover mptcp: receive path improvement
This series includes several changes to the MPTCP RX path.
The main goals are improving the RX performances _and_ increase the long term maintainability.
Some changes reflects recent (or not so) improvements introduced in the TCP stack: patch 1, 2 and 3 are the MPTCP counter part of skb deferral free and auto-tuning improvements.
Note that patch 3 could possibly fix issues/574, and overall such patch should protect from similar issues to arise in the future.
All the others patches are aimed at introducing the socket backlog usage to process the packets received by the subflows while the msk socket is owned. That (almost completely) replace the processing currently happening in the mptcp_release_cb().
The actual job is done in patch 10, while the others are cleanups needed to make the change tidy and more follow-up cleanups.
Sharing earlier with known issues (at least on fallback socket) to raise awareness about this upcoming work.
---
v2 -> v3:
- (hopefully) addressed CI failures
- reordered to avoid trainsintly breaking fallback
- refactor patch 3/12
v1 -> v2:
- fix compile warn in patch 3
- removed unneeded arg in patch 4
- commit msg clarification and rebase
Paolo Abeni (12):
mptcp: leverage skb deferral free
tcp: make tcp_rcvbuf_grow() accessible to mptcp code
mptcp: rcvbuf auto-tuning improvement
mptcp: introduce the mptcp_init_skb helper.
mptcp: remove unneeded mptcp_move_skb()
mptcp: factor out a basic skb coalesce helper
mptcp: minor move_skbs_to_msk() cleanup
mptcp: cleanup fallback data fin reception
mptcp: cleanup fallback dummy mapping generation.
mptcp: leverage the sk backlog for RX packet processing.
mptcp: prevernt __mptcp_move_skbs() interfering with the fastpath
mptcp: borrow forward memory from subflow
include/net/tcp.h | 1 + net/ipv4/tcp_input.c | 2 +- net/mptcp/mib.c | 2 + net/mptcp/mib.h | 4 + net/mptcp/protocol.c | 343 ++++++++++++++++++++++++------------------- net/mptcp/protocol.h | 8 +- net/mptcp/subflow.c | 12 +- 7 files changed, 218 insertions(+), 154 deletions(-)
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 1/12 mptcp: leverage skb deferral free
Usage of the skb deferral API is straight-forward; with multiple subflows actives this allow moving part of the received application load into multiple CPUs.
Also fix a typo in the related comment.
--- net/mptcp/protocol.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +3 -2
@@ -1943,12 +1943,13 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, }if (!(flags &MSG_PEEK )) { -/* avoid the indirect call, we know the destructor is sock_wfree */ +/* avoid the indirect call, we know the destructor is sock_rfree */ skb->destructor =NULL ; + skb->sk =NULL ;atomic_sub (skb->truesize, &sk->sk_rmem_alloc);sk_mem_uncharge (sk, skb->truesize);__skb_unlink (skb, &sk->sk_receive_queue); -__kfree_skb (skb); +skb_attempt_defer_free (skb); msk->bytes_consumed += count; }
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 2/12 tcp: make tcp_rcvbuf_grow() accessible to mptcp code
In reply to Paolo AbeniTo leverage the auto-tuning improvements brought by commit 2da35e4b4df9 ("Merge branch 'tcp-receive-side-improvements'"), the MPTCP stack need to access the mentioned helper.
--- include/net/tcp.h | 1 + net/ipv4/tcp_input.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/net/tcp.h +1 -0
@@ -356,6 +356,7 @@ void tcp_delack_timer_handler(struct sock *sk);int tcp_ioctl (struct sock *sk,int cmd,int *karg);enum skb_drop_reason tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb);void tcp_rcv_established (struct sock *sk,struct sk_buff *skb); +void tcp_rcvbuf_grow (struct sock *sk);void tcp_rcv_space_adjust (struct sock *sk);int tcp_twsk_unique (struct sock *sk,struct sock *sktw,void *twp);void tcp_twsk_destructor (struct sock *sk);
net/ipv4/tcp_input.c +1 -1
@@ -701,7 +701,7 @@ static inline void tcp_rcv_rtt_measure_ts(struct sock *sk, } } -static void tcp_rcvbuf_grow (struct sock *sk) +void tcp_rcvbuf_grow (struct sock *sk) {const struct net *net =sock_net (sk);struct tcp_sock *tp =tcp_sk (sk);
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 3/12 mptcp: rcvbuf auto-tuning improvement
In reply to Paolo AbeniApply to the MPTCP auto-tuning the same improvements introduced for the TCP protocol by the merge commit 2da35e4b4df9 ("Merge branch 'tcp-receive-side-improvements'").
The main difference is that TCP subflow and the main MPTCP socket need to account separately for OoO: MPTCP does not care for TCP-level OoO and vice versa, as a consequence do not reflect MPTCP-level rcvbuf increase due to OoO packets at the subflow level.
This refeactor additionally allow dropping the msk receive buffer update at receive time, as the latter only intended to cope with subflow receive buffer increase due to OoO packets.
---
v2 -> v3:
- copy tcp_rcvbuf_grow() implementation, verbatim
- intentionally omitted Mat's tag due to the many changes
v1 -> v2:
- fix unused variable
- reword the commit message
--- net/mptcp/protocol.c | 97 +++++++++++++++++++++----------------------- net/mptcp/protocol.h | 4 +- 2 files changed, 49 insertions(+), 52 deletions(-)
net/mptcp/protocol.c +47 -50
@@ -179,6 +179,35 @@ static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,return mptcp_try_coalesce ((struct sock *)msk, to, from); } +/* "inspired" by tcp_rcvbuf_grow(), main difference: +* - mptcp does not maintain a msk-level window clamp +* - returns true when the receive buffer is actually updated +*/ +static bool mptcp_rcvbuf_grow (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +const struct net *net =sock_net (sk); +int rcvwin, rcvbuf, cap; + +if (!READ_ONCE (net->ipv4.sysctl_tcp_moderate_rcvbuf) || + (sk->sk_userlocks &SOCK_RCVBUF_LOCK )) +return false; + + rcvwin = msk->rcvq_space.space <<1 ; + +if (!RB_EMPTY_ROOT (&msk->out_of_order_queue)) + rcvwin +=MPTCP_SKB_CB (msk->ooo_last_skb)->end_seq - msk->ack_seq; + + cap =READ_ONCE (net->ipv4.sysctl_tcp_rmem[2 ]); + + rcvbuf =min_t (u32,mptcp_space_from_win (sk, rcvwin), cap); +if (rcvbuf > sk->sk_rcvbuf) { +WRITE_ONCE (sk->sk_rcvbuf, rcvbuf); +return true; + } +return false; +} +/* "inspired" by tcp_data_queue_ofo(), main differences: * - use mptcp seqs * - don't cope with sacks
@@ -292,6 +321,9 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) end:skb_condense (skb);skb_set_owner_r (skb, sk); +/* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */ +if (sk->sk_socket) +mptcp_rcvbuf_grow (sk); } static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
@@ -784,18 +816,10 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)return moved; } -static void __mptcp_rcvbuf_update (struct sock *sk,struct sock *ssk) -{ -if (unlikely (ssk->sk_rcvbuf > sk->sk_rcvbuf)) -WRITE_ONCE (sk->sk_rcvbuf, ssk->sk_rcvbuf); -} -static void __mptcp_data_ready (struct sock *sk,struct sock *ssk) {struct mptcp_sock *msk =mptcp_sk (sk); -__mptcp_rcvbuf_update (sk, ssk); -/* Wake-up the reader only for in-sequence data */ if (move_skbs_to_msk (msk, ssk) &&mptcp_epollin_ready (sk)) sk->sk_data_ready (sk);
@@ -2014,48 +2038,26 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)if (msk->rcvq_space.copied <= msk->rcvq_space.space) goto new_measure; -if (READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_moderate_rcvbuf) && - !(sk->sk_userlocks &SOCK_RCVBUF_LOCK )) { -u64 rcvwin, grow; -int rcvbuf; - - rcvwin = ((u64 )msk->rcvq_space.copied <<1 ) +16 * advmss; - - grow = rcvwin * (msk->rcvq_space.copied - msk->rcvq_space.space); - -do_div (grow, msk->rcvq_space.space); - rcvwin += (grow <<1 ); - - rcvbuf =min_t (u64,mptcp_space_from_win (sk, rcvwin), -READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_rmem[2 ])); - -if (rcvbuf > sk->sk_rcvbuf) { -u32 window_clamp; - - window_clamp =mptcp_win_from_space (sk, rcvbuf); -WRITE_ONCE (sk->sk_rcvbuf, rcvbuf); + msk->rcvq_space.space = msk->rcvq_space.copied; +if (mptcp_rcvbuf_grow (sk)) { -/* Make subflows follow along. If we do not do this, we -* get drops at subflow level if skbs can't be moved to -* the mptcp rx queue fast enough (announced rcv_win can -* exceed ssk->sk_rcvbuf). -*/ -mptcp_for_each_subflow (msk, subflow) { -struct sock *ssk; -bool slow; +/* Make subflows follow along. If we do not do this, we +* get drops at subflow level if skbs can't be moved to +* the mptcp rx queue fast enough (announced rcv_win can +* exceed ssk->sk_rcvbuf). +*/ +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk; +bool slow; - ssk =mptcp_subflow_tcp_sock (subflow); - slow =lock_sock_fast (ssk); -WRITE_ONCE (ssk->sk_rcvbuf, rcvbuf); -WRITE_ONCE (tcp_sk (ssk)->window_clamp, window_clamp); -if (tcp_can_send_ack (ssk)) -tcp_cleanup_rbuf (ssk,1 ); -unlock_sock_fast (ssk, slow); - } + ssk =mptcp_subflow_tcp_sock (subflow); + slow =lock_sock_fast (ssk); +tcp_sk (ssk)->rcvq_space.space = msk->rcvq_space.copied; +tcp_rcvbuf_grow (ssk); +unlock_sock_fast (ssk, slow); } } - msk->rcvq_space.space = msk->rcvq_space.copied; new_measure: msk->rcvq_space.copied =0 ; msk->rcvq_space.time = mstamp;
@@ -2084,11 +2086,6 @@ static bool __mptcp_move_skbs(struct sock *sk)if (list_empty (&msk->conn_list))return false; -/* verify we can move any data from the subflow, eventually updating */ -if (!(sk->sk_userlocks &SOCK_RCVBUF_LOCK )) -mptcp_for_each_subflow (msk, subflow) -__mptcp_rcvbuf_update (sk, subflow->tcp_sock); - subflow =list_first_entry (&msk->conn_list, struct mptcp_subflow_context, node);for (;;) {
net/mptcp/protocol.h +2 -2
@@ -342,8 +342,8 @@ struct mptcp_sock {struct mptcp_pm_data pm;struct mptcp_sched_ops *sched;struct { -u32 space;/* bytes copied in last measurement window */ -u32 copied;/* bytes copied in this measurement window */ +int space;/* bytes copied in last measurement window */ +int copied;/* bytes copied in this measurement window */ u64 time;/* start time of measurement window */ u64 rtt_us;/* last maximum rtt of subflows */ } rcvq_space;
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 5/12 mptcp: remove unneeded mptcp_move_skb()
In reply to Paolo AbeniSince commit b7535cfed223 ("mptcp: drop legacy code around RX EOF"), sk_shutdown can't change during the main recvmsg loop, we can drop the related race breaker.
--- net/mptcp/protocol.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
net/mptcp/protocol.c +1 -7
@@ -2207,14 +2207,8 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,break ; } -if (sk->sk_shutdown &RCV_SHUTDOWN ) { -/* race breaker: the shutdown could be after the -* previous receive queue check -*/ -if (__mptcp_move_skbs (sk)) -continue ; +if (sk->sk_shutdown &RCV_SHUTDOWN )break ; - }if (sk->sk_state ==TCP_CLOSE ) { copied = -ENOTCONN ;
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 6/12 mptcp: factor out a basic skb coalesce helper
In reply to Paolo AbeniThe 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.
--- net/mptcp/protocol.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +18 -6
@@ -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
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 7/12 mptcp: minor move_skbs_to_msk() cleanup
In reply to Paolo AbeniSuch function is called only by __mptcp_data_ready(), which in turn is always invoked when msk is not owned by the user: we can drop the redundant, related check.
Additionally mptcp needs to propagate the socket error only for current subflow.
--- net/mptcp/protocol.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +2 -6
@@ -815,12 +815,8 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk) moved =__mptcp_move_skbs_from_subflow (msk, ssk);__mptcp_ofo_queue (msk); -if (unlikely (ssk->sk_err)) { -if (!sock_owned_by_user (sk)) -__mptcp_error_report (sk); -else -__set_bit (MPTCP_ERROR_REPORT , &msk->cb_flags); - } +if (unlikely (ssk->sk_err)) +__mptcp_subflow_error_report (sk, ssk);/* If the moves have caught up with the DATA_FIN sequence number * it's time to ack the DATA_FIN and change socket state, but
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 4/12 mptcp: introduce the mptcp_init_skb helper.
In reply to Paolo AbeniFactor out all the skb initialization step in a new helper and use it. Note that this change moves the MPTCP CB initialization
earlier: we can do such step as soon as the skb leaves the subflow socket receive queues.
---
v1 -> v2:
- drop subflow argument from mptcp_init_skb()
- change msk args to sock arg in __mptcp_move_skb()
--- net/mptcp/protocol.c | 46 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-)
net/mptcp/protocol.c +25 -21
@@ -326,27 +326,11 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)mptcp_rcvbuf_grow (sk); } -static bool __mptcp_move_skb (struct mptcp_sock *msk,struct sock *ssk, -struct sk_buff *skb,unsigned int offset, -size_t copy_len) +static void mptcp_init_skb (struct sock *ssk, +struct sk_buff *skb,int offset,int copy_len) { -struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk); -struct sock *sk = (struct sock *)msk; -struct sk_buff *tail; -bool has_rxtstamp; - -__skb_unlink (skb, &ssk->sk_receive_queue); - -skb_ext_reset (skb); -skb_orphan (skb); - -/* try to fetch required memory from subflow */ -if (!sk_rmem_schedule (sk, skb, skb->truesize)) { -MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED ); - goto drop; - } - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; +const struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk); +bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;/* the skb map_seq accounts for the skb offset: * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
@@ -358,6 +342,24 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,MPTCP_SKB_CB (skb)->has_rxtstamp = has_rxtstamp;MPTCP_SKB_CB (skb)->cant_coalesce =0 ; +__skb_unlink (skb, &ssk->sk_receive_queue); + +skb_ext_reset (skb); +skb_dst_drop (skb); +} + +static bool __mptcp_move_skb (struct sock *sk,struct sk_buff *skb) +{ +u64 copy_len =MPTCP_SKB_CB (skb)->end_seq -MPTCP_SKB_CB (skb)->map_seq; +struct mptcp_sock *msk =mptcp_sk (sk); +struct sk_buff *tail; + +/* try to fetch required memory from subflow */ +if (!sk_rmem_schedule (sk, skb, skb->truesize)) { +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED ); + goto drop; + } +if (MPTCP_SKB_CB (skb)->map_seq == msk->ack_seq) {/* in sequence */ msk->bytes_received += copy_len;
@@ -678,7 +680,9 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,if (offset < skb->len) {size_t len = skb->len - offset; - ret =__mptcp_move_skb (msk, ssk, skb, offset, len) || ret; +mptcp_init_skb (ssk, skb, offset, len); +skb_orphan (skb); + ret =__mptcp_move_skb (sk, skb) || ret; seq += len;if (unlikely (map_remaining < len)) {
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 8/12 mptcp: cleanup fallback data fin reception
In reply to Paolo AbeniMPTCP currently generate a dummy data_fin for fallback socket when the fallback subflow has completed data reception using the current ack_seq.
We are going to introduce backlog usage for the msk soon, even for fallback sockets: the ack_seq value will not match the most recent sequence number seen by the fallback subflow socket, as it will ignore data_seq sitting in the backlog.
Instead use the last map sequence number to set the data_fin, as fallback (dummy) map sequences are always in sequence.
---
v2 -> v3:
- keep the close check in subflow_sched_work_if_closed, fix CI failures
--- net/mptcp/subflow.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/mptcp/subflow.c +3 -1
@@ -1285,6 +1285,7 @@ static bool subflow_is_done(const struct sock *sk)/* 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) { +const struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);struct sock *sk = (struct sock *)msk; if (likely(ssk->sk_state != TCP_CLOSE &&
@@ -1303,7 +1304,8 @@ static void subflow_sched_work_if_closed(struct mptcp_sock *msk, struct sock *ss*/ 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_update_rcv_data_fin (msk, subflow->map_seq + + subflow->map_data_len, true))mptcp_schedule_work (sk); }
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 9/12 mptcp: cleanup fallback dummy mapping generation.
In reply to Paolo AbeniMPTCP currently access ack_seq outside the msk socket log scope to generate the dummy mapping for fallback socket. Soon we are going to introduce backlog usage and even for fallback socket the ack_seq value will be significantly off outside of the msk socket lock scope.
Avoid relying on ack_seq for dummy mapping generation, using instead the subflow sequence number. Note that in case of disconnect() and (re)connect() we must ensure that any previous state is re-set.
---
v2 -> v3:
- reordered before the backlog introduction to avoid transiently break the fallback
- explicitly reset ack_seq
--- net/mptcp/protocol.c | 3 +++ net/mptcp/subflow.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +3 -0
@@ -3224,6 +3224,9 @@ static int mptcp_disconnect(struct sock *sk, int flags) msk->bytes_retrans =0 ; msk->rcvspace_init =0 ; +/* for fallback's sake */ +WRITE_ONCE (msk->ack_seq,0 ); +WRITE_ONCE (sk->sk_shutdown,0 );sk_error_report (sk);return 0 ;
net/mptcp/subflow.c +7 -1
@@ -491,6 +491,9 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,mptcp_crypto_key_sha (subflow->remote_key,NULL , &subflow->iasn); subflow->iasn++; +/* for fallback's sake */ + subflow->map_seq = subflow->iasn; +WRITE_ONCE (msk->remote_key, subflow->remote_key);WRITE_ONCE (msk->ack_seq, subflow->iasn);WRITE_ONCE (msk->can_ack, true);
@@ -1435,9 +1438,12 @@ static bool subflow_check_data_avail(struct sock *ssk) skb =skb_peek (&ssk->sk_receive_queue); subflow->map_valid =1 ; - subflow->map_seq =READ_ONCE (msk->ack_seq); subflow->map_data_len = skb->len; subflow->map_subflow_seq =tcp_sk (ssk)->copied_seq - subflow->ssn_offset; + subflow->map_seq =__mptcp_expand_seq (subflow->map_seq, + subflow->iasn + +TCP_SKB_CB (skb)->seq - + subflow->ssn_offset -1 );WRITE_ONCE (subflow->data_avail, true);return true; }
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 10/12 mptcp: leverage the sk backlog for RX packet processing.
In reply to Paolo AbeniThis streamline the RX path implementation and improves the RX performances by reducing the subflow-level locking and the amount of work done under the msk socket lock; the implementation mirror closely the TCP backlog processing.
Note that MPTCP needs now to traverse the existing subflow looking for data that was left there due to the msk receive buffer full, only after that recvmsg completely empties the receive queue.
--- net/mptcp/protocol.c | 103 ++++++++++++++++++++++++++++++------------- net/mptcp/protocol.h | 2 +- 2 files changed, 73 insertions(+), 32 deletions(-)
net/mptcp/protocol.c +72 -31
@@ -360,6 +360,27 @@ static void mptcp_init_skb(struct sock *ssk,skb_dst_drop (skb); } +static void __mptcp_add_backlog (struct sock *sk,struct sock *ssk, +struct sk_buff *skb) +{ +struct sk_buff *tail = sk->sk_backlog.tail; +bool fragstolen; +int delta; + +if (tail &&MPTCP_SKB_CB (skb)->map_seq ==MPTCP_SKB_CB (tail)->end_seq) { + delta =__mptcp_try_coalesce (sk, tail, skb, &fragstolen); +if (delta) { + sk->sk_backlog.len += delta; +kfree_skb_partial (skb, fragstolen); +return ; + } + } + +/* mptcp checks the limit before adding the skb to the backlog */ +__sk_add_backlog (sk, skb); + sk->sk_backlog.len += skb->truesize; +} +static bool __mptcp_move_skb (struct sock *sk,struct sk_buff *skb) {u64 copy_len =MPTCP_SKB_CB (skb)->end_seq -MPTCP_SKB_CB (skb)->map_seq;
@@ -648,7 +669,7 @@ static void mptcp_dss_corruption(struct mptcp_sock *msk, struct sock *ssk) }static bool __mptcp_move_skbs_from_subflow (struct mptcp_sock *msk, -struct sock *ssk) +struct sock *ssk,bool own_msk) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);struct sock *sk = (struct sock *)msk;
@@ -659,12 +680,13 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,pr_debug ("msk=%p ssk=%p\n" , msk, ssk); tp =tcp_sk (ssk); do { + int mem = own_msk ? sk_rmem_alloc_get(sk) : sk->sk_backlog.len; u32 map_remaining, offset; u32 seq = tp->copied_seq; struct sk_buff *skb; bool fin; - if (sk_rmem_alloc_get(sk) > sk->sk_rcvbuf) + if (mem > READ_ONCE(sk->sk_rcvbuf)) break; /* try to move as much data as available */
@@ -694,7 +716,11 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,mptcp_init_skb (ssk, skb, offset, len);skb_orphan (skb); - ret =__mptcp_move_skb (sk, skb) || ret; + +if (own_msk) + ret |=__mptcp_move_skb (sk, skb); +else +__mptcp_add_backlog (sk, ssk, skb); seq += len;if (unlikely (map_remaining < len)) {
@@ -715,7 +741,7 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, }while (more_data_avail); -if (ret) +if (ret && own_msk) msk->last_data_recv = tcp_jiffies32;return ret; }
@@ -813,7 +839,7 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)struct sock *sk = (struct sock *)msk;bool moved; - moved =__mptcp_move_skbs_from_subflow (msk, ssk); + moved =__mptcp_move_skbs_from_subflow (msk, ssk, true);__mptcp_ofo_queue (msk);if (unlikely (ssk->sk_err))__mptcp_subflow_error_report (sk, ssk);
@@ -828,18 +854,10 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)return moved; } -static void __mptcp_data_ready (struct sock *sk,struct sock *ssk) -{ -struct mptcp_sock *msk =mptcp_sk (sk); - -/* Wake-up the reader only for in-sequence data */ -if (move_skbs_to_msk (msk, ssk) &&mptcp_epollin_ready (sk)) - sk->sk_data_ready (sk); -} -void mptcp_data_ready (struct sock *sk,struct sock *ssk) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk); +struct mptcp_sock *msk =mptcp_sk (sk);/* The peer can send data while we are shutting down this * subflow at msk destruction time, but we must avoid enqueuing
@@ -849,13 +867,33 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)return ;mptcp_data_lock (sk); -if (!sock_owned_by_user (sk)) -__mptcp_data_ready (sk, ssk); -else -__set_bit (MPTCP_DEQUEUE , &mptcp_sk (sk)->cb_flags); +if (!sock_owned_by_user (sk)) { +/* Wake-up the reader only for in-sequence data */ +if (move_skbs_to_msk (msk, ssk) &&mptcp_epollin_ready (sk)) + sk->sk_data_ready (sk); + }else { +__mptcp_move_skbs_from_subflow (msk, ssk, false); +if (unlikely (ssk->sk_err)) +__set_bit (MPTCP_ERROR_REPORT , &msk->cb_flags); + }mptcp_data_unlock (sk); } +static int mptcp_move_skb (struct sock *sk,struct sk_buff *skb) +{ +struct mptcp_sock *msk =mptcp_sk (sk); + +if (__mptcp_move_skb (sk, skb)) { + msk->last_data_recv = tcp_jiffies32; +__mptcp_ofo_queue (msk); +/* notify ack seq update */ +mptcp_cleanup_rbuf (msk,0 ); +mptcp_check_data_fin (sk); + sk->sk_data_ready (sk); + } +return 0 ; +} +static void mptcp_subflow_joined (struct mptcp_sock *msk,struct sock *ssk) {mptcp_subflow_ctx (ssk)->map_seq =READ_ONCE (msk->ack_seq);
@@ -2117,7 +2155,7 @@ static bool __mptcp_move_skbs(struct sock *sk) ssk =mptcp_subflow_tcp_sock (subflow); slowpath =lock_sock_fast (ssk); - ret =__mptcp_move_skbs_from_subflow (msk, ssk) || ret; + ret =__mptcp_move_skbs_from_subflow (msk, ssk, true) || ret;if (unlikely (ssk->sk_err))__mptcp_error_report (sk);unlock_sock_fast (ssk, slowpath);
@@ -2193,8 +2231,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, copied += bytes_read; -if (skb_queue_empty (&sk->sk_receive_queue) &&__mptcp_move_skbs (sk)) -continue ; +if (skb_queue_empty (&sk->sk_receive_queue)) { +__sk_flush_backlog (sk); +if (!skb_queue_empty (&sk->sk_receive_queue) || +__mptcp_move_skbs (sk)) +continue ; + }/* only the MPTCP socket status is relevant here. The exit * conditions mirror closely tcp_recvmsg()
@@ -2542,7 +2584,6 @@ static void __mptcp_close_subflow(struct sock *sk)mptcp_close_ssk (sk, ssk, subflow); } - }static bool mptcp_close_tout_expired (const struct sock *sk)
@@ -3126,6 +3167,13 @@ bool __mptcp_close(struct sock *sk, long timeout)pr_debug ("msk=%p state=%d\n" , sk, sk->sk_state);mptcp_pm_connection_closed (msk); +/* process the backlog; note that it never destroies the msk */ +local_bh_disable (); +bh_lock_sock (sk); +__release_sock (sk); +bh_unlock_sock (sk); +local_bh_enable (); +if (sk->sk_state ==TCP_CLOSE ) {__mptcp_destroy_sock (sk); do_cancel_work = true;
@@ -3429,8 +3477,7 @@ void __mptcp_check_push(struct sock *sk, struct sock *ssk)#define MPTCP_FLAGS_PROCESS_CTX_NEED (BIT(MPTCP_PUSH_PENDING) | \ BIT(MPTCP_RETRANSMIT) | \ - BIT(MPTCP_FLUSH_JOIN_LIST) | \ - BIT(MPTCP_DEQUEUE)) + BIT(MPTCP_FLUSH_JOIN_LIST))/* processes deferred events and flush wmem */ static void mptcp_release_cb (struct sock *sk)
@@ -3464,11 +3511,6 @@ static void mptcp_release_cb(struct sock *sk)__mptcp_push_pending (sk,0 );if (flags &BIT (MPTCP_RETRANSMIT ))__mptcp_retrans (sk); -if ((flags &BIT (MPTCP_DEQUEUE )) &&__mptcp_move_skbs (sk)) { -/* notify ack seq update */ -mptcp_cleanup_rbuf (msk,0 ); - sk->sk_data_ready (sk); - }cond_resched ();spin_lock_bh (&sk->sk_lock.slock);
@@ -3704,8 +3746,6 @@ static int mptcp_ioctl(struct sock *sk, int cmd, int *karg)return -EINVAL ;lock_sock (sk); -if (__mptcp_move_skbs (sk)) -mptcp_cleanup_rbuf (msk,0 ); *karg =mptcp_inq_hint (sk);release_sock (sk);break ;
@@ -3817,6 +3857,7 @@ static struct proto mptcp_prot = { .sendmsg = mptcp_sendmsg, .ioctl = mptcp_ioctl, .recvmsg = mptcp_recvmsg, + .backlog_rcv = mptcp_move_skb, .release_cb = mptcp_release_cb, .hash = mptcp_hash, .unhash = mptcp_unhash,
net/mptcp/protocol.h +1 -1
@@ -124,7 +124,6 @@#define MPTCP_FLUSH_JOIN_LIST 5#define MPTCP_SYNC_STATE 6#define MPTCP_SYNC_SNDBUF 7 -#define MPTCP_DEQUEUE 8struct mptcp_skb_cb {u64 map_seq;
@@ -408,6 +407,7 @@ static inline int mptcp_space_from_win(const struct sock *sk, int win)static inline int __mptcp_space (const struct sock *sk) {return mptcp_win_from_space (sk,READ_ONCE (sk->sk_rcvbuf) - +READ_ONCE (sk->sk_backlog.len) -sk_rmem_alloc_get (sk)); }
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 11/12 mptcp: prevernt __mptcp_move_skbs() interfering with the fastpath
In reply to Paolo Abeniskbs will be left waiting in the subflow only in exceptional cases, we want to avoid messing with the fast path by unintentionally processing in __mptcp_move_skbs() packets landed into the subflows after the last check.
Use a separate flag to mark delayed skbs and only process subflow with such flag set. Also add new mibs to track the exceptional events.
---
v1 -> v2:
- rebased
--- net/mptcp/mib.c | 2 ++ net/mptcp/mib.h | 4 ++++ net/mptcp/protocol.c | 40 ++++++++++++---------------------------- net/mptcp/protocol.h | 1 + 4 files changed, 19 insertions(+), 28 deletions(-)
net/mptcp/mib.c +2 -0
@@ -85,6 +85,8 @@ static const struct snmp_mib mptcp_snmp_list[] = {SNMP_MIB_ITEM ("DssFallback" ,MPTCP_MIB_DSSFALLBACK ),SNMP_MIB_ITEM ("SimultConnectFallback" ,MPTCP_MIB_SIMULTCONNFALLBACK ),SNMP_MIB_ITEM ("FallbackFailed" ,MPTCP_MIB_FALLBACKFAILED ), +SNMP_MIB_ITEM ("RcvDelayed" ,MPTCP_MIB_RCVDELAYED ), + SNMP_MIB_ITEM("DelayedProcess", MPTCP_MIB_DELAYED_PROCESS), };/* mptcp_mib_alloc - allocate percpu mib counters
net/mptcp/mib.h +4 -0
@@ -88,6 +88,10 @@ enum linux_mptcp_mib_field {MPTCP_MIB_DSSFALLBACK ,/* Bad or missing DSS */ MPTCP_MIB_SIMULTCONNFALLBACK ,/* Simultaneous connect */ MPTCP_MIB_FALLBACKFAILED ,/* Can't fallback due to msk status */ +MPTCP_MIB_RCVDELAYED ,/* Data move from subflow is delayed due to msk +* receive buffer full +*/ +MPTCP_MIB_DELAYED_PROCESS ,/* Delayed data moved in slowpath */ __MPTCP_MIB_MAX };
net/mptcp/protocol.c +12 -28
@@ -681,13 +681,17 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, tp =tcp_sk (ssk); do { int mem = own_msk ? sk_rmem_alloc_get(sk) : sk->sk_backlog.len; + bool over_limit = mem > READ_ONCE(sk->sk_rcvbuf); u32 map_remaining, offset; u32 seq = tp->copied_seq; struct sk_buff *skb; bool fin; - if (mem > READ_ONCE(sk->sk_rcvbuf)) + WRITE_ONCE(subflow->data_delayed, over_limit); + if (subflow->data_delayed) { + MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVDELAYED); break; + } /* try to move as much data as available */ map_remaining = subflow->map_data_len -
@@ -2113,32 +2117,13 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied) msk->rcvq_space.time = mstamp; } -static struct mptcp_subflow_context * -__mptcp_first_ready_from (struct mptcp_sock *msk, -struct mptcp_subflow_context *subflow) -{ -struct mptcp_subflow_context *start_subflow = subflow; - -while (!READ_ONCE (subflow->data_avail)) { - subflow =mptcp_next_subflow (msk, subflow); -if (subflow == start_subflow) -return NULL ; - } -return subflow; -} -static bool __mptcp_move_skbs (struct sock *sk) {struct mptcp_subflow_context *subflow;struct mptcp_sock *msk =mptcp_sk (sk);bool ret = false; -if (list_empty (&msk->conn_list)) -return false; - - subflow =list_first_entry (&msk->conn_list, - struct mptcp_subflow_context, node); -for (;;) { +mptcp_for_each_subflow (msk, subflow) {struct sock *ssk;bool slowpath;
@@ -2149,23 +2134,22 @@ static bool __mptcp_move_skbs(struct sock *sk)if (sk_rmem_alloc_get (sk) > sk->sk_rcvbuf)break ; - subflow =__mptcp_first_ready_from (msk, subflow); -if (!subflow) -break ; +if (!subflow->data_delayed) +continue ; ssk =mptcp_subflow_tcp_sock (subflow); slowpath =lock_sock_fast (ssk); - ret =__mptcp_move_skbs_from_subflow (msk, ssk, true) || ret; + ret |=__mptcp_move_skbs_from_subflow (msk, ssk, true);if (unlikely (ssk->sk_err))__mptcp_error_report (sk);unlock_sock_fast (ssk, slowpath); - - subflow =mptcp_next_subflow (msk, subflow); }__mptcp_ofo_queue (msk); -if (ret) +if (ret) { +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_DELAYED_PROCESS );mptcp_check_data_fin ((struct sock *)msk); + }return ret; }
net/mptcp/protocol.h +1 -0
@@ -560,6 +560,7 @@ struct mptcp_subflow_context { u8 reset_transient:1; u8 reset_reason:4;u8 stale_count; +bool data_delayed;u32 subflow_id;
Signature · 1 line
2.51.0
Paolo Abeni
maintainerPATCH v3 12/12 mptcp: borrow forward memory from subflow
In reply to Paolo AbeniIn the MPTCP receive path, we release the subflow allocated fwd memory just to allocate it again shortly after for the msk.
That could increases the failures chances, especially during backlog processing, when other actions could consume the just released memory before the msk socket has a chance to do the rcv allocation.
Replace the skb_orphan() call with an open-coded variant that explicitly borrows, with a PAGE_SIZE granularity, the fwd memory from the subflow socket instead of releasing it. During backlog processing the borrowed memory is accounted at release_cb time.
---
v1 -> v2:
- rebased
- explain why skb_orphan is removed
--- net/mptcp/protocol.c | 27 +++++++++++++++++++++------ net/mptcp/protocol.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +21 -6
@@ -338,11 +338,12 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)mptcp_rcvbuf_grow (sk); } -static void mptcp_init_skb (struct sock *ssk, -struct sk_buff *skb,int offset,int copy_len) +static int mptcp_init_skb (struct sock *ssk, +struct sk_buff *skb,int offset,int copy_len) {const struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; +int borrowed;/* the skb map_seq accounts for the skb offset: * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
@@ -358,6 +359,15 @@ static void mptcp_init_skb(struct sock *ssk,skb_ext_reset (skb);skb_dst_drop (skb); + +/* "borrow" the fwd memory from the subflow, instead of reclaiming it */ + skb->destructor =NULL ; + skb->sk =NULL ; +atomic_sub (skb->truesize, &ssk->sk_rmem_alloc); + borrowed = ssk->sk_forward_alloc -sk_unused_reserved_mem (ssk); + borrowed &= ~(PAGE_SIZE -1 ); +sk_forward_alloc_add (ssk, skb->truesize - borrowed); +return borrowed; } static void __mptcp_add_backlog(struct sock *sk, struct sock *ssk,
@@ -717,14 +727,17 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,if (offset < skb->len) {size_t len = skb->len - offset; +int bmem; -mptcp_init_skb (ssk, skb, offset, len); -skb_orphan (skb); + bmem =mptcp_init_skb (ssk, skb, offset, len); -if (own_msk) +if (own_msk) { +sk_forward_alloc_add (sk, bmem); ret |=__mptcp_move_skb (sk, skb); -else + }else { + msk->borrowed_fwd_mem += bmem;__mptcp_add_backlog (sk, ssk, skb); + } seq += len;if (unlikely (map_remaining < len)) {
@@ -3514,6 +3527,8 @@ static void mptcp_release_cb(struct sock *sk)if (__test_and_clear_bit (MPTCP_SYNC_SNDBUF , &msk->cb_flags))__mptcp_sync_sndbuf (sk); } +sk_forward_alloc_add (sk, msk->borrowed_fwd_mem); + msk->borrowed_fwd_mem =0 ; }/* MP_JOIN client subflow must wait for 4th ack before sending any data:
net/mptcp/protocol.h +1 -0
@@ -298,6 +298,7 @@ struct mptcp_sock {u32 last_data_sent;u32 last_data_recv;u32 last_ack_recv; +int borrowed_fwd_mem;unsigned long timer_ival;u32 token;unsigned long flags;
Signature · 1 line
2.51.0
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: Unstable: 1 failed test(s): selftest_mptcp_connect 🔴
- 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/17863851247
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/fe9e565e924a
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1004322
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-normalFor 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)
Re: [MPTCP next v3 03/12] mptcp: rcvbuf auto-tuning improvement
In reply to Paolo AbeniHi Paolo,
Quoted 18 lines · Paolo Abeni
Apply to the MPTCP auto-tuning the same improvements introduced for the TCP protocol by the merge commit
2da35e4b4df9("Merge branch 'tcp-receive-side-improvements'").The main difference is that TCP subflow and the main MPTCP socket need to account separately for OoO: MPTCP does not care for TCP-level OoO and vice versa, as a consequence do not reflect MPTCP-level rcvbuf increase due to OoO packets at the subflow level.
This refeactor additionally allow dropping the msk receive buffer update at receive time, as the latter only intended to cope with subflow receive buffer increase due to OoO packets.
Quoted 4 lines
---
v2 -> v3:
- copytcp_rcvbuf_grow()implementation, verbatim
- intentionally omitted Mat's tag due to the many changes
Thank you for the v3, that's easier to spot the differences now!
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerHi Paolo,
Quoted 17 lines · Paolo Abeni
This series includes several changes to the MPTCP RX path.
The main goals are improving the RX performances _and_ increase the long term maintainability.
Some changes reflects recent (or not so) improvements introduced in the TCP stack: patch 1, 2 and 3 are the MPTCP counter part of skb deferral free and auto-tuning improvements.
Note that patch 3 could possibly fix issues/574, and overall such patch should protect from similar issues to arise in the future.
All the others patches are aimed at introducing the socket backlog usage to process the packets received by the subflows while the msk socket is owned. That (almost completely) replace the processing currently happening in the
mptcp_release_cb().
Quoted 8 lines
The actual job is done in patch 10, while the others are cleanups needed to make the change tidy and more follow-up cleanups.
Sharing earlier with known issues (at least on fallback socket) to raise awareness about this upcoming work.
---
v2 -> v3:
- (hopefully) addressed CI failures
Sadly, the CI doesn't seem that happy, but only in debug mode:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17863851247
If it is easier for you, I can already apply (and send to netdev?) some of these patches? e.g. 1-7/12?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Re: [MPTCP next v3 04/12] mptcp: introduce the mptcp_init_skb helper.
In reply to Paolo AbeniHi Paolo,
Thank you for the v3. All tests pass on my end, including my "implement mptcp read_sock v11" test case.
I have a few minor cleanup comments to make the patch clean. There is no need to send a v4 or block the merging of this series. Matt can make the changes when he merges it, or I can send some squash-to patches to address these after merging. Either approach would be fine.
Quoted 32 lines · Paolo Abeni
Factor out all the skb initialization step in a new helper and use it. Note that this change moves the MPTCP CB initialization
earlier: we can do such step as soon as the skb leaves the subflow socket receive queues.Reviewed-by Matthieu Baerts (NGI0) <[email protected]>Signed-off-by Paolo Abeni <[email protected]>---
v1 -> v2:
- drop subflow argument frommptcp_init_skb()
- change msk args to sock arg in__mptcp_move_skb()
---
net/mptcp/protocol.c | 46 ++++++++++++++++++++++++------------------ --1 file changed, 25 insertions(+), 21 deletions(-)net/mptcp/protocol.c +0
-0@@ -326,27 +326,11 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) mptcp_rcvbuf_grow(sk); }
-static bool __mptcp_move_skb(structmptcp_sock*msk, struct sock *ssk,net/mptcp/protocol.c +0
-1- struct sk_buff *skb, unsigned intoffset,
net/mptcp/protocol.c +2
-1- size_t copy_len) +static void mptcp_init_skb (struct sock *ssk, + struct sk_buff *skb, int offset, int
Quoted 1 line
copy_len)
nit:
static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb,
int offset, int copy_len)
is better.
Quoted 21 lines
{
net/mptcp/protocol.c +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +1
-16-struct sock *sk = (struct sock *)msk; -struct sk_buff *tail; -bool has_rxtstamp; - -__skb_unlink (skb, &ssk->sk_receive_queue); - -skb_ext_reset (skb); -skb_orphan (skb); - -/* try to fetch required memory from subflow */ -if (!sk_rmem_schedule (sk, skb, skb->truesize)) { -MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED ); - goto drop; - } - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; + const struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);
net/mptcp/protocol.c static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) · line 333
Quoted 1 line
net/mptcp/protocol.c +1
-0+bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;
nit, how about keeping it as the original code to make this patch smaller:
- struct mptcp_subflow_context *subflow =mptcp_subflow_ctx(ssk);
- bool has_rxtstamp;
-
- has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
Thanks,
-Geliang
Quoted 44 lines
/* the skbmap_seqaccounts for the skb offset:
*mptcp_subflow_get_mapped_dsn()is based on the currenttp->copied_seqnet/mptcp/protocol.c +0
-0@@ -358,6 +342,24 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk, MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp; MPTCP_SKB_CB(skb)->cant_coalesce = 0;net/mptcp/protocol.c +9
-0+__skb_unlink (skb, &ssk->sk_receive_queue); + +skb_ext_reset (skb); +skb_dst_drop (skb); +} + +static bool __mptcp_move_skb (struct sock *sk,struct sk_buff *skb) +{ + u64 copy_len = MPTCP_SKB_CB(skb)->end_seq -MPTCP_SKB_CB(skb)->map_seq;
net/mptcp/protocol.c +9
-0+struct mptcp_sock *msk =mptcp_sk (sk); +struct sk_buff *tail; + +/* try to fetch required memory from subflow */ +if (!sk_rmem_schedule (sk, skb, skb->truesize)) { +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED ); + goto drop; + } +if (MPTCP_SKB_CB(skb)->map_seq ==
msk->ack_seq) { /* in sequence */msk->bytes_received+=copy_len;net/mptcp/protocol.c +0
-0@@ -678,7 +680,9 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, if (offset < skb->len) { size_t len = skb->len - offset;net/mptcp/protocol.c +0
-1- ret = __mptcp_move_skb(msk, ssk, skb,offset, len) || ret;
net/mptcp/protocol.c +3
-0+mptcp_init_skb (ssk, skb, offset, len); +skb_orphan (skb); + ret =__mptcp_move_skb (sk, skb) || ret;seq += len;
if (unlikely(map_remaining < len)) {
Re: [MPTCP next v3 04/12] mptcp: introduce the mptcp_init_skb helper.
In reply to Paolo AbeniHi Paolo,
Thank you for the v3. All tests pass on my end, including my "implement mptcp read_sock v11" test case.
I have a few minor cleanup comments to make the patch clean. There is no need to send a v4 or block the merging of this series. Matt can make the changes when he merges it, or I can send some squash-to patches to address these after merging. Either approach would be fine.
Quoted 32 lines · Paolo Abeni
Factor out all the skb initialization step in a new helper and use it. Note that this change moves the MPTCP CB initialization
earlier: we can do such step as soon as the skb leaves the subflow socket receive queues.Reviewed-by Matthieu Baerts (NGI0) <[email protected]>Signed-off-by Paolo Abeni <[email protected]>---
v1 -> v2:
- drop subflow argument frommptcp_init_skb()
- change msk args to sock arg in__mptcp_move_skb()
---
net/mptcp/protocol.c | 46 ++++++++++++++++++++++++------------------ --1 file changed, 25 insertions(+), 21 deletions(-)net/mptcp/protocol.c +0
-0@@ -326,27 +326,11 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) mptcp_rcvbuf_grow(sk); }
-static bool __mptcp_move_skb(structmptcp_sock*msk, struct sock *ssk,net/mptcp/protocol.c +0
-1- struct sk_buff *skb, unsigned intoffset,
net/mptcp/protocol.c +2
-1- size_t copy_len) +static void mptcp_init_skb (struct sock *ssk, + struct sk_buff *skb, int offset, int
Quoted 1 line
copy_len)
nit:
static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb,
int offset, int copy_len)
is better.
Quoted 21 lines
{
net/mptcp/protocol.c +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +1
-16-struct sock *sk = (struct sock *)msk; -struct sk_buff *tail; -bool has_rxtstamp; - -__skb_unlink (skb, &ssk->sk_receive_queue); - -skb_ext_reset (skb); -skb_orphan (skb); - -/* try to fetch required memory from subflow */ -if (!sk_rmem_schedule (sk, skb, skb->truesize)) { -MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED ); - goto drop; - } - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; + const struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);
net/mptcp/protocol.c static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) · line 333
Quoted 1 line
net/mptcp/protocol.c +1
-0+bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;
nit, how about keeping it as the original code to make this patch smaller:
- struct mptcp_subflow_context *subflow =mptcp_subflow_ctx(ssk);
- bool has_rxtstamp;
-
- has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
Thanks,
-Geliang
Quoted 44 lines
/* the skbmap_seqaccounts for the skb offset:
*mptcp_subflow_get_mapped_dsn()is based on the currenttp->copied_seqnet/mptcp/protocol.c +0
-0@@ -358,6 +342,24 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk, MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp; MPTCP_SKB_CB(skb)->cant_coalesce = 0;net/mptcp/protocol.c +9
-0+__skb_unlink (skb, &ssk->sk_receive_queue); + +skb_ext_reset (skb); +skb_dst_drop (skb); +} + +static bool __mptcp_move_skb (struct sock *sk,struct sk_buff *skb) +{ + u64 copy_len = MPTCP_SKB_CB(skb)->end_seq -MPTCP_SKB_CB(skb)->map_seq;
net/mptcp/protocol.c +9
-0+struct mptcp_sock *msk =mptcp_sk (sk); +struct sk_buff *tail; + +/* try to fetch required memory from subflow */ +if (!sk_rmem_schedule (sk, skb, skb->truesize)) { +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED ); + goto drop; + } +if (MPTCP_SKB_CB(skb)->map_seq ==
msk->ack_seq) { /* in sequence */msk->bytes_received+=copy_len;net/mptcp/protocol.c +0
-0@@ -678,7 +680,9 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, if (offset < skb->len) { size_t len = skb->len - offset;net/mptcp/protocol.c +0
-1- ret = __mptcp_move_skb(msk, ssk, skb,offset, len) || ret;
net/mptcp/protocol.c +3
-0+mptcp_init_skb (ssk, skb, offset, len); +skb_orphan (skb); + ret =__mptcp_move_skb (sk, skb) || ret;seq += len;
if (unlikely(map_remaining < len)) {
Re: [MPTCP next v3 08/12] mptcp: cleanup fallback data fin reception
In reply to Paolo AbeniQuoted 11 lines · Paolo Abeni
MPTCP currently generate a dummy
data_finfor fallback socket when the fallback subflow has completed data reception using the currentack_seq.We are going to introduce backlog usage for the msk soon, even for fallback sockets: the
ack_seqvalue will not match the most recent
sequence number seen by the fallback subflow socket, as it will ignoredata_seqsitting in the backlog.
Quoted 4 lines
Instead use the last map sequence number to set the
data_fin, as fallback (dummy) map sequences are always in sequence.Signed-off-by Paolo Abeni <[email protected]>
LGTM.
Thanks,
-Geliang
Quoted 36 lines
---
v2 -> v3:
- keep the close check insubflow_sched_work_if_closed, fix CI failures
---
net/mptcp/subflow.c | 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)net/mptcp/subflow.c +1
-0@@ -1285,6 +1285,7 @@ static bool subflow_is_done(const struct sock *sk) /* 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) { + const struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);
struct sock *sk = (struct sock *)msk;
if (likely(ssk->sk_state !=TCP_CLOSE&&net/mptcp/subflow.c +0
-0@@ -1303,7 +1304,8 @@ static void subflow_sched_work_if_closed(struct
mptcp_sock*msk, struct sock *ss
*/
if (__mptcp_check_fallback(msk)&&subflow_is_done(ssk)&&msk->first== ssk &&net/mptcp/subflow.c +0
-1- mptcp_update_rcv_data_fin(msk, READ_ONCE(msk->ack_seq),true))
net/mptcp/subflow.c +2
-0+ mptcp_update_rcv_data_fin(msk, subflow->map_seq + + subflow->map_data_len, true))
mptcp_schedule_work(sk);
}
Re: [MPTCP next v3 09/12] mptcp: cleanup fallback dummy mapping generation.
In reply to Paolo AbeniQuoted 56 lines · Paolo Abeni
MPTCP currently access
ack_seqoutside the msk socket log scope to generate the dummy mapping for fallback socket. Soon we are going to introduce backlog usage and even for fallback socket theack_seqvalue will be significantly off outside of the msk socket lock scope.Avoid relying on
ack_seqfor dummy mapping generation, using instead the subflow sequence number. Note that in case ofdisconnect()and (re)connect() we must ensure that any previous state is re-set.Signed-off-by Paolo Abeni <[email protected]>---
v2 -> v3:
- reordered before the backlog introduction to avoid transiently break the fallback
- explicitly resetack_seq
---
net/mptcp/protocol.c | 3 +++
net/mptcp/subflow.c | 8 +++++++-2 files changed, 10 insertions(+), 1 deletion(-)net/mptcp/protocol.c +0
-0@@ -3224,6 +3224,9 @@ static int mptcp_disconnect(struct sock *sk, int flags) msk->bytes_retrans = 0; msk->rcvspace_init = 0;net/mptcp/protocol.c +3
-0+/* for fallback's sake */ +WRITE_ONCE (msk->ack_seq,0 ); +
WRITE_ONCE(sk->sk_shutdown, 0);
sk_error_report(sk);
return 0;net/mptcp/subflow.c +0
-0@@ -491,6 +491,9 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,mptcp_crypto_key_sha(subflow->remote_key, NULL, &subflow-
Quoted 1 line
iasn);
subflow->iasn++;
net/mptcp/subflow.c +3
-0+/* for fallback's sake */ + subflow->map_seq = subflow->iasn; +
WRITE_ONCE(msk->remote_key, subflow->remote_key);WRITE_ONCE(msk->ack_seq, subflow->iasn);WRITE_ONCE(msk->can_ack, true);net/mptcp/subflow.c +0
-0@@ -1435,9 +1438,12 @@ static bool subflow_check_data_avail(struct sock *ssk)
skb =skb_peek(&ssk->sk_receive_queue);
subflow->map_valid= 1;
net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1438
Quoted 1 line
net/mptcp/subflow.c +0
-1- subflow->map_seq =READ_ONCE (msk->ack_seq);
nit:
How about replacing this line in place? I mean, do not move it to a later position:
+ subflow->map_seq = __mptcp_expand_seq(subflow->map_seq,
+ subflow->iasn + + TCP_SKB_CB(skb)->seq - + subflow->ssn_offset -
1);
Thanks,
-Geliang
Quoted 11 lines
subflow->map_data_len=skb->len;subflow->map_subflow_seq= tcp_sk(ssk)->copied_seq -subflow->ssn_offset;net/mptcp/subflow.c +4
-0+ subflow->map_seq = __mptcp_expand_seq(subflow->map_seq, + subflow->iasn + + TCP_SKB_CB(skb)->seq - + subflow->ssn_offset -1);
WRITE_ONCE(subflow->data_avail, true);
return true;
}
Geliang Tang
reviewerRe: [MPTCP next v3 10/12] mptcp: leverage the sk backlog for RX packet processing.
In reply to Paolo AbeniQuoted 215 lines · Paolo Abeni
This streamline the RX path implementation and improves the RX performances by reducing the subflow-level locking and the amount of work done under the msk socket lock; the implementation mirror closely
the TCP backlog processing.Note that MPTCP needs now to traverse the existing subflow looking for
data that was left there due to the msk receive buffer full, only after
that recvmsg completely empties the receive queue.Signed-off-by Paolo Abeni <[email protected]>---
net/mptcp/protocol.c | 103 ++++++++++++++++++++++++++++++----------- --
net/mptcp/protocol.h | 2 +-2 files changed, 73 insertions(+), 32 deletions(-)net/mptcp/protocol.c +0
-0@@ -360,6 +360,27 @@ static void mptcp_init_skb(struct sock *ssk, skb_dst_drop(skb); }net/mptcp/protocol.c +8
-0+static void __mptcp_add_backlog(struct sock *sk, struct sock *ssk, + struct sk_buff *skb) +{ + struct sk_buff *tail = sk->sk_backlog.tail; + bool fragstolen; + int delta; + + if (tail && MPTCP_SKB_CB(skb)->map_seq ==MPTCP_SKB_CB(tail)->end_seq) {
net/mptcp/protocol.c +1
-0+ delta = __mptcp_try_coalesce(sk, tail, skb,&fragstolen);
net/mptcp/protocol.c +8
-0+if (delta) { + sk->sk_backlog.len += delta; +kfree_skb_partial (skb, fragstolen); +return ; + } + } + +/* mptcp checks the limit before adding the skb to the backlog */
net/mptcp/protocol.c +4
-0+__sk_add_backlog (sk, skb); + sk->sk_backlog.len += skb->truesize; +} +static bool
__mptcp_move_skb(struct sock *sk, struct sk_buff *skb){
u64copy_len= MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;net/mptcp/protocol.c +0
-0@@ -648,7 +669,7 @@ static void mptcp_dss_corruption(struct mptcp_sock *msk, struct sock *ssk) }
static bool __mptcp_move_skbs_from_subflow(structmptcp_sock*msk,net/mptcp/protocol.c +1
-1- struct sock *ssk) + struct sock *ssk, bool
own_msk)
{
structmptcp_subflow_context*subflow =mptcp_subflow_ctx(ssk);
struct sock *sk = (struct sock *)msk;net/mptcp/protocol.c +1
-0@@ -659,12 +680,13 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, pr_debug("msk=%p ssk=%p\n", msk, ssk); tp = tcp_sk(ssk); do { + int mem = own_msk ? sk_rmem_alloc_get(sk) : sk- >sk_backlog.len; u32 map_remaining, offset; u32 seq = tp->copied_seq; struct sk_buff *skb; bool fin;net/mptcp/protocol.c +1
-1-if (sk_rmem_alloc_get (sk) > sk->sk_rcvbuf) +if (mem >READ_ONCE (sk->sk_rcvbuf))break;
/* try to move as much data as available */net/mptcp/protocol.c +0
-0@@ -694,7 +716,11 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
mptcp_init_skb(ssk, skb, offset, len);skb_orphan(skb);net/mptcp/protocol.c +5
-1- ret =__mptcp_move_skb (sk, skb) || ret; + +if (own_msk) + ret |=__mptcp_move_skb (sk, skb); +else +__mptcp_add_backlog (sk, ssk, skb);seq += len;
if (unlikely(map_remaining < len)) {net/mptcp/protocol.c +0
-0@@ -715,7 +741,7 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
} while (more_data_avail);net/mptcp/protocol.c +1
-1-if (ret) +if (ret && own_msk)
msk->last_data_recv=tcp_jiffies32; return ret;
}net/mptcp/protocol.c +0
-0@@ -813,7 +839,7 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk) struct sock *sk = (struct sock *)msk; bool moved;net/mptcp/protocol.c +1
-1- moved =__mptcp_move_skbs_from_subflow (msk, ssk); + moved =__mptcp_move_skbs_from_subflow (msk, ssk, true);
__mptcp_ofo_queue(msk);
if (unlikely(ssk->sk_err))__mptcp_subflow_error_report(sk, ssk);net/mptcp/protocol.c +0
-0@@ -828,18 +854,10 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk) return moved; }net/mptcp/protocol.c +0
-9-static void __mptcp_data_ready (struct sock *sk,struct sock *ssk) -{ -struct mptcp_sock *msk =mptcp_sk (sk); - -/* Wake-up the reader only for in-sequence data */ -if (move_skbs_to_msk (msk, ssk) &&mptcp_epollin_ready (sk)) - sk->sk_data_ready (sk); -} -void
mptcp_data_ready(struct sock *sk, struct sock *ssk){
structmptcp_subflow_context*subflow =mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +1
-0+struct mptcp_sock *msk =mptcp_sk (sk);
/* The peer can send data while we are shutting down this
* subflow at msk destruction time, but we must avoid enqueuingnet/mptcp/protocol.c +0
-0@@ -849,13 +867,33 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk) return;
mptcp_data_lock(sk);net/mptcp/protocol.c +3
-4-if (!sock_owned_by_user (sk)) -__mptcp_data_ready (sk, ssk); -else -__set_bit (MPTCP_DEQUEUE , &mptcp_sk (sk)->cb_flags); +if (!sock_owned_by_user (sk)) { +/* Wake-up the reader only for in-sequence data */ + if (move_skbs_to_msk(msk, ssk) &&
mptcp_epollin_ready(sk))net/mptcp/protocol.c +5
-0+ sk->sk_data_ready (sk); + }else { +__mptcp_move_skbs_from_subflow (msk, ssk, false); +if (unlikely (ssk->sk_err)) + __set_bit(MPTCP_ERROR_REPORT, &msk-Quoted 1 line
cb_flags);net/mptcp/protocol.c +1
-0+ }
mptcp_data_unlock(sk);
}net/mptcp/protocol.c +15
-0+static int mptcp_move_skb (struct sock *sk,struct sk_buff *skb) +{ +struct mptcp_sock *msk =mptcp_sk (sk); + +if (__mptcp_move_skb (sk, skb)) { + msk->last_data_recv = tcp_jiffies32; +__mptcp_ofo_queue (msk); +/* notify ack seq update */ +mptcp_cleanup_rbuf (msk,0 ); +mptcp_check_data_fin (sk); + sk->sk_data_ready (sk); + } +return 0 ; +} +static void
mptcp_subflow_joined(struct mptcp_sock *msk, struct sock *ssk)
{
mptcp_subflow_ctx(ssk)->map_seq =READ_ONCE(msk->ack_seq);net/mptcp/protocol.c +0
-0@@ -2117,7 +2155,7 @@ static bool __mptcp_move_skbs(struct sock *sk)
ssk =mptcp_subflow_tcp_sock(subflow); slowpath =lock_sock_fast(ssk);net/mptcp/protocol.c +0
-1- ret = __mptcp_move_skbs_from_subflow(msk, ssk) ||ret;
net/mptcp/protocol.c +1
-0+ ret =__mptcp_move_skbs_from_subflow (msk, ssk, true)|| ret;
if (unlikely(ssk->sk_err))
__mptcp_error_report(sk);
unlock_sock_fast(ssk, slowpath);net/mptcp/protocol.c +0
-0@@ -2193,8 +2231,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
copied +=bytes_read;net/mptcp/protocol.c +0
-1- if (skb_queue_empty(&sk->sk_receive_queue) &&
__mptcp_move_skbs(sk))net/mptcp/protocol.c +3
-1-continue ; +if (skb_queue_empty (&sk->sk_receive_queue)) { +__sk_flush_backlog (sk); + if (!skb_queue_empty(&sk->sk_receive_queue)||
net/mptcp/protocol.c +3
-0+ __mptcp_move_skbs(sk)) +continue ; + }
/* only the MPTCP socket status is relevant here. The exit
* conditions mirror closelytcp_recvmsg()net/mptcp/protocol.c +0
-0@@ -2542,7 +2584,6 @@ static void __mptcp_close_subflow(struct sock *sk)
Quoted 4 lines
mptcp_close_ssk(sk, ssk, subflow); }
-
Deleting this blank line is unrelated to the current patch. Let's make the change later when we modify the __mptcp_close_subflow function together.
I need to spend some more time understanding and testing patches 10-12.
Thanks,
-Geliang
Quoted 82 lines
}
static boolmptcp_close_tout_expired(const struct sock *sk)net/mptcp/protocol.c +0
-0@@ -3126,6 +3167,13 @@ bool __mptcp_close(struct sock *sk, long timeout) pr_debug("msk=%p state=%d\n", sk, sk->sk_state); mptcp_pm_connection_closed(msk);net/mptcp/protocol.c +1
-0+/* process the backlog; note that it never destroies the msk */
net/mptcp/protocol.c +6
-0+local_bh_disable (); +bh_lock_sock (sk); +__release_sock (sk); +bh_unlock_sock (sk); +local_bh_enable (); +if (
sk->sk_state==TCP_CLOSE) {
__mptcp_destroy_sock(sk);
do_cancel_work= true;net/mptcp/protocol.c +0
-0@@ -3429,8 +3477,7 @@ void __mptcp_check_push(struct sock *sk, struct sock *ssk)
#defineMPTCP_FLAGS_PROCESS_CTX_NEED(BIT(MPTCP_PUSH_PENDING)| \
BIT(MPTCP_RETRANSMIT)| \net/mptcp/protocol.c +1
-2- BIT(MPTCP_FLUSH_JOIN_LIST) | \ - BIT(MPTCP_DEQUEUE)) + BIT(MPTCP_FLUSH_JOIN_LIST))
/* processes deferred events and flush wmem */
static voidmptcp_release_cb(struct sock *sk)net/mptcp/protocol.c +0
-5@@ -3464,11 +3511,6 @@ static void mptcp_release_cb(struct sock *sk) __mptcp_push_pending(sk, 0); if (flags & BIT(MPTCP_RETRANSMIT)) __mptcp_retrans(sk); -if ((flags &BIT (MPTCP_DEQUEUE )) && __mptcp_move_skbs(sk)) { -/* notify ack seq update */ -mptcp_cleanup_rbuf (msk,0 ); - sk->sk_data_ready (sk); - }
cond_resched();
spin_lock_bh(&sk->sk_lock.slock);net/mptcp/protocol.c +0
-0@@ -3704,8 +3746,6 @@ static int mptcp_ioctl(struct sock *sk, int cmd, int *karg) return -EINVAL;
lock_sock(sk);net/mptcp/protocol.c +0
-2-if (__mptcp_move_skbs (sk)) -mptcp_cleanup_rbuf (msk,0 );*karg =
mptcp_inq_hint(sk);
release_sock(sk);
break;net/mptcp/protocol.c +1
-0@@ -3817,6 +3857,7 @@ static struct proto mptcp_prot = { .sendmsg = mptcp_sendmsg, .ioctl = mptcp_ioctl, .recvmsg = mptcp_recvmsg, + .backlog_rcv = mptcp_move_skb, .release_cb = mptcp_release_cb, .hash = mptcp_hash, .unhash = mptcp_unhash,net/mptcp/protocol.h +0
-1@@ -124,7 +124,6 @@ #define MPTCP_FLUSH_JOIN_LIST 5 #define MPTCP_SYNC_STATE 6 #define MPTCP_SYNC_SNDBUF 7 -#define MPTCP_DEQUEUE 8
structmptcp_skb_cb{
u64map_seq;net/mptcp/protocol.h +0
-0@@ -408,6 +407,7 @@ static inline int mptcp_space_from_win(const struct sock *sk, int win) static inline int __mptcp_space(const struct sock *sk) {return mptcp_win_from_space(sk,
READ_ONCE(sk->sk_rcvbuf)-net/mptcp/protocol.h +1
-0+ READ_ONCE(sk->sk_backlog.len) -
sk_rmem_alloc_get(sk)); }
Geliang Tang
reviewerHi Paolo, Matt,
Quoted 36 lines · Matthieu Baerts
Hi Paolo,
Quoted 26 lines · Paolo Abeni
This series includes several changes to the MPTCP RX path.
The main goals are improving the RX performances _and_ increase the long term maintainability.
Some changes reflects recent (or not so) improvements introduced in the
TCP stack: patch 1, 2 and 3 are the MPTCP counter part of skb deferral
free and auto-tuning improvements.Note that patch 3 could possibly fix issues/574, and overall such patch
should protect from similar issues to arise in the future.All the others patches are aimed at introducing the socket backlog usage
to process the packets received by the subflows while the msk socket is
owned. That (almost completely) replace the processing currently happening in themptcp_release_cb().The actual job is done in patch 10, while the others are cleanups needed
to make the change tidy and more follow-up cleanups.Quoted 6 lines
Sharing earlier with known issues (at least on fallback socket) to raise
awareness about this upcoming work.
---
v2 -> v3:
- (hopefully) addressed CI failures
Quoted 3 lines
Sadly, the CI doesn't seem that happy, but only in debug mode:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17863851247
I just sent two fixes for these CI failures to our mail list. It works on my end. Still waiting for the CI results - hope everything goes well.
Thanks,
-Geliang
Quoted 7 lines
If it is easier for you, I can already apply (and send to netdev?) some
of these patches? e.g. 1-7/12?Cheers,
Matt
Geliang Tang
reviewerHi Paolo, Matt,
Quoted 36 lines · Matthieu Baerts
Hi Paolo,
Quoted 26 lines · Paolo Abeni
This series includes several changes to the MPTCP RX path.
The main goals are improving the RX performances _and_ increase the long term maintainability.
Some changes reflects recent (or not so) improvements introduced in the
TCP stack: patch 1, 2 and 3 are the MPTCP counter part of skb deferral
free and auto-tuning improvements.Note that patch 3 could possibly fix issues/574, and overall such patch
should protect from similar issues to arise in the future.All the others patches are aimed at introducing the socket backlog usage
to process the packets received by the subflows while the msk socket is
owned. That (almost completely) replace the processing currently happening in themptcp_release_cb().The actual job is done in patch 10, while the others are cleanups needed
to make the change tidy and more follow-up cleanups.Quoted 6 lines
Sharing earlier with known issues (at least on fallback socket) to raise
awareness about this upcoming work.
---
v2 -> v3:
- (hopefully) addressed CI failures
Quoted 3 lines
Sadly, the CI doesn't seem that happy, but only in debug mode:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17863851247
I just sent two fixes for these CI failures to our mail list. It works on my end. Still waiting for the CI results - hope everything goes well.
Thanks,
-Geliang
Quoted 7 lines
If it is easier for you, I can already apply (and send to netdev?) some
of these patches? e.g. 1-7/12?Cheers,
Matt
Geliang Tang
reviewerRe: [MPTCP next v3 04/12] mptcp: introduce the mptcp_init_skb helper.
In reply to Geliang TangQuoted 129 lines · Geliang Tang
Hi Paolo,
Thank you for the v3. All tests pass on my end, including my "implement
mptcpread_sockv11" test case.I have a few minor cleanup comments to make the patch clean. There is no need to send a v4 or block the merging of this series. Matt can make
the changes when he merges it, or I can send some squash-to patches to
address these after merging. Either approach would be fine.Quoted 33 lines · Paolo Abeni
Factor out all the skb initialization step in a new helper and use it. Note that this change moves the MPTCP CB initialization
earlier: we can do such step as soon as the skb leaves the subflow socket receive queues.Reviewed-by Matthieu Baerts (NGI0) <[email protected]>Signed-off-by Paolo Abeni <[email protected]>---
v1 -> v2:
- drop subflow argument frommptcp_init_skb()
- change msk args to sock arg in__mptcp_move_skb()
---
net/mptcp/protocol.c | 46 ++++++++++++++++++++++++---------------- --
--1 file changed, 25 insertions(+), 21 deletions(-)net/mptcp/protocol.c +0
-0@@ -326,27 +326,11 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) mptcp_rcvbuf_grow(sk); }
-static bool __mptcp_move_skb(structmptcp_sock*msk, struct sock *ssk,net/mptcp/protocol.c +0
-1- struct sk_buff *skb, unsigned intoffset,
net/mptcp/protocol.c +2
-1- size_t copy_len) +static void mptcp_init_skb (struct sock *ssk, + struct sk_buff *skb, int offset, intQuoted 1 line
copy_len)nit:
static void
mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset, int copy_len)is better.
Quoted 22 lines
{
net/mptcp/protocol.c +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +0
-12-struct sock *sk = (struct sock *)msk; -struct sk_buff *tail; -bool has_rxtstamp; - -__skb_unlink (skb, &ssk->sk_receive_queue); - -skb_ext_reset (skb); -skb_orphan (skb); - -/* try to fetch required memory from subflow */ -if (!sk_rmem_schedule (sk, skb, skb->truesize)) { - MPTCP_INC_STATS(sock_net(sk),
MPTCP_MIB_RCVPRUNED);net/mptcp/protocol.c +1
-4- goto drop; - } - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; + const struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) · line 333
Quoted 1 line
net/mptcp/protocol.c +1
-0+bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;nit, how about keeping it as the original code to make this patch smaller:
(quoted diff) +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +0
-3-bool has_rxtstamp; - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;Reviewed-by Geliang Tang <[email protected]>Tested-by Geliang Tang <[email protected]>Thanks,
-GeliangQuoted 34 lines
/* the skbmap_seqaccounts for the skb offset:
*mptcp_subflow_get_mapped_dsn()is based on the currenttp->copied_seqnet/mptcp/protocol.c +0
-0@@ -358,6 +342,24 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk, MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp; MPTCP_SKB_CB(skb)->cant_coalesce = 0;net/mptcp/protocol.c +9
-0+__skb_unlink (skb, &ssk->sk_receive_queue); + +skb_ext_reset (skb); +skb_dst_drop (skb); +} + +static bool __mptcp_move_skb (struct sock *sk,struct sk_buff *skb) +{ + u64 copy_len = MPTCP_SKB_CB(skb)->end_seq -MPTCP_SKB_CB(skb)->map_seq;
net/mptcp/protocol.c +6
-0+struct mptcp_sock *msk =mptcp_sk (sk); +struct sk_buff *tail; + +/* try to fetch required memory from subflow */ +if (!sk_rmem_schedule (sk, skb, skb->truesize)) { + MPTCP_INC_STATS(sock_net(sk),
MPTCP_MIB_RCVPRUNED);net/mptcp/protocol.c +3
-0+ goto drop; + } +if (MPTCP_SKB_CB(skb)->map_seq ==
msk->ack_seq) { /* in sequence */msk->bytes_received+=copy_len;net/mptcp/protocol.c +0
-0@@ -678,7 +680,9 @@ static bool__mptcp_move_skbs_from_subflow(struct
Quoted 8 lines
net/mptcp/protocol.c static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, · line 684
Quoted 8 lines
mptcp_sock*msk,
if (offset <skb->len) {size_tlen =skb->len- offset;net/mptcp/protocol.c +0
-1- ret = __mptcp_move_skb(msk, ssk, skb,offset, len) || ret;
net/mptcp/protocol.c +2
-0+mptcp_init_skb (ssk, skb, offset, len); +skb_orphan (skb);
One more small request: could you also put skb_orphan(skb); into mptcp_init_skb, placing it on the last line, and then replace it in patch 12.
Thanks,
-Geliang
Quoted 4 lines
Quoted 4 lines
net/mptcp/protocol.c +1
-0+ ret =__mptcp_move_skb (sk, skb) || ret;seq += len;
if (unlikely(map_remaining < len)) {
Re: [MPTCP next v3 10/12] mptcp: leverage the sk backlog for RX packet processing.
In reply to Geliang TangQuoted 234 lines · Geliang Tang
Quoted 223 lines · Paolo Abeni
This streamline the RX path implementation and improves the RX performances by reducing the subflow-level locking and the amount of
work done under the msk socket lock; the implementation mirror closely
the TCP backlog processing.Note that MPTCP needs now to traverse the existing subflow looking for
data that was left there due to the msk receive buffer full, only after
that recvmsg completely empties the receive queue.Signed-off-by Paolo Abeni <[email protected]>---
net/mptcp/protocol.c | 103 ++++++++++++++++++++++++++++++--------- --
--
net/mptcp/protocol.h | 2 +-2 files changed, 73 insertions(+), 32 deletions(-)net/mptcp/protocol.c +0
-0@@ -360,6 +360,27 @@ static void mptcp_init_skb(struct sock *ssk, skb_dst_drop(skb); }net/mptcp/protocol.c +8
-0+static void __mptcp_add_backlog(struct sock *sk, struct sock *ssk, + struct sk_buff *skb) +{ + struct sk_buff *tail = sk->sk_backlog.tail; + bool fragstolen; + int delta; + + if (tail && MPTCP_SKB_CB(skb)->map_seq ==MPTCP_SKB_CB(tail)->end_seq) {
net/mptcp/protocol.c +1
-0+ delta = __mptcp_try_coalesce(sk, tail, skb,&fragstolen);
net/mptcp/protocol.c +8
-0+if (delta) { + sk->sk_backlog.len += delta; +kfree_skb_partial (skb, fragstolen); +return ; + } + } + +/* mptcp checks the limit before adding the skb to the backlog */
net/mptcp/protocol.c +4
-0+__sk_add_backlog (sk, skb); + sk->sk_backlog.len += skb->truesize; +} +static bool
__mptcp_move_skb(struct sock *sk, struct sk_buff *skb){
u64copy_len= MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;net/mptcp/protocol.c +0
-0@@ -648,7 +669,7 @@ static void mptcp_dss_corruption(struct mptcp_sock *msk, struct sock *ssk) }
static bool __mptcp_move_skbs_from_subflow(structmptcp_sock*msk,net/mptcp/protocol.c +1
-1- struct sock *ssk) + struct sock *ssk, bool
own_msk)
{
structmptcp_subflow_context*subflow =mptcp_subflow_ctx(ssk);
struct sock *sk = (struct sock *)msk;net/mptcp/protocol.c +1
-0@@ -659,12 +680,13 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, pr_debug("msk=%p ssk=%p\n", msk, ssk); tp = tcp_sk(ssk); do { + int mem = own_msk ? sk_rmem_alloc_get(sk) : sk- > sk_backlog.len; u32 map_remaining, offset; u32 seq = tp->copied_seq; struct sk_buff *skb; bool fin;net/mptcp/protocol.c +1
-1-if (sk_rmem_alloc_get (sk) > sk->sk_rcvbuf) +if (mem >READ_ONCE (sk->sk_rcvbuf))break;
/* try to move as much data as available */net/mptcp/protocol.c +0
-0@@ -694,7 +716,11 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
mptcp_init_skb(ssk, skb, offset, len);skb_orphan(skb);net/mptcp/protocol.c +5
-1- ret =__mptcp_move_skb (sk, skb) || ret; + +if (own_msk) + ret |=__mptcp_move_skb (sk, skb); +else +__mptcp_add_backlog (sk, ssk, skb);seq += len;
if (unlikely(map_remaining < len)) {net/mptcp/protocol.c +0
-0@@ -715,7 +741,7 @@ static bool__mptcp_move_skbs_from_subflow(struct
mptcp_sock*msk,
} while (more_data_avail);net/mptcp/protocol.c +1
-1-if (ret) +if (ret && own_msk)
msk->last_data_recv=tcp_jiffies32; return ret;
}net/mptcp/protocol.c +0
-0@@ -813,7 +839,7 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk) struct sock *sk = (struct sock *)msk; bool moved;net/mptcp/protocol.c +1
-1- moved =__mptcp_move_skbs_from_subflow (msk, ssk); + moved =__mptcp_move_skbs_from_subflow (msk, ssk, true);
__mptcp_ofo_queue(msk);
if (unlikely(ssk->sk_err))__mptcp_subflow_error_report(sk, ssk);net/mptcp/protocol.c +0
-0@@ -828,18 +854,10 @@ static bool move_skbs_to_msk(struct
mptcp_sock
*msk, struct sock *ssk)
return moved;
}net/mptcp/protocol.c +0
-9-static void __mptcp_data_ready (struct sock *sk,struct sock *ssk) -{ -struct mptcp_sock *msk =mptcp_sk (sk); - -/* Wake-up the reader only for in-sequence data */ -if (move_skbs_to_msk (msk, ssk) &&mptcp_epollin_ready (sk)) - sk->sk_data_ready (sk); -} -void
mptcp_data_ready(struct sock *sk, struct sock *ssk){
structmptcp_subflow_context*subflow =mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +1
-0+struct mptcp_sock *msk =mptcp_sk (sk);
/* The peer can send data while we are shutting down this
* subflow at msk destruction time, but we must avoid enqueuingnet/mptcp/protocol.c +0
-0@@ -849,13 +867,33 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk) return;
mptcp_data_lock(sk);net/mptcp/protocol.c +3
-4-if (!sock_owned_by_user (sk)) -__mptcp_data_ready (sk, ssk); -else -__set_bit (MPTCP_DEQUEUE , &mptcp_sk (sk)->cb_flags); +if (!sock_owned_by_user (sk)) { +/* Wake-up the reader only for in-sequence data */ + if (move_skbs_to_msk(msk, ssk) &&
mptcp_epollin_ready(sk))net/mptcp/protocol.c +5
-0+ sk->sk_data_ready (sk); + }else { +__mptcp_move_skbs_from_subflow (msk, ssk, false); +if (unlikely (ssk->sk_err)) + __set_bit(MPTCP_ERROR_REPORT, &msk-Quoted 1 line
cb_flags);net/mptcp/protocol.c +1
-0+ }
mptcp_data_unlock(sk);
}net/mptcp/protocol.c +15
-0+static int mptcp_move_skb (struct sock *sk,struct sk_buff *skb) +{ +struct mptcp_sock *msk =mptcp_sk (sk); + +if (__mptcp_move_skb (sk, skb)) { + msk->last_data_recv = tcp_jiffies32; +__mptcp_ofo_queue (msk); +/* notify ack seq update */ +mptcp_cleanup_rbuf (msk,0 ); +mptcp_check_data_fin (sk); + sk->sk_data_ready (sk); + } +return 0 ; +} +static void mptcp_subflow_joined(struct
mptcp_sock*msk, struct sock
*ssk)
{
mptcp_subflow_ctx(ssk)->map_seq =READ_ONCE(msk->ack_seq);net/mptcp/protocol.c +0
-0@@ -2117,7 +2155,7 @@ static bool __mptcp_move_skbs(struct sock *sk)
ssk =mptcp_subflow_tcp_sock(subflow); slowpath =lock_sock_fast(ssk);net/mptcp/protocol.c +0
-1- ret = __mptcp_move_skbs_from_subflow(msk, ssk) ||ret;
net/mptcp/protocol.c +1
-0+ ret = __mptcp_move_skbs_from_subflow(msk, ssk,true)
Quoted 1 line
Quoted 1 line
ret;
if (
unlikely(ssk->sk_err))
__mptcp_error_report(sk);
unlock_sock_fast(ssk, slowpath);net/mptcp/protocol.c +0
-0@@ -2193,8 +2231,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
copied +=bytes_read;net/mptcp/protocol.c +0
-1- if (skb_queue_empty(&sk->sk_receive_queue) &&
__mptcp_move_skbs(sk))net/mptcp/protocol.c +3
-1-continue ; + if (skb_queue_empty(&sk->sk_receive_queue)) { + __sk_flush_backlog(sk); + if (!skb_queue_empty(&sk-Quoted 2 lines
sk_receive_queue)Quoted 1 line
net/mptcp/protocol.c +3
-0+ __mptcp_move_skbs(sk)) +continue ; + }
/* only the MPTCP socket status is relevant here. The exit
* conditions mirror closelytcp_recvmsg()net/mptcp/protocol.c +0
-0@@ -2542,7 +2584,6 @@ static void __mptcp_close_subflow(struct sock *sk)Quoted 4 lines
mptcp_close_ssk(sk, ssk, subflow); }
-Deleting this blank line is unrelated to the current patch. Let's make
the change later when we modify the__mptcp_close_subflowfunction together.
Quoted 2 lines
I need to spend some more time understanding and testing patches 10- 12.
Please delete the sentence in the subject of this patch to maintain consistency with the other patches in the series.
Thanks,
-Geliang
Quoted 91 lines
Thanks,
-GeliangQuoted 87 lines
}
static boolmptcp_close_tout_expired(const struct sock *sk)net/mptcp/protocol.c +0
-0@@ -3126,6 +3167,13 @@ bool __mptcp_close(struct sock *sk, long timeout) pr_debug("msk=%p state=%d\n", sk, sk->sk_state); mptcp_pm_connection_closed(msk);net/mptcp/protocol.c +1
-0+/* process the backlog; note that it never destroies the msk
*/net/mptcp/protocol.c +6
-0+local_bh_disable (); +bh_lock_sock (sk); +__release_sock (sk); +bh_unlock_sock (sk); +local_bh_enable (); +if (
sk->sk_state==TCP_CLOSE) {
__mptcp_destroy_sock(sk);
do_cancel_work= true;net/mptcp/protocol.c +0
-0@@ -3429,8 +3477,7 @@ void __mptcp_check_push(struct sock *sk,struct
sock *ssk)
#defineMPTCP_FLAGS_PROCESS_CTX_NEED(BIT(MPTCP_PUSH_PENDING)| \
BIT(MPTCP_RETRANSMIT)| \net/mptcp/protocol.c +0
-1- BIT(MPTCP_FLUSH_JOIN_LIST) |\
net/mptcp/protocol.c +1
-1- BIT(MPTCP_DEQUEUE)) + BIT(MPTCP_FLUSH_JOIN_LIST))
/* processes deferred events and flush wmem */
static voidmptcp_release_cb(struct sock *sk)net/mptcp/protocol.c +0
-5@@ -3464,11 +3511,6 @@ static void mptcp_release_cb(struct sock *sk) __mptcp_push_pending(sk, 0); if (flags & BIT(MPTCP_RETRANSMIT)) __mptcp_retrans(sk); -if ((flags &BIT (MPTCP_DEQUEUE )) && __mptcp_move_skbs(sk)) { -/* notify ack seq update */ -mptcp_cleanup_rbuf (msk,0 ); - sk->sk_data_ready (sk); - }
cond_resched();
spin_lock_bh(&sk->sk_lock.slock);net/mptcp/protocol.c +0
-0@@ -3704,8 +3746,6 @@ static int mptcp_ioctl(struct sock *sk, int cmd, int *karg) return -EINVAL;
lock_sock(sk);net/mptcp/protocol.c +0
-2-if (__mptcp_move_skbs (sk)) -mptcp_cleanup_rbuf (msk,0 );*karg =
mptcp_inq_hint(sk);
release_sock(sk);
break;net/mptcp/protocol.c +1
-0@@ -3817,6 +3857,7 @@ static struct proto mptcp_prot = { .sendmsg = mptcp_sendmsg, .ioctl = mptcp_ioctl, .recvmsg = mptcp_recvmsg, + .backlog_rcv = mptcp_move_skb, .release_cb = mptcp_release_cb, .hash = mptcp_hash, .unhash = mptcp_unhash,net/mptcp/protocol.h +0
-1@@ -124,7 +124,6 @@ #define MPTCP_FLUSH_JOIN_LIST 5 #define MPTCP_SYNC_STATE 6 #define MPTCP_SYNC_SNDBUF 7 -#define MPTCP_DEQUEUE 8
structmptcp_skb_cb{
u64map_seq;net/mptcp/protocol.h +0
-0@@ -408,6 +407,7 @@ static inline int mptcp_space_from_win(const struct sock *sk, int win) static inline int __mptcp_space(const struct sock *sk) {return mptcp_win_from_space(sk,
READ_ONCE(sk->sk_rcvbuf)-net/mptcp/protocol.h +1
-1+ READ_ONCE(sk->sk_backlog.len) -
sk_rmem_alloc_get(sk)); }
Re: [MPTCP next v3 11/12] mptcp: prevernt __mptcp_move_skbs() interfering with the fastpath
In reply to Paolo AbeniQuoted 10 lines · Paolo Abeni
skbs will be left waiting in the subflow only in exceptional cases, we want to avoid messing with the fast path by unintentionally processing in
__mptcp_move_skbs()packets landed into the subflows after the last check.Use a separate flag to mark delayed skbs and only process subflow with such flag set. Also add new mibs to track the exceptional events.
Signed-off-by Paolo Abeni <[email protected]>
LGTM!
Thanks,
-Geliang
Quoted 150 lines
---
v1 -> v2:
- rebased
---
net/mptcp/mib.c | 2 ++
net/mptcp/mib.h | 4 ++++
net/mptcp/protocol.c | 40 ++++++++++++----------------------------net/mptcp/protocol.h| 1 +4 files changed, 19 insertions(+), 28 deletions(-)net/mptcp/mib.c +2
-0@@ -85,6 +85,8 @@ static const struct snmp_mib mptcp_snmp_list[] = { SNMP_MIB_ITEM("DssFallback", MPTCP_MIB_DSSFALLBACK), SNMP_MIB_ITEM("SimultConnectFallback",MPTCP_MIB_SIMULTCONNFALLBACK ), SNMP_MIB_ITEM("FallbackFailed", MPTCP_MIB_FALLBACKFAILED), +SNMP_MIB_ITEM ("RcvDelayed" ,MPTCP_MIB_RCVDELAYED ), + SNMP_MIB_ITEM("DelayedProcess", MPTCP_MIB_DELAYED_PROCESS), };
/*mptcp_mib_alloc- allocate percpu mib countersnet/mptcp/mib.h +0
-0@@ -88,6 +88,10 @@ enum linux_mptcp_mib_field {
MPTCP_MIB_DSSFALLBACK, /* Bad or missing DSS */
MPTCP_MIB_SIMULTCONNFALLBACK, /* Simultaneous connect */
MPTCP_MIB_FALLBACKFAILED, /* Can't fallback due to msk
status */net/mptcp/mib.h +1
-0+ MPTCP_MIB_RCVDELAYED, /* Data move from subflow isdelayed due to msk
net/mptcp/mib.h +3
-0+* receive buffer full +*/ + MPTCP_MIB_DELAYED_PROCESS, /* Delayed data moved inslowpath */
__MPTCP_MIB_MAX
};net/mptcp/protocol.c +0
-0@@ -681,13 +681,17 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, tp = tcp_sk(ssk); do {int mem =
own_msk?sk_rmem_alloc_get(sk): sk-Quoted 1 line
sk_backlog.len;
net/mptcp/protocol.c +1
-0+bool over_limit = mem >READ_ONCE (sk->sk_rcvbuf);u32
map_remaining, offset;
u32 seq =tp->copied_seq;
structsk_buff*skb;
bool fin;net/mptcp/protocol.c +3
-1-if (mem >READ_ONCE (sk->sk_rcvbuf)) +WRITE_ONCE (subflow->data_delayed, over_limit); +if (subflow->data_delayed) { + MPTCP_INC_STATS(sock_net(sk),
MPTCP_MIB_RCVDELAYED);
break;net/mptcp/protocol.c +1
-0+ }
/* try to move as much data as available */map_remaining=subflow->map_data_len-net/mptcp/protocol.c +0
-0@@ -2113,32 +2117,13 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied) msk->rcvq_space.time = mstamp; }net/mptcp/protocol.c +0
-14-static struct mptcp_subflow_context * -__mptcp_first_ready_from (struct mptcp_sock *msk, -struct mptcp_subflow_context *subflow) -{ -struct mptcp_subflow_context *start_subflow = subflow; - -while (!READ_ONCE (subflow->data_avail)) { - subflow =mptcp_next_subflow (msk, subflow); -if (subflow == start_subflow) -return NULL ; - } -return subflow; -} -static bool
__mptcp_move_skbs(struct sock *sk)
{
structmptcp_subflow_context*subflow;
structmptcp_sock*msk =mptcp_sk(sk);
bool ret = false;net/mptcp/protocol.c +0
-5-if (list_empty (&msk->conn_list)) -return false; - - subflow = list_first_entry(&msk->conn_list, - struct mptcp_subflow_context,node);
net/mptcp/protocol.c +1
-1-for (;;) { +mptcp_for_each_subflow (msk, subflow) {struct sock *ssk;
bool slowpath;net/mptcp/protocol.c +0
-0@@ -2149,23 +2134,22 @@ static bool __mptcp_move_skbs(struct sock *sk) if (sk_rmem_alloc_get(sk) > sk->sk_rcvbuf) break;net/mptcp/protocol.c +2
-3- subflow =__mptcp_first_ready_from (msk, subflow); -if (!subflow) -break ; +if (!subflow->data_delayed) +continue ;
ssk =mptcp_subflow_tcp_sock(subflow); slowpath =lock_sock_fast(ssk);net/mptcp/protocol.c +0
-1- ret =__mptcp_move_skbs_from_subflow (msk, ssk, true)|| ret;
net/mptcp/protocol.c +1
-0+ ret |= __mptcp_move_skbs_from_subflow(msk, ssk,true);
if (unlikely(ssk->sk_err))
__mptcp_error_report(sk);
unlock_sock_fast(ssk, slowpath);net/mptcp/protocol.c +0
-2- - subflow =mptcp_next_subflow (msk, subflow);}
__mptcp_ofo_queue(msk);net/mptcp/protocol.c +2
-1-if (ret) +if (ret) { + MPTCP_INC_STATS(sock_net(sk),
MPTCP_MIB_DELAYED_PROCESS);mptcp_check_data_fin((struct sock *)msk);net/mptcp/protocol.c +1
-0+ }return ret;
}net/mptcp/protocol.h +1
-0@@ -560,6 +560,7 @@ struct mptcp_subflow_context { u8 reset_transient:1; u8 reset_reason:4; u8 stale_count; +bool data_delayed;
u32subflow_id;
Re: [MPTCP next v3 12/12] mptcp: borrow forward memory from subflow
In reply to Paolo AbeniQuoted 8 lines · Paolo Abeni
In the MPTCP receive path, we release the subflow allocated fwd memory just to allocate it again shortly after for the msk.
That could increases the failures chances, especially during backlog processing, when other actions could consume the just released memory before the msk socket has a chance to do the rcv allocation.
Quoted 6 lines
Replace the
skb_orphan()call with an open-coded variant that explicitly borrows, with aPAGE_SIZEgranularity, the fwd memory from the subflow socket instead of releasing it. During backlog processing the borrowed memory is accounted atrelease_cbtime.Signed-off-by Paolo Abeni <[email protected]>
LGTM!
Thanks,
-Geliang
Quoted 98 lines
---
v1 -> v2:
- rebased
- explain whyskb_orphanis removed
---
net/mptcp/protocol.c | 27 +++++++++++++++++++++------net/mptcp/protocol.h| 1 +2 files changed, 22 insertions(+), 6 deletions(-)net/mptcp/protocol.c +0
-0@@ -338,11 +338,12 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) mptcp_rcvbuf_grow(sk); }net/mptcp/protocol.c +0
-2-static void mptcp_init_skb (struct sock *ssk, - struct sk_buff *skb, int offset, int
copy_len)net/mptcp/protocol.c +2
-0+static int mptcp_init_skb (struct sock *ssk, + struct sk_buff *skb, int offset, int
copy_len)
{
const structmptcp_subflow_context*subflow =mptcp_subflow_ctx(ssk);
boolhas_rxtstamp= TCP_SKB_CB(skb)->has_rxtstamp;net/mptcp/protocol.c +1
-0+int borrowed;
/* the skbmap_seqaccounts for the skb offset:
*mptcp_subflow_get_mapped_dsn()is based on the currenttp->copied_seqnet/mptcp/protocol.c +0
-0@@ -358,6 +359,15 @@ static void mptcp_init_skb(struct sock *ssk,
skb_ext_reset(skb);
skb_dst_drop(skb);net/mptcp/protocol.c +2
-0+ +/* "borrow" the fwd memory from the subflow, instead of reclaiming it */
net/mptcp/protocol.c +4
-0+ skb->destructor =NULL ; + skb->sk =NULL ; +atomic_sub (skb->truesize, &ssk->sk_rmem_alloc); + borrowed = ssk->sk_forward_alloc -
sk_unused_reserved_mem(ssk);net/mptcp/protocol.c +3
-0+ borrowed &= ~(PAGE_SIZE -1 ); +sk_forward_alloc_add (ssk, skb->truesize - borrowed); +return borrowed;}
static void __mptcp_add_backlog(struct sock *sk, struct sock *ssk,net/mptcp/protocol.c +0
-0@@ -717,14 +727,17 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
if (offset <skb->len) {size_tlen =skb->len- offset;net/mptcp/protocol.c +1
-0+int bmem;net/mptcp/protocol.c +1
-2-mptcp_init_skb (ssk, skb, offset, len); -skb_orphan (skb); + bmem = mptcp_init_skb(ssk, skb, offset,len);
net/mptcp/protocol.c +2
-1-if (own_msk) +if (own_msk) { +sk_forward_alloc_add (sk, bmem);ret |=
__mptcp_move_skb(sk, skb);net/mptcp/protocol.c +2
-1-else + }else { + msk->borrowed_fwd_mem += bmem;
__mptcp_add_backlog(sk, ssk, skb);net/mptcp/protocol.c +1
-0+ }seq += len;
if (unlikely(map_remaining < len)) {net/mptcp/protocol.c +0
-0@@ -3514,6 +3527,8 @@ static void mptcp_release_cb(struct sock *sk)if (__test_and_clear_bit(MPTCP_SYNC_SNDBUF, &msk-
Quoted 1 line
cb_flags))
__mptcp_sync_sndbuf(sk);
}net/mptcp/protocol.c +2
-0+sk_forward_alloc_add (sk, msk->borrowed_fwd_mem); + msk->borrowed_fwd_mem =0 ;}
/*MP_JOINclient subflow must wait for 4th ack before sending any data:net/mptcp/protocol.h +1
-0@@ -298,6 +298,7 @@ struct mptcp_sock { u32 last_data_sent; u32 last_data_recv; u32 last_ack_recv; +int borrowed_fwd_mem; unsigned long timer_ival; u32 token; unsigned long flags;
Geliang Tang
reviewerRe: [MPTCP next v3 04/12] mptcp: introduce the mptcp_init_skb helper.
In reply to Geliang TangQuoted 139 lines · Geliang Tang
Quoted 138 lines · Geliang Tang
Hi Paolo,
Thank you for the v3. All tests pass on my end, including my "implement
mptcpread_sockv11" test case.I have a few minor cleanup comments to make the patch clean. There is
no need to send a v4 or block the merging of this series. Matt can make
the changes when he merges it, or I can send some squash-to patches to
address these after merging. Either approach would be fine.Quoted 34 lines · Paolo Abeni
Factor out all the skb initialization step in a new helper and use it. Note that this change moves the MPTCP CB initialization
earlier: we can do such step as soon as the skb leaves the subflow socket receive queues.Reviewed-by Matthieu Baerts (NGI0) <[email protected]>Signed-off-by Paolo Abeni <[email protected]>---
v1 -> v2:
- drop subflow argument frommptcp_init_skb()
- change msk args to sock arg in__mptcp_move_skb()
---
net/mptcp/protocol.c | 46 ++++++++++++++++++++++++-------------- --
--
--1 file changed, 25 insertions(+), 21 deletions(-)net/mptcp/protocol.c +0
-0@@ -326,27 +326,11 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) mptcp_rcvbuf_grow(sk); }
-static bool __mptcp_move_skb(structmptcp_sock*msk, struct sock *ssk,net/mptcp/protocol.c +0
-1- struct sk_buff *skb, unsigned intoffset,
net/mptcp/protocol.c +2
-1- size_t copy_len) +static void mptcp_init_skb (struct sock *ssk, + struct sk_buff *skb, int offset, intQuoted 1 line
copy_len)nit:
static void
mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset, int copy_len)is better.
Quoted 22 lines
{
net/mptcp/protocol.c +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +0
-12-struct sock *sk = (struct sock *)msk; -struct sk_buff *tail; -bool has_rxtstamp; - -__skb_unlink (skb, &ssk->sk_receive_queue); - -skb_ext_reset (skb); -skb_orphan (skb); - -/* try to fetch required memory from subflow */ -if (!sk_rmem_schedule (sk, skb, skb->truesize)) { - MPTCP_INC_STATS(sock_net(sk),
MPTCP_MIB_RCVPRUNED);net/mptcp/protocol.c +1
-4- goto drop; - } - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; + const struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) · line 333
Quoted 1 line
net/mptcp/protocol.c +1
-0+bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;nit, how about keeping it as the original code to make this patch smaller:
(quoted diff) +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +0
-3-bool has_rxtstamp; - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;Reviewed-by Geliang Tang <[email protected]>Tested-by Geliang Tang <[email protected]>Thanks,
-GeliangQuoted 41 lines
/* the skbmap_seqaccounts for the skb offset:
*mptcp_subflow_get_mapped_dsn()is based on the currenttp->copied_seqnet/mptcp/protocol.c +0
-0@@ -358,6 +342,24 @@ static bool __mptcp_move_skb(struct
mptcp_sock
*msk, struct sock *ssk, MPTCP_SKB_CB(skb)->has_rxtstamp =has_rxtstamp; MPTCP_SKB_CB(skb)->cant_coalesce = 0;net/mptcp/protocol.c +7
-0+__skb_unlink (skb, &ssk->sk_receive_queue); + +skb_ext_reset (skb); +skb_dst_drop (skb); +} + +static bool __mptcp_move_skb(struct sock *sk, struct sk_buff*skb)
net/mptcp/protocol.c +2
-0+{ + u64 copy_len = MPTCP_SKB_CB(skb)->end_seq -MPTCP_SKB_CB(skb)->map_seq;
net/mptcp/protocol.c +6
-0+struct mptcp_sock *msk =mptcp_sk (sk); +struct sk_buff *tail; + +/* try to fetch required memory from subflow */ +if (!sk_rmem_schedule (sk, skb, skb->truesize)) { + MPTCP_INC_STATS(sock_net(sk),
MPTCP_MIB_RCVPRUNED);net/mptcp/protocol.c +3
-0+ goto drop; + } +if (MPTCP_SKB_CB(skb)->map_seq ==
msk->ack_seq) { /* in sequence */msk->bytes_received+=copy_len;net/mptcp/protocol.c +0
-0@@ -678,7 +680,9 @@ static bool__mptcp_move_skbs_from_subflow(struct
mptcp_sock*msk,
if (offset <skb->len) {size_tlen =skb->len- offset;
Quoted 8 lines
Quoted 4 lines
net/mptcp/protocol.c static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, · line 684
Quoted 4 lines
net/mptcp/protocol.c +0
-1- ret = __mptcp_move_skb(msk, ssk, skb,offset, len) || ret;
net/mptcp/protocol.c +2
-0+mptcp_init_skb (ssk, skb, offset, len); +skb_orphan (skb);One more small request: could you also put
skb_orphan(skb); intomptcp_init_skb, placing it on the last line, and then replace it in patch 12.
And please delete the sentence in the subject of this patch too.
Thanks,
-Geliang
Quoted 8 lines
Thanks,
-GeliangQuoted 4 lines
Quoted 4 lines
net/mptcp/protocol.c +1
-0+ ret =__mptcp_move_skb (sk, skb) || ret;seq += len;
if (unlikely(map_remaining < len)) {
Geliang Tang
reviewerRe: [MPTCP next v3 09/12] mptcp: cleanup fallback dummy mapping generation.
In reply to Geliang TangQuoted 72 lines · Geliang Tang
Quoted 58 lines · Paolo Abeni
MPTCP currently access
ack_seqoutside the msk socket log scope to generate the dummy mapping for fallback socket. Soon we are going to introduce backlog usage and even for fallback socket theack_seqvalue will be significantly off outside of the msk socket lock scope.Avoid relying on
ack_seqfor dummy mapping generation, using instead
the subflow sequence number. Note that in case ofdisconnect()and (re)connect() we must ensure that any previous state is re-set.Signed-off-by Paolo Abeni <[email protected]>---
v2 -> v3:
- reordered before the backlog introduction to avoid transiently break the fallback
- explicitly resetack_seq
---
net/mptcp/protocol.c | 3 +++
net/mptcp/subflow.c | 8 +++++++-2 files changed, 10 insertions(+), 1 deletion(-)net/mptcp/protocol.c +0
-0@@ -3224,6 +3224,9 @@ static int mptcp_disconnect(struct sock *sk, int flags) msk->bytes_retrans = 0; msk->rcvspace_init = 0;net/mptcp/protocol.c +3
-0+/* for fallback's sake */ +WRITE_ONCE (msk->ack_seq,0 ); +
WRITE_ONCE(sk->sk_shutdown, 0);
sk_error_report(sk);
return 0;net/mptcp/subflow.c +0
-0@@ -491,6 +491,9 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,mptcp_crypto_key_sha(subflow->remote_key, NULL, &subflow-
Quoted 1 line
iasn);
subflow->iasn++;
net/mptcp/subflow.c +3
-0+/* for fallback's sake */ + subflow->map_seq = subflow->iasn; +
WRITE_ONCE(msk->remote_key, subflow->remote_key);WRITE_ONCE(msk->ack_seq, subflow->iasn);WRITE_ONCE(msk->can_ack, true);net/mptcp/subflow.c +0
-0@@ -1435,9 +1438,12 @@ static bool subflow_check_data_avail(struct sock *ssk)
skb =skb_peek(&ssk->sk_receive_queue);
subflow->map_valid= 1;net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1438
Quoted 1 line
net/mptcp/subflow.c +0
-1- subflow->map_seq =READ_ONCE (msk->ack_seq);nit:
How about replacing this line in place? I mean, do not move it to a later position:
net/mptcp/subflow.c +4
-0+ subflow->map_seq = __mptcp_expand_seq(subflow->map_seq, + subflow->iasn + + TCP_SKB_CB(skb)->seq - + subflow->ssn_offset -1);
Quoted 2 lines
Reviewed-by Geliang Tang <[email protected]>Tested-by Geliang Tang <[email protected]>
Please delete the sentence in the subject of this patch too.
Thanks,
-Geliang
Quoted 17 lines
Thanks,
-GeliangQuoted 13 lines
subflow->map_data_len=skb->len;subflow->map_subflow_seq= tcp_sk(ssk)->copied_seq -subflow->ssn_offset;net/mptcp/subflow.c +4
-2+ subflow->map_seq =__mptcp_expand_seq (subflow->map_seq, + subflow->iasn + + TCP_SKB_CB(skb)->seq - + subflow->ssn_offset -1);
WRITE_ONCE(subflow->data_avail, true);
return true;
}
Paolo Abeni
maintainerRe: [MPTCP next v3 04/12] mptcp: introduce the mptcp_init_skb helper.
In reply to Geliang TangQuoted 70 lines · Geliang Tang
Quoted 32 lines · Paolo Abeni
Factor out all the skb initialization step in a new helper and use it. Note that this change moves the MPTCP CB initialization
earlier: we can do such step as soon as the skb leaves the subflow socket receive queues.Reviewed-by Matthieu Baerts (NGI0) <[email protected]>Signed-off-by Paolo Abeni <[email protected]>---
v1 -> v2:
- drop subflow argument frommptcp_init_skb()
- change msk args to sock arg in__mptcp_move_skb()
---
net/mptcp/protocol.c | 46 ++++++++++++++++++++++++------------------ --1 file changed, 25 insertions(+), 21 deletions(-)net/mptcp/protocol.c +0
-0@@ -326,27 +326,11 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) mptcp_rcvbuf_grow(sk); }
-static bool __mptcp_move_skb(structmptcp_sock*msk, struct sock *ssk,net/mptcp/protocol.c +0
-1- struct sk_buff *skb, unsigned intoffset,
net/mptcp/protocol.c +2
-1- size_t copy_len) +static void mptcp_init_skb (struct sock *ssk, + struct sk_buff *skb, int offset, intQuoted 1 line
copy_len)nit:
static void mptcp_init_skb(struct sock *ssk, struct
sk_buff*skb,
int offset, intcopy_len)is better.
Quoted 21 lines
{
net/mptcp/protocol.c +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c +1
-16-struct sock *sk = (struct sock *)msk; -struct sk_buff *tail; -bool has_rxtstamp; - -__skb_unlink (skb, &ssk->sk_receive_queue); - -skb_ext_reset (skb); -skb_orphan (skb); - -/* try to fetch required memory from subflow */ -if (!sk_rmem_schedule (sk, skb, skb->truesize)) { -MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED ); - goto drop; - } - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; + const struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/protocol.c static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) · line 333
Quoted 1 line
net/mptcp/protocol.c +1
-0+bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;nit, how about keeping it as the original code to make this patch smaller:
(quoted diff) +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(ssk);
net/mptcp/protocol.c static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) · line 349
Quoted 3 lines
net/mptcp/protocol.c +0
-3-bool has_rxtstamp; - - has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;
I would like to keep the 'struct mptcp_subflow_context' constantness, helps GCC generating better code.
Quoted 3 lines
Reviewed-by Geliang Tang <[email protected]>Tested-by Geliang Tang <[email protected]>
Thanks,
Paolo
Paolo Abeni
maintainerQuoted 27 lines · Matthieu Baerts
Quoted 17 lines · Paolo Abeni
This series includes several changes to the MPTCP RX path.
The main goals are improving the RX performances _and_ increase the long term maintainability.
Some changes reflects recent (or not so) improvements introduced in the TCP stack: patch 1, 2 and 3 are the MPTCP counter part of skb deferral free and auto-tuning improvements.
Note that patch 3 could possibly fix issues/574, and overall such patch should protect from similar issues to arise in the future.
All the others patches are aimed at introducing the socket backlog usage to process the packets received by the subflows while the msk socket is owned. That (almost completely) replace the processing currently happening in the
mptcp_release_cb().Quoted 8 lines
The actual job is done in patch 10, while the others are cleanups needed to make the change tidy and more follow-up cleanups.
Sharing earlier with known issues (at least on fallback socket) to raise awareness about this upcoming work.
---
v2 -> v3:
- (hopefully) addressed CI failures
Quoted 6 lines
Sadly, the CI doesn't seem that happy, but only in debug mode:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17863851247
If it is easier for you, I can already apply (and send to netdev?) some of these patches? e.g. 1-7/12?
I did a bit more testing. AFAICS patch 10 introduces a few chances of additional failures (even on top of Geliang's patches) I *think* patch 1-7 and 12 are safe.
Thanks,
Paolo