refactor push pending
Subsystems (5)
v7 cover refactor push pending
v7:
- update delegate sending in patch 10
- rebase to export/20221011T063543.
- This series should be merged between the commit "mptcp: add get_subflow wrappers" and "bpf: Add bpf_mptcp_sched_ops", except the last squash-to patch.
v6:
- drop all msk->last_snd, add last_snd variable instead in patch 13
- fix lock_sock issue in patch 3
- merge squash-to patches
v5:
- address Mat's comments in v4.
v4:
- update __mptcp_subflow_push_pending as Mat suggested.
- add more patches from "BPF redundant scheduler" series.
v3:
- add a cleanup patch.
- remove msk->last_snd in mptcp_subflow_get_send().
- add the loop that calls the scheduler again in __mptcp_push_pending().
v2:
- add snd_burst check in dfrags loop as Mat suggested.
Refactor __mptcp_push_pending() and __mptcp_subflow_push_pending() to remove duplicate code and support redundant scheduler more easily in __mptcp_subflow_push_pending().
Geliang Tang (12):
Squash to "mptcp: add get_subflow wrappers"
mptcp: change 'first' as a parameter
mptcp: refactor push_pending logic
mptcp: drop last_snd of struct mptcp_sock
mptcp: simplify push_pending
mptcp: multi subflows push_pending
mptcp: use msk instead of mptcp_sk
mptcp: refactor subflow_push_pending logic
mptcp: simplify subflow_push_pending
mptcp: multi subflows subflow_push_pending
mptcp: multi subflows retrans support
Squash to "selftests/bpf: Add bpf_rr scheduler"
net/mptcp/pm.c | 9 +- net/mptcp/pm_netlink.c | 3 - net/mptcp/protocol.c | 283 ++++++++++-------- net/mptcp/protocol.h | 6 +- net/mptcp/sched.c | 61 ++-- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 - .../selftests/bpf/progs/mptcp_bpf_rr.c | 6 +- 7 files changed, 186 insertions(+), 183 deletions(-)
Signature · 1 line
2.35.3
PATCH v7 1/12 Squash to "mptcp: add get_subflow wrappers"
Please update the commit log:
'''
This patch defines two new wrappers mptcp_sched_get_send() and mptcp_sched_get_retrans(), invoke get_subflow() of msk->sched in them.
Set the subflow pointers array in struct mptcp_sched_data before invoking get_subflow(), then it can be used in get_subflow() in the BPF contexts.
Check the subflow scheduled flags to test which subflow or subflows are picked by the scheduler.
Move sock_owned_by_me() and the fallback check code from mptcp_subflow_get_send/retrans() into the wrappers. '''
--- net/mptcp/protocol.c | 8 +++--- net/mptcp/protocol.h | 4 +-- net/mptcp/sched.c | 61 +++++++++++++++++++++----------------------- 3 files changed, 35 insertions(+), 38 deletions(-)
net/mptcp/protocol.c +4 -4
@@ -1547,7 +1547,7 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)int ret =0 ; prev_ssk = ssk; - ssk =mptcp_sched_get_send (msk); + ssk =mptcp_subflow_get_send (msk);/* First check. If the ssk has changed since * the last round, release prev_ssk
@@ -1616,7 +1616,7 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk)* check for a different subflow usage only after * spooling the first chunk of data */ - xmit_ssk = first ? ssk :mptcp_sched_get_send (mptcp_sk (sk)); + xmit_ssk = first ? ssk :mptcp_subflow_get_send (mptcp_sk (sk));if (!xmit_ssk) goto out;if (xmit_ssk != ssk) {
@@ -2481,7 +2481,7 @@ static void __mptcp_retrans(struct sock *sk)mptcp_clean_una_wakeup (sk);/* first check ssk: need to kick "stale" logic */ - ssk =mptcp_sched_get_retrans (msk); + ssk =mptcp_subflow_get_retrans (msk); dfrag =mptcp_rtx_head (sk);if (!dfrag) {if (mptcp_data_fin_enabled (msk)) {
@@ -3199,7 +3199,7 @@ void __mptcp_check_push(struct sock *sk, struct sock *ssk)return ;if (!sock_owned_by_user (sk)) { -struct sock *xmit_ssk =mptcp_sched_get_send (mptcp_sk (sk)); +struct sock *xmit_ssk =mptcp_subflow_get_send (mptcp_sk (sk));if (xmit_ssk == ssk)__mptcp_subflow_push_pending (sk, ssk);
net/mptcp/protocol.h +2 -2
@@ -642,8 +642,8 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled);struct sock *mptcp_subflow_get_send (struct mptcp_sock *msk);struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk); -struct sock *mptcp_sched_get_send (struct mptcp_sock *msk); -struct sock *mptcp_sched_get_retrans (struct mptcp_sock *msk); +int mptcp_sched_get_send (struct mptcp_sock *msk); +int mptcp_sched_get_retrans (struct mptcp_sock *msk);static inline bool __tcp_can_send (const struct sock *ssk) {
net/mptcp/sched.c +29 -32
96 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v7 2/12 mptcp: change 'first' as a parameter
In reply to Geliang TangThe function mptcp_subflow_process_delegated() uses the input ssk first, while __mptcp_check_push() invokes the packet scheduler first.
So this patch adds a new parameter named 'first' for the function __mptcp_subflow_push_pending() to deal with these two cases separately.
With this change, the code that invokes the packet scheduler in the function __mptcp_check_push() can be removed, and replaced by invoking __mptcp_subflow_push_pending() directly.
--- net/mptcp/protocol.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
net/mptcp/protocol.c +7 -14
@@ -1593,7 +1593,8 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)__mptcp_check_send_data_fin (sk); } -static void __mptcp_subflow_push_pending (struct sock *sk,struct sock *ssk) +static void __mptcp_subflow_push_pending (struct sock *sk,struct sock *ssk, +bool first) {struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_sendmsg_info info = {
@@ -1602,7 +1603,6 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk)struct mptcp_data_frag *dfrag;struct sock *xmit_ssk;int len, copied =0 ; -bool first = true; info.flags =0 ;while ((dfrag =mptcp_send_head (sk))) {
@@ -1612,8 +1612,7 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk)while (len >0 ) {int ret =0 ; -/* the caller already invoked the packet scheduler, -* check for a different subflow usage only after +/* check for a different subflow usage only after * spooling the first chunk of data */ xmit_ssk = first ? ssk :mptcp_subflow_get_send (mptcp_sk (sk));
@@ -3198,16 +3197,10 @@ void __mptcp_check_push(struct sock *sk, struct sock *ssk)if (!mptcp_send_head (sk))return ; -if (!sock_owned_by_user (sk)) { -struct sock *xmit_ssk =mptcp_subflow_get_send (mptcp_sk (sk)); - -if (xmit_ssk == ssk) -__mptcp_subflow_push_pending (sk, ssk); -else if (xmit_ssk) -mptcp_subflow_delegate (mptcp_subflow_ctx (xmit_ssk),MPTCP_DELEGATE_SEND ); - }else { +if (!sock_owned_by_user (sk)) +__mptcp_subflow_push_pending (sk, ssk, false); +else __set_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->cb_flags); - } }#define MPTCP_FLAGS_PROCESS_CTX_NEED (BIT(MPTCP_PUSH_PENDING) | \
@@ -3298,7 +3291,7 @@ void mptcp_subflow_process_delegated(struct sock *ssk)if (test_bit (MPTCP_DELEGATE_SEND , &subflow->delegated_status)) {mptcp_data_lock (sk);if (!sock_owned_by_user (sk)) -__mptcp_subflow_push_pending (sk, ssk); +__mptcp_subflow_push_pending (sk, ssk, true);else __set_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->cb_flags);mptcp_data_unlock (sk);
Signature · 1 line
2.35.3
PATCH v7 3/12 mptcp: refactor push_pending logic
In reply to Geliang TangTo support redundant package schedulers more easily, this patch refactors __mptcp_push_pending() logic from:
For each dfrag:
While sends succeed:
Call the scheduler (selects subflow and msk->snd_burst) Update subflow locks (push/release/acquire as needed) Send the dfrag data with mptcp_sendmsg_frag() Update already_sent, snd_nxt, snd_burst
Update msk->first_pending
Push/release on final subflow
->
While the scheduler selects one subflow:
Lock the subflow
For each pending dfrag:
While sends succeed:
Send the dfrag data with mptcp_sendmsg_frag() Update already_sent, snd_nxt, snd_burst
Update msk->first_pending
Break if required by msk->snd_burst / etc
Push and release the subflow
This patch also moves the burst check conditions out of the function mptcp_subflow_get_send(), check them in __mptcp_push_pending() and __mptcp_subflow_push_pending() in the inner "for each pending dfrag" loop.
--- net/mptcp/protocol.c | 86 ++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 47 deletions(-)
net/mptcp/protocol.c +39 -47
@@ -1417,14 +1417,6 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)u64 linger_time;long tout =0 ; -/* re-use last subflow, if the burst allow that */ -if (msk->last_snd && msk->snd_burst >0 && -sk_stream_memory_free (msk->last_snd) && -mptcp_subflow_active (mptcp_subflow_ctx (msk->last_snd))) { -mptcp_set_timeout (sk); -return msk->last_snd; - } -/* pick the subflow with the lower wmem/wspace ratio */ for (i =0 ; i <SSK_MODE_MAX ; ++i) { send_info[i].ssk =NULL ;
@@ -1530,60 +1522,53 @@ void mptcp_check_and_set_pending(struct sock *sk)void __mptcp_push_pending (struct sock *sk,unsigned int flags) { -struct sock *prev_ssk =NULL , *ssk =NULL ;struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_sendmsg_info info = { .flags = flags, };bool do_check_data_fin = false;struct mptcp_data_frag *dfrag; +struct sock *ssk;int len; -while ((dfrag =mptcp_send_head (sk))) { - info.sent = dfrag->already_sent; - info.limit = dfrag->data_len; - len = dfrag->data_len - dfrag->already_sent; -while (len >0 ) { -int ret =0 ; - - prev_ssk = ssk; - ssk =mptcp_subflow_get_send (msk); - -/* First check. If the ssk has changed since -* the last round, release prev_ssk -*/ -if (ssk != prev_ssk && prev_ssk) -mptcp_push_release (prev_ssk, &info); -if (!ssk) - goto out; +again: +while (mptcp_send_head (sk) && (ssk =mptcp_subflow_get_send (msk))) { +lock_sock (ssk); -/* Need to lock the new subflow only if different -* from the previous one, otherwise we are still -* helding the relevant lock -*/ -if (ssk != prev_ssk) -lock_sock (ssk); +while ((dfrag =mptcp_send_head (sk))) { + info.sent = dfrag->already_sent; + info.limit = dfrag->data_len; + len = dfrag->data_len - dfrag->already_sent; +while (len >0 ) { +int ret =0 ; + + ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); +if (ret <=0 ) { +mptcp_push_release (ssk, &info); +if (ret == -EAGAIN ) + goto again; + goto out; + } + + do_check_data_fin = true; + info.sent += ret; + len -= ret; + +mptcp_update_post_push (msk, dfrag, ret); + } +WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); - ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); -if (ret <=0 ) { -if (ret == -EAGAIN ) -continue ; +if (msk->snd_burst <=0 || + !sk_stream_memory_free (ssk) || + !mptcp_subflow_active (mptcp_subflow_ctx (ssk))) {mptcp_push_release (ssk, &info); - goto out; + goto again; } - - do_check_data_fin = true; - info.sent += ret; - len -= ret; - -mptcp_update_post_push (msk, dfrag, ret); +mptcp_set_timeout (sk); } -WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); - } -/* at this point we held the socket lock for the last subflow we used */ -if (ssk)mptcp_push_release (ssk, &info); + } out:/* ensure the rtx timer is running */
@@ -1636,6 +1621,13 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk,mptcp_update_post_push (msk, dfrag, ret); }WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); + +if (msk->snd_burst <=0 || + !sk_stream_memory_free (ssk) || + !mptcp_subflow_active (mptcp_subflow_ctx (ssk))) { + goto out; + } +mptcp_set_timeout (sk); } out:
Signature · 1 line
2.35.3
PATCH v7 4/12 mptcp: drop last_snd of struct mptcp_sock
In reply to Geliang Tangmsk->last_snd is no longer used anymore, drop it as well as the macro MPTCP_RESET_SCHEDULER.
--- net/mptcp/pm.c | 9 +-------- net/mptcp/pm_netlink.c | 3 --- net/mptcp/protocol.c | 11 +---------- net/mptcp/protocol.h | 2 -- 4 files changed, 2 insertions(+), 23 deletions(-)
net/mptcp/pm.c +1 -8
@@ -282,15 +282,8 @@ void mptcp_pm_mp_prio_received(struct sock *ssk, u8 bkup)pr_debug ("subflow->backup=%d, bkup=%d\n" , subflow->backup, bkup); msk =mptcp_sk (sk); -if (subflow->backup != bkup) { +if (subflow->backup != bkup) subflow->backup = bkup; -mptcp_data_lock (sk); -if (!sock_owned_by_user (sk)) - msk->last_snd =NULL ; -else -__set_bit (MPTCP_RESET_SCHEDULER , &msk->cb_flags); -mptcp_data_unlock (sk); - }mptcp_event (MPTCP_EVENT_SUB_PRIORITY , msk, ssk,GFP_ATOMIC ); }
net/mptcp/pm_netlink.c +0 -3
@@ -475,9 +475,6 @@ static void __mptcp_pm_send_ack(struct mptcp_sock *msk, struct mptcp_subflow_con slow =lock_sock_fast (ssk);if (prio) { -if (subflow->backup != backup) - msk->last_snd =NULL ; - subflow->send_mp_prio =1 ; subflow->backup = backup; subflow->request_bkup = backup;
net/mptcp/protocol.c +1 -10
@@ -1469,16 +1469,13 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk) burst =min_t (int,MPTCP_SEND_BURST_SIZE ,mptcp_wnd_end (msk) - msk->snd_nxt); wmem =READ_ONCE (ssk->sk_wmem_queued); -if (!burst) { - msk->last_snd =NULL ; +if (!burst)return ssk; - } subflow =mptcp_subflow_ctx (ssk); subflow->avg_pacing_rate =div_u64 ((u64 )subflow->avg_pacing_rate * wmem +READ_ONCE (ssk->sk_pacing_rate) * burst, burst + wmem); - msk->last_snd = ssk; msk->snd_burst = burst;return ssk; }
@@ -2346,9 +2343,6 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, msk->first =NULL ; out: -if (ssk == msk->last_snd) - msk->last_snd =NULL ; -if (need_push)__mptcp_push_pending (sk,0 ); }
@@ -2981,7 +2975,6 @@ static int mptcp_disconnect(struct sock *sk, int flags)* subflow */ mptcp_destroy_common (msk,MPTCP_CF_FASTCLOSE ); - msk->last_snd =NULL ;WRITE_ONCE (msk->flags,0 ); msk->cb_flags =0 ; msk->push_pending =0 ;
@@ -3242,8 +3235,6 @@ static void mptcp_release_cb(struct sock *sk)__mptcp_set_connected (sk);if (__test_and_clear_bit (MPTCP_ERROR_REPORT , &msk->cb_flags))__mptcp_error_report (sk); -if (__test_and_clear_bit (MPTCP_RESET_SCHEDULER , &msk->cb_flags)) - msk->last_snd =NULL ; }__mptcp_update_rmem (sk);
net/mptcp/protocol.h +0 -2
@@ -124,7 +124,6 @@#define MPTCP_RETRANSMIT 4#define MPTCP_FLUSH_JOIN_LIST 5#define MPTCP_CONNECTED 6 -#define MPTCP_RESET_SCHEDULER 7static inline bool before64 (__u64 seq1,__u64 seq2) {
@@ -258,7 +257,6 @@ struct mptcp_sock {atomic64_t rcv_wnd_sent;u64 rcv_data_fin_seq;int rmem_fwd_alloc; -struct sock *last_snd;int snd_burst;int old_wspace;u64 recovery_snd_nxt;/* in recovery mode accept up to this seq;
Signature · 1 line
2.35.3
PATCH v7 5/12 mptcp: simplify push_pending
In reply to Geliang TangThis patch moves the duplicate code from __mptcp_push_pending() and __mptcp_subflow_push_pending() into a new helper function, named __subflow_push_pending(). And simplify __mptcp_push_pending() by invoking this helper.
--- net/mptcp/protocol.c | 95 +++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 41 deletions(-)
net/mptcp/protocol.c +54 -41
@@ -1480,12 +1480,6 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)return ssk; } -static void mptcp_push_release (struct sock *ssk,struct mptcp_sendmsg_info *info) -{ -tcp_push (ssk,0 , info->mss_now,tcp_sk (ssk)->nonagle, info->size_goal); -release_sock (ssk); -} -static void mptcp_update_post_push (struct mptcp_sock *msk,struct mptcp_data_frag *dfrag,u32 sent)
@@ -1517,61 +1511,80 @@ void mptcp_check_and_set_pending(struct sock *sk)mptcp_sk (sk)->push_pending |=BIT (MPTCP_PUSH_PENDING ); } +static int __subflow_push_pending (struct sock *sk,struct sock *ssk, +struct mptcp_sendmsg_info *info) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct mptcp_data_frag *dfrag; +int len, copied =0 , err =0 ; + +while ((dfrag =mptcp_send_head (sk))) { + info->sent = dfrag->already_sent; + info->limit = dfrag->data_len; + len = dfrag->data_len - dfrag->already_sent; +while (len >0 ) { +int ret =0 ; + + ret =mptcp_sendmsg_frag (sk, ssk, dfrag, info); +if (ret <=0 ) { + err = copied ? : ret; + goto out; + } + + info->sent += ret; + copied += ret; + len -= ret; + +mptcp_update_post_push (msk, dfrag, ret); + } +WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); + +if (msk->snd_burst <=0 || + !sk_stream_memory_free (ssk) || + !mptcp_subflow_active (mptcp_subflow_ctx (ssk))) { + err = copied ? : -EAGAIN ; + goto out; + } +mptcp_set_timeout (sk); + } + err = copied; + +out: +if (copied) { +tcp_push (ssk,0 , info->mss_now,tcp_sk (ssk)->nonagle, + info->size_goal); + } + +return err; +} +void __mptcp_push_pending (struct sock *sk,unsigned int flags) {struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_sendmsg_info info = { .flags = flags, }; -bool do_check_data_fin = false; -struct mptcp_data_frag *dfrag;struct sock *ssk; -int len; +int ret =0 ; again:while (mptcp_send_head (sk) && (ssk =mptcp_subflow_get_send (msk))) {lock_sock (ssk); + ret =__subflow_push_pending (sk, ssk, &info); +release_sock (ssk); -while ((dfrag =mptcp_send_head (sk))) { - info.sent = dfrag->already_sent; - info.limit = dfrag->data_len; - len = dfrag->data_len - dfrag->already_sent; -while (len >0 ) { -int ret =0 ; - - ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); -if (ret <=0 ) { -mptcp_push_release (ssk, &info); -if (ret == -EAGAIN ) - goto again; - goto out; - } - - do_check_data_fin = true; - info.sent += ret; - len -= ret; - -mptcp_update_post_push (msk, dfrag, ret); - } -WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); - -if (msk->snd_burst <=0 || - !sk_stream_memory_free (ssk) || - !mptcp_subflow_active (mptcp_subflow_ctx (ssk))) { -mptcp_push_release (ssk, &info); +if (ret <=0 ) { +if (ret == -EAGAIN ) goto again; - } -mptcp_set_timeout (sk); + goto out; } - -mptcp_push_release (ssk, &info); } out:/* ensure the rtx timer is running */ if (!mptcp_timer_pending (sk))mptcp_reset_timer (sk); -if (do_check_data_fin) +if (ret >0 )__mptcp_check_send_data_fin (sk); }
Signature · 1 line
2.35.3
PATCH v7 6/12 mptcp: multi subflows push_pending
In reply to Geliang TangThis patch adds the multiple subflows support for __mptcp_push_pending(). Use mptcp_sched_get_send() wrapper instead of mptcp_subflow_get_send() in it.
Check the subflow scheduled flags to test which subflow or subflows are picked by the scheduler, use them to send data.
--- net/mptcp/protocol.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
net/mptcp/protocol.c +20 -12
@@ -1561,22 +1561,30 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,void __mptcp_push_pending (struct sock *sk,unsigned int flags) {struct mptcp_sock *msk =mptcp_sk (sk); -struct mptcp_sendmsg_info info = { - .flags = flags, - }; -struct sock *ssk;int ret =0 ; again: -while (mptcp_send_head (sk) && (ssk =mptcp_subflow_get_send (msk))) { -lock_sock (ssk); - ret =__subflow_push_pending (sk, ssk, &info); -release_sock (ssk); +while (mptcp_send_head (sk) && !mptcp_sched_get_send (msk)) { +struct mptcp_subflow_context *subflow; +struct mptcp_sendmsg_info info = { + .flags = flags, + }; -if (ret <=0 ) { -if (ret == -EAGAIN ) - goto again; - goto out; +mptcp_for_each_subflow (msk, subflow) { +if (READ_ONCE (subflow->scheduled)) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); + +lock_sock (ssk); + ret =__subflow_push_pending (sk, ssk, &info); +release_sock (ssk); + +if (ret <=0 ) { +if (ret == -EAGAIN ) + goto again; + goto out; + } +mptcp_subflow_set_scheduled (subflow, false); + } } }
Signature · 1 line
2.35.3
PATCH v7 7/12 mptcp: use msk instead of mptcp_sk
In reply to Geliang TangUse msk instead of mptcp_sk(sk) in the functions where the variable "msk = mptcp_sk(sk)" has been defined.
--- net/mptcp/protocol.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/mptcp/protocol.c +5 -5
@@ -1618,7 +1618,7 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk,/* check for a different subflow usage only after * spooling the first chunk of data */ - xmit_ssk = first ? ssk :mptcp_subflow_get_send (mptcp_sk (sk)); + xmit_ssk = first ? ssk :mptcp_subflow_get_send (msk);if (!xmit_ssk) goto out;if (xmit_ssk != ssk) {
@@ -2251,7 +2251,7 @@ bool __mptcp_retransmit_pending_data(struct sock *sk)struct mptcp_data_frag *cur, *rtx_head;struct mptcp_sock *msk =mptcp_sk (sk); -if (__mptcp_check_fallback (mptcp_sk (sk))) +if (__mptcp_check_fallback (msk))return false;if (tcp_rtx_and_write_queues_empty (sk))
@@ -2930,7 +2930,7 @@ bool __mptcp_close(struct sock *sk, long timeout)sock_hold (sk);pr_debug ("msk=%p state=%d" , sk, sk->sk_state); -if (mptcp_sk (sk)->token) +if (msk->token)mptcp_event (MPTCP_EVENT_CLOSED , msk,NULL ,GFP_KERNEL );if (sk->sk_state ==TCP_CLOSE ) {
@@ -2989,8 +2989,8 @@ static int mptcp_disconnect(struct sock *sk, int flags)mptcp_stop_timer (sk);sk_stop_timer (sk, &sk->sk_timer); -if (mptcp_sk (sk)->token) -mptcp_event (MPTCP_EVENT_CLOSED ,mptcp_sk (sk),NULL ,GFP_KERNEL ); +if (msk->token) +mptcp_event (MPTCP_EVENT_CLOSED , msk,NULL ,GFP_KERNEL );/* msk->subflow is still intact, the following will not free the first * subflow
Signature · 1 line
2.35.3
PATCH v7 8/12 mptcp: refactor subflow_push_pending logic
In reply to Geliang TangThis patch refactors __mptcp_subflow_push_pending logic from:
For each dfrag:
While sends succeed: Call the scheduler (selects subflow and msk->snd_burst) Send the dfrag data with mptcp_subflow_delegate(), break Send the dfrag data with mptcp_sendmsg_frag() Update dfrag->already_sent, msk->snd_nxt, msk->snd_burst Update msk->first_pending
->
While first_pending isn't empty:
Call the scheduler (selects subflow and msk->snd_burst) Send the dfrag data with mptcp_subflow_delegate(), break Send the dfrag data with mptcp_sendmsg_frag()
For each pending dfrag:
While sends succeed:
Send the dfrag data with mptcp_sendmsg_frag() Update already_sent, snd_nxt, snd_burst
Update msk->first_pending
Break if required by msk->snd_burst / etc
--- net/mptcp/protocol.c | 66 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 32 deletions(-)
net/mptcp/protocol.c +34 -32
@@ -1608,44 +1608,46 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk,int len, copied =0 ; info.flags =0 ; -while ((dfrag =mptcp_send_head (sk))) { - info.sent = dfrag->already_sent; - info.limit = dfrag->data_len; - len = dfrag->data_len - dfrag->already_sent; -while (len >0 ) { -int ret =0 ; +while (mptcp_send_head (sk)) { +/* check for a different subflow usage only after +* spooling the first chunk of data +*/ + xmit_ssk = first ? ssk :mptcp_subflow_get_send (msk); +if (!xmit_ssk) + goto out; +if (xmit_ssk != ssk) { +mptcp_subflow_delegate (mptcp_subflow_ctx (xmit_ssk), +MPTCP_DELEGATE_SEND ); + goto out; + } -/* check for a different subflow usage only after -* spooling the first chunk of data -*/ - xmit_ssk = first ? ssk :mptcp_subflow_get_send (msk); -if (!xmit_ssk) - goto out; -if (xmit_ssk != ssk) { -mptcp_subflow_delegate (mptcp_subflow_ctx (xmit_ssk), -MPTCP_DELEGATE_SEND ); - goto out; - } +while ((dfrag =mptcp_send_head (sk))) { + info.sent = dfrag->already_sent; + info.limit = dfrag->data_len; + len = dfrag->data_len - dfrag->already_sent; +while (len >0 ) { +int ret =0 ; - ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); -if (ret <=0 ) - goto out; + ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); +if (ret <=0 ) + goto out; - info.sent += ret; - copied += ret; - len -= ret; - first = false; + info.sent += ret; + copied += ret; + len -= ret; + first = false; -mptcp_update_post_push (msk, dfrag, ret); - } -WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); +mptcp_update_post_push (msk, dfrag, ret); + } +WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); -if (msk->snd_burst <=0 || - !sk_stream_memory_free (ssk) || - !mptcp_subflow_active (mptcp_subflow_ctx (ssk))) { - goto out; +if (msk->snd_burst <=0 || + !sk_stream_memory_free (ssk) || + !mptcp_subflow_active (mptcp_subflow_ctx (ssk))) { + goto out; + } +mptcp_set_timeout (sk); } -mptcp_set_timeout (sk); } out:
Signature · 1 line
2.35.3
PATCH v7 9/12 mptcp: simplify subflow_push_pending
In reply to Geliang TangThis patch simplifies __mptcp_subflow_push_pending() by invoking __subflow_push_pending() helper.
--- net/mptcp/protocol.c | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-)
net/mptcp/protocol.c +8 -31
@@ -1603,11 +1603,11 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk,struct mptcp_sendmsg_info info = { .data_lock_held = true, }; -struct mptcp_data_frag *dfrag;struct sock *xmit_ssk; -int len, copied =0 ; +int ret =0 ; info.flags =0 ; +again:while (mptcp_send_head (sk)) {/* check for a different subflow usage only after * spooling the first chunk of data
@@ -1621,32 +1621,11 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, goto out; } -while ((dfrag =mptcp_send_head (sk))) { - info.sent = dfrag->already_sent; - info.limit = dfrag->data_len; - len = dfrag->data_len - dfrag->already_sent; -while (len >0 ) { -int ret =0 ; - - ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); -if (ret <=0 ) - goto out; - - info.sent += ret; - copied += ret; - len -= ret; - first = false; - -mptcp_update_post_push (msk, dfrag, ret); - } -WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); - -if (msk->snd_burst <=0 || - !sk_stream_memory_free (ssk) || - !mptcp_subflow_active (mptcp_subflow_ctx (ssk))) { - goto out; - } -mptcp_set_timeout (sk); + ret =__subflow_push_pending (sk, ssk, &info); +if (ret <=0 ) { +if (ret == -EAGAIN ) + goto again; +break ; } }
@@ -1654,9 +1633,7 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk,/* __mptcp_alloc_tx_skb could have released some wmem and we are * not going to flush it via release_sock() */ -if (copied) { -tcp_push (ssk,0 , info.mss_now,tcp_sk (ssk)->nonagle, - info.size_goal); +if (ret >0 ) {if (!mptcp_timer_pending (sk))mptcp_reset_timer (sk);
Signature · 1 line
2.35.3
PATCH v7 10/12 mptcp: multi subflows subflow_push_pending
In reply to Geliang TangThis patch adds the multiple subflows support for __mptcp_subflow_push_pending(). Use mptcp_sched_get_send() wrapper instead of mptcp_subflow_get_send() in it.
Check the subflow scheduled flags to test which subflow or subflows are picked by the scheduler, use them to send data.
--- net/mptcp/protocol.c | 50 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-)
net/mptcp/protocol.c +38 -12
@@ -1599,11 +1599,11 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)static void __mptcp_subflow_push_pending (struct sock *sk,struct sock *ssk,bool first) { +struct mptcp_subflow_context *subflow, *last =NULL ;struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_sendmsg_info info = { .data_lock_held = true, }; -struct sock *xmit_ssk;int ret =0 ; info.flags =0 ;
@@ -1612,20 +1612,46 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk,/* check for a different subflow usage only after * spooling the first chunk of data */ - xmit_ssk = first ? ssk :mptcp_subflow_get_send (msk); -if (!xmit_ssk) - goto out; -if (xmit_ssk != ssk) { -mptcp_subflow_delegate (mptcp_subflow_ctx (xmit_ssk), -MPTCP_DELEGATE_SEND ); +if (first) { + ret =__subflow_push_pending (sk, ssk, &info); +if (ret <=0 ) { +if (ret == -EAGAIN ) + goto again; +break ; + } + first = false; +continue ; + } + +if (mptcp_sched_get_send (msk)) goto out; + +mptcp_for_each_subflow (msk, subflow) { +if (READ_ONCE (subflow->scheduled)) + last = subflow; } - ret =__subflow_push_pending (sk, ssk, &info); -if (ret <=0 ) { -if (ret == -EAGAIN ) - goto again; -break ; +mptcp_for_each_subflow (msk, subflow) { +if (READ_ONCE (subflow->scheduled)) { +struct sock *xmit_ssk =mptcp_subflow_tcp_sock (subflow); + +if (xmit_ssk != ssk) { +mptcp_subflow_delegate (subflow, +MPTCP_DELEGATE_SEND ); +mptcp_subflow_set_scheduled (subflow, false); +if (last && subflow != last) +continue ; + goto out; + } + + ret =__subflow_push_pending (sk, ssk, &info); +if (ret <=0 ) { +if (ret == -EAGAIN ) + goto again; + goto out; + } +mptcp_subflow_set_scheduled (subflow, false); + } } }
Signature · 1 line
2.35.3
Re: [PATCH mptcp-next v7 10/12] mptcp: multi subflows subflow_push_pending
Quoted 8 lines · Geliang Tang
This patch adds the multiple subflows support for
__mptcp_subflow_push_pending(). Usemptcp_sched_get_send()wrapper instead ofmptcp_subflow_get_send()in it.Check the subflow scheduled flags to test which subflow or subflows are picked by the scheduler, use them to send data.
Signed-off-by Geliang Tang <[email protected]>
Hi Geliang -
We talked about redundant transmits from __mptcp_subflow_push_pending() in the meeting today: https://annuel2.framapad.org/p/mptcp_upstreaming_20221013#L110
It was hard to capture the whole discussion in the notes, but the main point is that handling the multi-sublow __mptcp_subflow_push_pending() is a lot more complicated than the __mptcp_push_pending() case.
__mptcp_subflow_push_pending() is running in one of two contexts, where the ssk lock is already held and sock_owned_by_user(msk) has been checked:
1. From mptcp_incoming_options(). This allows transmission of unsent data from mptcp_send_head when acks are received on a subflow - if the scheduler selects the subflow that is already locked, then additional data can be quickly sent without any delegated actions, release callbacks, or worker threads. If the scheduler selects a different subflow, a "delegated action" is used to schedule a callback for that subflow using the NAPI poll API.
2. From mptcp_napi_poll() (the "delegated action"), as scheduled by the case above.
There are some constraints to observe here:
In both case 1 and case 2, it should only delegate to one other subflow. If there are more than two redundant subflows scheduled, there would need to be a way to chain delegated calls. (I'll explain more about this with the code below).
It's also important to understand that the subflow and msk data locks are released between case 1 above and a delegated action that runs later. __mptcp_push_pending() could run and invoke the scheduler again, which would overwrite the subflow->scheduled bits that were set by __mptcp_subflow_push_pending(). This means __mptcp_push_pending() needs to be aware of multiple-subflow sends that are in progress, and finish those pushes before calling the scheduler again.
To make all this work, we think more data needs to be stored in each subflow by the scheduler. Each scheduled subflow needs to know:
* Is it scheduled? (subflow->scheduled)
* Where to start sending
* How much data to try to send on that subflow
As the code is now, __mptcp_subflow_push_pending() will send sequential data instead of redundant data if multiple subflows are scheduled.
Like I said above, this is getting quite a bit more complicated for the multiple subflow case. What do you think about posting a v8 patch set that has only the single subflow refactoring and any necessary squash-to patches? Then we could add those commits to the export branch, and start working on a dedicated multi-subflow series?
Quoted 56 lines
---
net/mptcp/protocol.c| 50 +++++++++++++++++++++++++++++++++-----------1 file changed, 38 insertions(+), 12 deletions(-)net/mptcp/protocol.c +18
-12@@ -1599,11 +1599,11 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)static void __mptcp_subflow_push_pending (struct sock *sk,struct sock *ssk,bool first) { +struct mptcp_subflow_context *subflow, *last =NULL ;struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_sendmsg_info info = { .data_lock_held = true, }; -struct sock *xmit_ssk;int ret =0 ; info.flags =0 ;@@ -1612,20 +1612,46 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk,/* check for a different subflow usage only after * spooling the first chunk of data */ - xmit_ssk = first ? ssk :mptcp_subflow_get_send (msk); -if (!xmit_ssk) - goto out; -if (xmit_ssk != ssk) { -mptcp_subflow_delegate (mptcp_subflow_ctx (xmit_ssk), -MPTCP_DELEGATE_SEND ); +if (first) { + ret =__subflow_push_pending (sk, ssk, &info); +if (ret <=0 ) { +if (ret == -EAGAIN ) + goto again; +break ; + } + first = false; +continue ; + } + +if (mptcp_sched_get_send (msk)) goto out; + +mptcp_for_each_subflow (msk, subflow) { +if (READ_ONCE (subflow->scheduled)) + last = subflow; } - ret =__subflow_push_pending (sk, ssk, &info); -if (ret <=0 ) { -if (ret == -EAGAIN ) - goto again; -break ; +mptcp_for_each_subflow (msk, subflow) {
net/mptcp/protocol.c static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, · line 1644
Quoted 10 lines
net/mptcp/protocol.c +10
-0+if (READ_ONCE (subflow->scheduled)) { +struct sock *xmit_ssk =mptcp_subflow_tcp_sock (subflow); + +if (xmit_ssk != ssk) { +mptcp_subflow_delegate (subflow, +MPTCP_DELEGATE_SEND ); +mptcp_subflow_set_scheduled (subflow, false); +if (last && subflow != last) +continue ; + goto out;
mptcp_subflow_delegate() should be called only one time to pick the next subflow to attempt. mptcp_napi_poll() will try to send on that subflow, and then call mptcp_subflow_delegate() to schedule the next subflow. This chain will continue until all the redundant subflows have transmitted their data.
Quoted 18 lines
net/mptcp/protocol.c +10
-0+ } + + ret =__subflow_push_pending (sk, ssk, &info); +if (ret <=0 ) { +if (ret == -EAGAIN ) + goto again; + goto out; + } +mptcp_subflow_set_scheduled (subflow, false); + } } }Signature · 1 line
2.35.3
--
Mat Martineau
Intel
PATCH v7 11/12 mptcp: multi subflows retrans support
In reply to Geliang TangThis patch adds the multiple subflows support for __mptcp_retrans(). In it, use sched_get_retrans() wrapper instead of mptcp_subflow_get_retrans().
Iterate each subflow of msk, check the scheduled flag to test if it is picked by the scheduler. If so, use it to retrans data.
--- net/mptcp/protocol.c | 61 +++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 23 deletions(-)
net/mptcp/protocol.c +38 -23
@@ -2483,16 +2483,17 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)static void __mptcp_retrans (struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk); +struct mptcp_subflow_context *subflow;struct mptcp_sendmsg_info info = {};struct mptcp_data_frag *dfrag; -size_t copied =0 ;struct sock *ssk; -int ret; +int ret, err; +u16 len =0 ;mptcp_clean_una_wakeup (sk);/* first check ssk: need to kick "stale" logic */ - ssk =mptcp_subflow_get_retrans (msk); + err =mptcp_sched_get_retrans (msk); dfrag =mptcp_rtx_head (sk);if (!dfrag) {if (mptcp_data_fin_enabled (msk)) {
@@ -2511,31 +2512,45 @@ static void __mptcp_retrans(struct sock *sk) goto reset_timer; } -if (!ssk) +if (err) goto reset_timer; -lock_sock (ssk); +mptcp_for_each_subflow (msk, subflow) { +if (READ_ONCE (subflow->scheduled)) { +u16 copied =0 ; + + ssk =mptcp_subflow_tcp_sock (subflow); +if (!ssk) + goto reset_timer; + +lock_sock (ssk); + +/* limit retransmission to the bytes already sent on some subflows */ + info.sent =0 ; + info.limit =READ_ONCE (msk->csum_enabled) ? dfrag->data_len : + dfrag->already_sent; +while (info.sent < info.limit) { + ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); +if (ret <=0 ) +break ; + +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RETRANSSEGS ); + copied += ret; + info.sent += ret; + } +if (copied) { + len =max (copied, len); +tcp_push (ssk,0 , info.mss_now,tcp_sk (ssk)->nonagle, + info.size_goal); +WRITE_ONCE (msk->allow_infinite_fallback, false); + } -/* limit retransmission to the bytes already sent on some subflows */ - info.sent =0 ; - info.limit =READ_ONCE (msk->csum_enabled) ? dfrag->data_len : dfrag->already_sent; -while (info.sent < info.limit) { - ret =mptcp_sendmsg_frag (sk, ssk, dfrag, &info); -if (ret <=0 ) -break ; +release_sock (ssk); -MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RETRANSSEGS ); - copied += ret; - info.sent += ret; - } -if (copied) { - dfrag->already_sent =max (dfrag->already_sent, info.sent); -tcp_push (ssk,0 , info.mss_now,tcp_sk (ssk)->nonagle, - info.size_goal); -WRITE_ONCE (msk->allow_infinite_fallback, false); +mptcp_subflow_set_scheduled (subflow, false); + } } - -release_sock (ssk); + dfrag->already_sent =max (dfrag->already_sent, len); reset_timer:mptcp_check_and_set_pending (sk);
Signature · 1 line
2.35.3
PATCH v7 12/12 Squash to "selftests/bpf: Add bpf_rr scheduler"
In reply to Geliang TangUse last_snd instead of msk->last_snd, then last_snd of struct mptcp_sock could be removed.
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 - tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +0 -1
@@ -257,7 +257,6 @@ struct mptcp_sched_ops {struct mptcp_sock {struct inet_connection_sock sk; -struct sock *last_snd;__u32 token;struct sock *first;char ca_name[TCP_CA_NAME_MAX ];
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c +4 -2
@@ -5,6 +5,7 @@#include "bpf_tcp_helpers.h" char _license[] SEC("license") = "GPL"; +struct sock *last_snd =NULL ; SEC("struct_ops/mptcp_sched_rr_init")void BPF_PROG (mptcp_sched_rr_init ,const struct mptcp_sock *msk)
@@ -22,10 +23,10 @@ void BPF_STRUCT_OPS(bpf_rr_get_subflow, const struct mptcp_sock *msk,int nr =0 ;for (int i =0 ; i <MPTCP_SUBFLOWS_MAX ; i++) { -if (!msk->last_snd || !data->contexts[i]) +if (!last_snd || !data->contexts[i])break ; -if (data->contexts[i]->tcp_sock == msk->last_snd) { +if (data->contexts[i]->tcp_sock == last_snd) {if (i +1 ==MPTCP_SUBFLOWS_MAX || !data->contexts[i +1 ])break ;
@@ -35,6 +36,7 @@ void BPF_STRUCT_OPS(bpf_rr_get_subflow, const struct mptcp_sock *msk, }mptcp_subflow_set_scheduled (data->contexts[nr], true); + last_snd = data->contexts[nr]->tcp_sock; }SEC (".struct_ops" )
Signature · 1 line
2.35.3
Re: Squash to "selftests/bpf: Add bpf_rr scheduler": Tests Results
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal:
- Unstable: 3 failed test(s): packetdrill_add_addr selftest_mptcp_join selftest_simult_flows 🔴:
- Task: https://cirrus-ci.com/task/5096210894159872
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5096210894159872/summary/summary.txt
- KVM Validation: debug:
- Success! ✅:
- Task: https://cirrus-ci.com/task/6222110801002496
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6222110801002496/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/e52192a357aa
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-debugFor 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 (Tessares)