mptcp: add statistics for mptcp socket in use
Subsystems (3)
v3 cover mptcp: add statistics for mptcp socket in use
From: Menglong Dong <[email protected]>
In the 1th patch, we do some code cleanup with replease 'sock->sk' with 'sk'. In the 2th patch, we add statistics for mptcp socket in use. And in the 3th patch, we add the testing for this commit.
Changes since v2:
- add testing
Changes since v1:
- split the code cleanup into the 1th patch.
- decrease the statistics for listening mptcp socket inuse with mptcp_listen_inuse_dec()
- add MPTCP_DESTROIED flags to store if mptcp_destroy_common() was called on the msk. For fallback case, we need to decrease the statistics only once, and mptcp_destroy_common() can be called more than once.
Menglong Dong (3):
mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
mptcp: add statistics for mptcp socket in use
selftest: mptcp: add test for mptcp socket in use
net/mptcp/protocol.c | 35 ++++++++++++++++++----- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 3 ++ tools/testing/selftests/net/mptcp/diag.sh | 28 ++++++++++++++++++ 4 files changed, 60 insertions(+), 7 deletions(-)
Signature · 1 line
2.37.2
PATCH v3 1/3 mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
From: Menglong Dong <[email protected]>
'sock->sk' is used frequently in mptcp_listen(). Therefore, we can introduce the 'sk' and replace 'sock->sk' with it.
--- net/mptcp/protocol.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +7 -6
@@ -3577,12 +3577,13 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,static int mptcp_listen (struct socket *sock,int backlog) {struct mptcp_sock *msk =mptcp_sk (sock->sk); +struct sock *sk = sock->sk;struct socket *ssock;int err;pr_debug ("msk=%p" , msk); -lock_sock (sock->sk); +lock_sock (sk); ssock =__mptcp_nmpc_socket (msk);if (!ssock) { err = -EINVAL ;
@@ -3590,16 +3591,16 @@ static int mptcp_listen(struct socket *sock, int backlog) }mptcp_token_destroy (msk); -inet_sk_state_store (sock->sk,TCP_LISTEN ); -sock_set_flag (sock->sk,SOCK_RCU_FREE ); +inet_sk_state_store (sk,TCP_LISTEN ); +sock_set_flag (sk,SOCK_RCU_FREE ); err = ssock->ops->listen (ssock, backlog); -inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk)); +inet_sk_state_store (sk,inet_sk_state_load (ssock->sk));if (!err) -mptcp_copy_inaddrs (sock->sk, ssock->sk); +mptcp_copy_inaddrs (sk, ssock->sk); unlock: -release_sock (sock->sk); +release_sock (sk);return err; }
Signature · 1 line
2.37.2
PATCH v3 2/3 mptcp: add statistics for mptcp socket in use
In reply to [email protected]From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from /proc/net/protocols:
& cat /proc/net/protocols
protocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n
---
v2:
- decrease the statistics for listening mptcp socket inuse with mptcp_listen_inuse_dec()
- add MPTCP_DESTROIED flags to store if mptcp_destroy_common() was called on the msk. For fallback case, we need to decrease the statistics only once, and mptcp_destroy_common() can be called more than once.
--- net/mptcp/protocol.c | 22 +++++++++++++++++++++- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +21 -1
@@ -2913,6 +2913,16 @@ static void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; } +static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN ) +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); +} +static int mptcp_disconnect (struct sock *sk,int flags) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -2925,6 +2935,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)if (mptcp_sk (sk)->token)mptcp_event (MPTCP_EVENT_CLOSED ,mptcp_sk (sk),NULL ,GFP_KERNEL ); +mptcp_listen_inuse_dec (sk);/* msk->subflow is still intact, the following will not free the first * subflow */
@@ -3096,6 +3107,11 @@ void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags)skb_rbtree_purge (&msk->out_of_order_queue);mptcp_data_unlock (sk); +if ((__mptcp_check_fallback (msk) && + !test_and_set_bit (MPTCP_DESTROIED , &msk->flags)) || + !sk_unhashed (sk)) +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); +/* move all the rx fwd alloc into the sk_mem_reclaim_final in * inet_sock_destruct() will dispose it */
@@ -3110,6 +3126,7 @@ static void mptcp_destroy(struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk); +mptcp_listen_inuse_dec (sk);/* clears msk->subflow, allowing the following to close * even the initial subflow */
@@ -3542,6 +3559,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,mptcp_token_destroy (msk);inet_sk_state_store (sock->sk,TCP_SYN_SENT ); subflow =mptcp_subflow_ctx (ssock->sk); +sock_prot_inuse_add (sock_net (sock->sk), sock->sk->sk_prot,1 );#ifdef CONFIG_TCP_MD5SIG /* no MPTCP if MD5SIG is enabled on this socket or we may run out of * TCP option space.
@@ -3596,8 +3614,10 @@ static int mptcp_listen(struct socket *sock, int backlog) err = ssock->ops->listen (ssock, backlog);inet_sk_state_store (sk,inet_sk_state_load (ssock->sk)); -if (!err) +if (!err) { +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,1 );mptcp_copy_inaddrs (sk, ssock->sk); + } unlock:release_sock (sk);
net/mptcp/protocol.h +1 -0
@@ -116,6 +116,7 @@#define MPTCP_WORK_EOF 3#define MPTCP_FALLBACK_DONE 4#define MPTCP_WORK_CLOSE_SUBFLOW 5 +#define MPTCP_DESTROIED 6/* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1
net/mptcp/subflow.c +3 -0
@@ -747,6 +747,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,mptcp_sk (new_msk)->setsockopt_seq = ctx->setsockopt_seq;mptcp_pm_new_connection (mptcp_sk (new_msk), child,1 );mptcp_token_accept (subflow_req,mptcp_sk (new_msk)); +sock_prot_inuse_add (sock_net (new_msk), + new_msk->sk_prot, +1 ); ctx->conn = new_msk; new_msk =NULL ;
Signature · 1 line
2.37.2
Quoted 100 lines · On Fri, 30 Sep 2022, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y nSigned-off-by Menglong Dong <[email protected]>---
v2:
- decrease the statistics for listening mptcp socket inuse withmptcp_listen_inuse_dec()
- addMPTCP_DESTROIEDflags to store ifmptcp_destroy_common()was called on the msk. For fallback case, we need to decrease the statistics only once, andmptcp_destroy_common()can be called more than once.
---net/mptcp/protocol.c | 22 +++++++++++++++++++++- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-)net/mptcp/protocol.c +21
-1@@ -2913,6 +2913,16 @@ static void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; } +static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN ) +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); +} +static int mptcp_disconnect (struct sock *sk,int flags) {struct mptcp_sock *msk =mptcp_sk (sk);@@ -2925,6 +2935,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)if (mptcp_sk (sk)->token)mptcp_event (MPTCP_EVENT_CLOSED ,mptcp_sk (sk),NULL ,GFP_KERNEL ); +mptcp_listen_inuse_dec (sk);/* msk->subflow is still intact, the following will not free the first * subflow */ @@ -3096,6 +3107,11 @@ void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags)skb_rbtree_purge (&msk->out_of_order_queue);mptcp_data_unlock (sk); +if ((__mptcp_check_fallback (msk) && + !test_and_set_bit (MPTCP_DESTROIED , &msk->flags)) || + !sk_unhashed (sk)) +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); +/* move all the rx fwd alloc into the sk_mem_reclaim_final in * inet_sock_destruct() will dispose it */ @@ -3110,6 +3126,7 @@ static void mptcp_destroy(struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk); +mptcp_listen_inuse_dec (sk);/* clears msk->subflow, allowing the following to close * even the initial subflow */ @@ -3542,6 +3559,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,mptcp_token_destroy (msk);inet_sk_state_store (sock->sk,TCP_SYN_SENT ); subflow =mptcp_subflow_ctx (ssock->sk); +sock_prot_inuse_add (sock_net (sock->sk), sock->sk->sk_prot,1 );#ifdef CONFIG_TCP_MD5SIG /* no MPTCP if MD5SIG is enabled on this socket or we may run out of * TCP option space. @@ -3596,8 +3614,10 @@ static int mptcp_listen(struct socket *sock, int backlog) err = ssock->ops->listen (ssock, backlog);inet_sk_state_store (sk,inet_sk_state_load (ssock->sk)); -if (!err) +if (!err) { +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,1 );mptcp_copy_inaddrs (sk, ssock->sk); + }unlock:
release_sock(sk);net/mptcp/protocol.h +0
-0
net/mptcp/protocol.h line 118
Quoted 3 lines
net/mptcp/protocol.h +0
-0@@ -116,6 +116,7 @@#define MPTCP_WORK_EOF 3#define MPTCP_FALLBACK_DONE 4#define MPTCP_WORK_CLOSE_SUBFLOW 5
Hi Menglong -
Overall, v3 is looking good. Thanks for adding the tests!
One thing that was requested in v2 review was to fix this spelling:
net/mptcp/protocol.h line 119
Quoted 1 line
net/mptcp/protocol.h +1
-0+#define MPTCP_DESTROIED 6
to be MPTCP_DESTROYED. Can you fix that and post v4?
- Mat
Quoted 21 lines
net/mptcp/protocol.h +0
-0/* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1net/mptcp/subflow.c +3
-0@@ -747,6 +747,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,mptcp_sk (new_msk)->setsockopt_seq = ctx->setsockopt_seq;mptcp_pm_new_connection (mptcp_sk (new_msk), child,1 );mptcp_token_accept (subflow_req,mptcp_sk (new_msk)); +sock_prot_inuse_add (sock_net (new_msk), + new_msk->sk_prot, +1 ); ctx->conn = new_msk; new_msk =NULL ;Signature · 1 line
2.37.2
--
Mat Martineau
Intel
Quoted 109 lines · Mat Martineau
Quoted 100 lines · On Fri, 30 Sep 2022, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y nSigned-off-by Menglong Dong <[email protected]>---
v2:
- decrease the statistics for listening mptcp socket inuse withmptcp_listen_inuse_dec()
- addMPTCP_DESTROIEDflags to store ifmptcp_destroy_common()was called on the msk. For fallback case, we need to decrease the statistics only once, andmptcp_destroy_common()can be called more than once.
---net/mptcp/protocol.c | 22 +++++++++++++++++++++- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-)net/mptcp/protocol.c +21
-1@@ -2913,6 +2913,16 @@ static void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; } +static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN ) +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); +} +static int mptcp_disconnect (struct sock *sk,int flags) {struct mptcp_sock *msk =mptcp_sk (sk);@@ -2925,6 +2935,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)if (mptcp_sk (sk)->token)mptcp_event (MPTCP_EVENT_CLOSED ,mptcp_sk (sk),NULL ,GFP_KERNEL ); +mptcp_listen_inuse_dec (sk);/* msk->subflow is still intact, the following will not free the first * subflow */ @@ -3096,6 +3107,11 @@ void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags)skb_rbtree_purge (&msk->out_of_order_queue);mptcp_data_unlock (sk); +if ((__mptcp_check_fallback (msk) && + !test_and_set_bit (MPTCP_DESTROIED , &msk->flags)) || + !sk_unhashed (sk)) +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); +/* move all the rx fwd alloc into the sk_mem_reclaim_final in * inet_sock_destruct() will dispose it */ @@ -3110,6 +3126,7 @@ static void mptcp_destroy(struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk); +mptcp_listen_inuse_dec (sk);/* clears msk->subflow, allowing the following to close * even the initial subflow */ @@ -3542,6 +3559,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,mptcp_token_destroy (msk);inet_sk_state_store (sock->sk,TCP_SYN_SENT ); subflow =mptcp_subflow_ctx (ssock->sk); +sock_prot_inuse_add (sock_net (sock->sk), sock->sk->sk_prot,1 );#ifdef CONFIG_TCP_MD5SIG /* no MPTCP if MD5SIG is enabled on this socket or we may run out of * TCP option space. @@ -3596,8 +3614,10 @@ static int mptcp_listen(struct socket *sock, int backlog) err = ssock->ops->listen (ssock, backlog);inet_sk_state_store (sk,inet_sk_state_load (ssock->sk)); -if (!err) +if (!err) { +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,1 );mptcp_copy_inaddrs (sk, ssock->sk); + }unlock:
release_sock(sk);net/mptcp/protocol.h +0
-0net/mptcp/protocol.h line 118
Quoted 3 lines
net/mptcp/protocol.h +0
-0@@ -116,6 +116,7 @@#define MPTCP_WORK_EOF 3#define MPTCP_FALLBACK_DONE 4#define MPTCP_WORK_CLOSE_SUBFLOW 5Hi Menglong -
Quoted 8 lines
Overall, v3 is looking good. Thanks for adding the tests!
One thing that was requested in v2 review was to fix this spelling:
net/mptcp/protocol.h line 119
Quoted 1 line
net/mptcp/protocol.h +1
-0+#define MPTCP_DESTROIED 6to be
MPTCP_DESTROYED. Can you fix that and post v4?
OMG! I forgot this part :) Yeah, I'll fix it in v4.
Thanks!
Menglong Dong
Quoted 28 lines
- Mat
Quoted 18 lines
net/mptcp/protocol.h +0
-0/* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1net/mptcp/subflow.c +3
-1@@ -747,6 +747,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,mptcp_sk (new_msk)->setsockopt_seq = ctx->setsockopt_seq;mptcp_pm_new_connection (mptcp_sk (new_msk), child,1 );mptcp_token_accept (subflow_req,mptcp_sk (new_msk)); +sock_prot_inuse_add (sock_net (new_msk), + new_msk->sk_prot, +1 ); ctx->conn = new_msk; new_msk =NULL ; --Quoted 3 lines
2.37.2
--
Mat Martineau
Intel
PATCH v3 3/3 selftest: mptcp: add test for mptcp socket in use
In reply to [email protected]From: Menglong Dong <[email protected]>
Add the function chk_msk_inuse() to diag.sh, which is used to check the statistics of mptcp socket in use. As mptcp socket in listen state will be closed randomly after 'accept', we need to get the count of listening mptcp socket through 'ss' command.
mptcp_connect command with '-r' flag seems won't exit after flush_pids, therefore we need consider this additional statistics. But after the second flush_pids, it will exit.
All tests pass.
--- tools/testing/selftests/net/mptcp/diag.sh | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+)
tools/testing/selftests/net/mptcp/diag.sh +28 -0
@@ -141,6 +141,28 @@ chk_msk_listen() nr=$(ss -Ml $filter | wc -l) } +chk_msk_inuse() +{ + local nr listen_nr + local expected=$1 + + shift 1 + msg=$* + + nr=$(ip netns exec $ns awk '$1~/^MPTCP$/{print $3}' /proc/net/protocols) + listen_nr=$(ss -N $ns -Ml | grep -c LISTEN) + expected=$(($expected+$listen_nr)) + + printf "%-50s" "$msg" + + if [ $nr != $expected ]; then + echo "[ fail ] expected $expected found $nr" + ret=$test_cnt + else + echo "[ ok ]" + fi +} + # $1: ns, $2: port wait_local_port_listen() {
@@ -194,8 +216,11 @@ wait_connected $ns 10000 chk_msk_nr 2 "after MPC handshake " chk_msk_remote_key_nr 2 "....chk remote_key" chk_msk_fallback_nr 0 "....chk no fallback" +chk_msk_inuse 2 "msk in use statistics" flush_pids +# with '-r' flag, client won't exit after flush_pids +chk_msk_inuse 1 "msk in use statistics" echo "a" | \ timeout ${timeout_test} \
@@ -231,6 +256,9 @@ for I in `seq 1 $NR_CLIENTS`; do done wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present" +chk_msk_inuse $((NR_CLIENTS*2+1)) "msk in use statistics" flush_pids +chk_msk_inuse 0 "msk in use statistics" + exit $ret
Signature · 1 line
2.37.2
Re: selftest: mptcp: add test for mptcp socket in use: Tests Results
Hi Menglong,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal:
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/4902994138365952
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4902994138365952/summary/summary.txt
- KVM Validation: debug:
- Unstable: 2 failed test(s): selftest_diag selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/6028894045208576
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6028894045208576/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/9efac8bc4497
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)