mptcp.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use
@ 2022-09-21 12:04 menglong8.dong
  2022-09-21 12:04 ` [PATCH mptcp-next v2 1/2] mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen() menglong8.dong
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: menglong8.dong @ 2022-09-21 12:04 UTC (permalink / raw)
  To: mathew.j.martineau; +Cc: mptcp, Menglong Dong

From: Menglong Dong <imagedong@tencent.com>

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.

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 (2):
  mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
  mptcp: add statistics for mptcp socket in use

 net/mptcp/protocol.c | 34 +++++++++++++++++++++++++++-------
 net/mptcp/protocol.h |  1 +
 net/mptcp/subflow.c  |  3 +++
 3 files changed, 31 insertions(+), 7 deletions(-)

-- 
2.37.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH mptcp-next v2 1/2] mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
  2022-09-21 12:04 [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use menglong8.dong
@ 2022-09-21 12:04 ` menglong8.dong
  2022-09-21 12:04 ` [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use menglong8.dong
  2022-09-22  0:03 ` [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use Mat Martineau
  2 siblings, 0 replies; 8+ messages in thread
From: menglong8.dong @ 2022-09-21 12:04 UTC (permalink / raw)
  To: mathew.j.martineau; +Cc: mptcp, Menglong Dong

From: Menglong Dong <imagedong@tencent.com>

'sock->sk' is used frequently in mptcp_listen(). Therefore, we can
introduce the 'sk' and replace 'sock->sk' with it.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
 net/mptcp/protocol.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d6d3ebeb7c9b..1550455f7640 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3548,12 +3548,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;
@@ -3561,16 +3562,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;
 }
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use
  2022-09-21 12:04 [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use menglong8.dong
  2022-09-21 12:04 ` [PATCH mptcp-next v2 1/2] mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen() menglong8.dong
@ 2022-09-21 12:04 ` menglong8.dong
  2022-09-21 12:42   ` Matthieu Baerts
  2022-09-21 13:37   ` mptcp: add statistics for mptcp socket in use: Tests Results MPTCP CI
  2022-09-22  0:03 ` [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use Mat Martineau
  2 siblings, 2 replies; 8+ messages in thread
From: menglong8.dong @ 2022-09-21 12:04 UTC (permalink / raw)
  To: mathew.j.martineau; +Cc: mptcp, Menglong Dong

From: Menglong Dong <imagedong@tencent.com>

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

Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
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(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 1550455f7640..57d468b24a92 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2885,6 +2885,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);
@@ -2897,6 +2907,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
 	 */
@@ -3068,6 +3079,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
 	 */
@@ -3082,6 +3098,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
 	 */
@@ -3514,6 +3531,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.
@@ -3567,8 +3585,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);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index c0b5b4628f65..675de024de10 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -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
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 07dd23d0fe04..da6cfa73a3bd 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -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;
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use
  2022-09-21 12:04 ` [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use menglong8.dong
@ 2022-09-21 12:42   ` Matthieu Baerts
  2022-09-21 12:52     ` Menglong Dong
  2022-09-21 13:37   ` mptcp: add statistics for mptcp socket in use: Tests Results MPTCP CI
  1 sibling, 1 reply; 8+ messages in thread
From: Matthieu Baerts @ 2022-09-21 12:42 UTC (permalink / raw)
  To: menglong8.dong, mathew.j.martineau; +Cc: mptcp, Menglong Dong

Hi Menglong,

On 21/09/2022 14:04, menglong8.dong@gmail.com wrote:
> From: Menglong Dong <imagedong@tencent.com>
> 
> 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:

(...)

> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index c0b5b4628f65..675de024de10 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -116,6 +116,7 @@
>  #define MPTCP_WORK_EOF		3
>  #define MPTCP_FALLBACK_DONE	4
>  #define MPTCP_WORK_CLOSE_SUBFLOW 5
> +#define MPTCP_DESTROIED		6

I'm only reacting here about the name (I didn't check the rest in
details) but do you mind using MPTCP_DESTROYED with a Y instead of I please
When it is written using capital letters, it is better to avoid such
typos :)

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use
  2022-09-21 12:42   ` Matthieu Baerts
@ 2022-09-21 12:52     ` Menglong Dong
  0 siblings, 0 replies; 8+ messages in thread
From: Menglong Dong @ 2022-09-21 12:52 UTC (permalink / raw)
  To: Matthieu Baerts; +Cc: mathew.j.martineau, mptcp, Menglong Dong

On Wed, Sep 21, 2022 at 8:42 PM Matthieu Baerts
<matthieu.baerts@tessares.net> wrote:
>
> Hi Menglong,
>
> On 21/09/2022 14:04, menglong8.dong@gmail.com wrote:
> > From: Menglong Dong <imagedong@tencent.com>
> >
> > 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:
>
> (...)
>
> > diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> > index c0b5b4628f65..675de024de10 100644
> > --- a/net/mptcp/protocol.h
> > +++ b/net/mptcp/protocol.h
> > @@ -116,6 +116,7 @@
> >  #define MPTCP_WORK_EOF               3
> >  #define MPTCP_FALLBACK_DONE  4
> >  #define MPTCP_WORK_CLOSE_SUBFLOW 5
> > +#define MPTCP_DESTROIED              6
>
> I'm only reacting here about the name (I didn't check the rest in
> details) but do you mind using MPTCP_DESTROYED with a Y instead of I please
> When it is written using capital letters, it is better to avoid such
> typos :)
>

Oops, it's my mistake!

Thanks!
Menglong Dong

> Cheers,
> Matt
> --
> Tessares | Belgium | Hybrid Access Solutions
> www.tessares.net

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mptcp: add statistics for mptcp socket in use: Tests Results
  2022-09-21 12:04 ` [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use menglong8.dong
  2022-09-21 12:42   ` Matthieu Baerts
@ 2022-09-21 13:37   ` MPTCP CI
  1 sibling, 0 replies; 8+ messages in thread
From: MPTCP CI @ 2022-09-21 13:37 UTC (permalink / raw)
  To: Menglong Dong; +Cc: mptcp

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_simult_flows 🔴:
  - Task: https://cirrus-ci.com/task/4839559384006656
  - Summary: https://api.cirrus-ci.com/v1/artifact/task/4839559384006656/summary/summary.txt

- KVM Validation: debug:
  - Unstable: 2 failed test(s): packetdrill_add_addr packetdrill_dss 🔴:
  - Task: https://cirrus-ci.com/task/5965459290849280
  - Summary: https://api.cirrus-ci.com/v1/artifact/task/5965459290849280/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/179389e0fe2d


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-debug

For more details:

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


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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use
  2022-09-21 12:04 [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use menglong8.dong
  2022-09-21 12:04 ` [PATCH mptcp-next v2 1/2] mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen() menglong8.dong
  2022-09-21 12:04 ` [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use menglong8.dong
@ 2022-09-22  0:03 ` Mat Martineau
  2022-09-22  3:48   ` Menglong Dong
  2 siblings, 1 reply; 8+ messages in thread
From: Mat Martineau @ 2022-09-22  0:03 UTC (permalink / raw)
  To: menglong8.dong; +Cc: mptcp, Menglong Dong

On Wed, 21 Sep 2022, menglong8.dong@gmail.com wrote:

> From: Menglong Dong <imagedong@tencent.com>
>
> 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.
>
> 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.
>

Hi Menglong -

Thanks for the v2. Other than Matthieu's request about MPTCP_DESTROYED, 
could you also add a selftest patch to confirm the counter is updated 
correctly?

This test script:

tools/testing/selftests/net/mptcp/diag.sh

already creates a large number of simultaneous sockets, so it might work 
well to modify the wait_msk_nr() function to also confirm the protocol 
inuse counter, and then check that the counter returns to zero after the 
sockets are closed.

> Menglong Dong (2):
>  mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
>  mptcp: add statistics for mptcp socket in use
>
> net/mptcp/protocol.c | 34 +++++++++++++++++++++++++++-------
> net/mptcp/protocol.h |  1 +
> net/mptcp/subflow.c  |  3 +++
> 3 files changed, 31 insertions(+), 7 deletions(-)
>
> -- 
> 2.37.2
>
>

--
Mat Martineau
Intel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use
  2022-09-22  0:03 ` [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use Mat Martineau
@ 2022-09-22  3:48   ` Menglong Dong
  0 siblings, 0 replies; 8+ messages in thread
From: Menglong Dong @ 2022-09-22  3:48 UTC (permalink / raw)
  To: Mat Martineau; +Cc: mptcp, Menglong Dong

Hello,

On Thu, Sep 22, 2022 at 8:04 AM Mat Martineau
<mathew.j.martineau@linux.intel.com> wrote:
>
> On Wed, 21 Sep 2022, menglong8.dong@gmail.com wrote:
>
> > From: Menglong Dong <imagedong@tencent.com>
> >
> > 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.
> >
> > 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.
> >
>
> Hi Menglong -
>
> Thanks for the v2. Other than Matthieu's request about MPTCP_DESTROYED,
> could you also add a selftest patch to confirm the counter is updated
> correctly?
>
> This test script:
>
> tools/testing/selftests/net/mptcp/diag.sh
>
> already creates a large number of simultaneous sockets, so it might work
> well to modify the wait_msk_nr() function to also confirm the protocol
> inuse counter, and then check that the counter returns to zero after the
> sockets are closed.

Thanks for the explanation, I think it can work. In case of that
there are mptcp sockets existing out of the testing, we can also
record the statistics before creating mptcp socket, and compare
the statistics after the closing of mptcp socket.

I'll add the test in the next version.

Thanks!
Menglong Dong

>
> > Menglong Dong (2):
> >  mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
> >  mptcp: add statistics for mptcp socket in use
> >
> > net/mptcp/protocol.c | 34 +++++++++++++++++++++++++++-------
> > net/mptcp/protocol.h |  1 +
> > net/mptcp/subflow.c  |  3 +++
> > 3 files changed, 31 insertions(+), 7 deletions(-)
> >
> > --
> > 2.37.2
> >
> >
>
> --
> Mat Martineau
> Intel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-22  3:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 12:04 [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use menglong8.dong
2022-09-21 12:04 ` [PATCH mptcp-next v2 1/2] mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen() menglong8.dong
2022-09-21 12:04 ` [PATCH mptcp-next v2 2/2] mptcp: add statistics for mptcp socket in use menglong8.dong
2022-09-21 12:42   ` Matthieu Baerts
2022-09-21 12:52     ` Menglong Dong
2022-09-21 13:37   ` mptcp: add statistics for mptcp socket in use: Tests Results MPTCP CI
2022-09-22  0:03 ` [PATCH mptcp-next v2 0/2] mptcp: add statistics for mptcp socket in use Mat Martineau
2022-09-22  3:48   ` Menglong Dong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).