Skip to contentSkip to conversation

mptcp: use _fast lock version in __mptcp_move_skbs

PATCH In review Florian Westphal 3 participants 5 messages Sep 2, 2020 – Sep 4, 2020

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author
#0 lore raw

PATCH 1/1 mptcp: use _fast lock version in __mptcp_move_skbs

The function is short and won't sleep, so this can use the _fast version.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +3 -2
index 3b621a99c8c5..0c2b506d17de 100644
@@ -1472,13 +1472,14 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	__mptcp_flush_join_list(msk);
 	do {
 		struct sock *ssk = mptcp_subflow_recv_lookup(msk);
+		bool slowpath;
 
 		if (!ssk)
 			break;
 
-		lock_sock(ssk);
+		slowpath = lock_sock_fast(ssk);
 		done = __mptcp_move_skbs_from_subflow(msk, ssk, &moved);
-		release_sock(ssk);
+		unlock_sock_fast(ssk, slowpath);
 	} while (!done);
 
 	if (mptcp_ofo_queue(msk) || moved > 0) {
Signature · 1 line
2.26.2
#1 lore raw
Quoted 18 lines · Florian Westphal

The function is short and won't sleep, so this can use the _fast version.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +1 -0
index 3b621a99c8c5..0c2b506d17de 100644
@@ -1472,13 +1472,14 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	__mptcp_flush_join_list(msk);
 	do {
 		struct sock *ssk = mptcp_subflow_recv_lookup(msk);
+		bool slowpath;
 
 		if (!ssk)

net/mptcp/protocol.c static bool __mptcp_move_skbs(struct mptcp_sock *msk) · line 1485

Quoted 10 lines
net/mptcp/protocol.c +2 -2
 			break;
 
-		lock_sock(ssk);
+		slowpath = lock_sock_fast(ssk);
 		done = __mptcp_move_skbs_from_subflow(msk, ssk, &moved);
-		release_sock(ssk);
+		unlock_sock_fast(ssk, slowpath);
 	} while (!done);
 
 	if (mptcp_ofo_queue(msk) || moved > 0) {

Good catch! the patch LGTM, thanks!

Do you think it could useful do the same also in mptcp_sendmsg() and mptcp_worker()? (since mptcp_sendmsg_frag() does not sleep, should be possible...)

Cheers,

Paolo

author
#2 lore raw
Quoted 28 lines · Paolo Abeni
Quoted 27 lines · Florian Westphal

The function is short and won't sleep, so this can use the _fast version.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +3 -2
index 3b621a99c8c5..0c2b506d17de 100644
@@ -1472,13 +1472,14 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	__mptcp_flush_join_list(msk);
 	do {
 		struct sock *ssk = mptcp_subflow_recv_lookup(msk);
+		bool slowpath;
 
 		if (!ssk)
 			break;
 
-		lock_sock(ssk);
+		slowpath = lock_sock_fast(ssk);
 		done = __mptcp_move_skbs_from_subflow(msk, ssk, &moved);
-		release_sock(ssk);
+		unlock_sock_fast(ssk, slowpath);
 	} while (!done);
 
Quoted 7 lines

net/mptcp/protocol.c static bool __mptcp_move_skbs(struct mptcp_sock *msk) · line 1485

Quoted 1 line
net/mptcp/protocol.c +0 -0
 	if (mptcp_ofo_queue(msk) || moved > 0) {

Good catch! the patch LGTM, thanks!

Do you think it could useful do the same also in mptcp_sendmsg() and mptcp_worker()? (since mptcp_sendmsg_frag() does not sleep, should be possible...)

sendmsg path might sleep (it copies data from userspace).

mptcp_worker might work, but I think we would need to make sure mptcp_ext_cache_refill() uses atomic allocations for this to work.

Not sure this is a good idea. For work queue case I think its better to try to make it a true slowpath that isn't invoked frequently.

#3 lore raw
Quoted 33 lines · Florian Westphal
Quoted 32 lines · Paolo Abeni
Quoted 18 lines · Florian Westphal

The function is short and won't sleep, so this can use the _fast version.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +1 -0
index 3b621a99c8c5..0c2b506d17de 100644
@@ -1472,13 +1472,14 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	__mptcp_flush_join_list(msk);
 	do {
 		struct sock *ssk = mptcp_subflow_recv_lookup(msk);
+		bool slowpath;
 
 		if (!ssk)

net/mptcp/protocol.c static bool __mptcp_move_skbs(struct mptcp_sock *msk) · line 1485

Quoted 10 lines
net/mptcp/protocol.c +2 -2
 			break;
 
-		lock_sock(ssk);
+		slowpath = lock_sock_fast(ssk);
 		done = __mptcp_move_skbs_from_subflow(msk, ssk, &moved);
-		release_sock(ssk);
+		unlock_sock_fast(ssk, slowpath);
 	} while (!done);
 
 	if (mptcp_ofo_queue(msk) || moved > 0) {

Good catch! the patch LGTM, thanks!

Quoted 5 lines
Quoted 3 lines

Do you think it could useful do the same also in mptcp_sendmsg() and mptcp_worker()? (since mptcp_sendmsg_frag() does not sleep, should be possible...)

sendmsg path might sleep (it copies data from userspace).

Whoops I missed that.

Quoted 5 lines

mptcp_worker might work, but I think we would need to make sure mptcp_ext_cache_refill() uses atomic allocations for this to work.

Not sure this is a good idea. For work queue case I think its better to try to make it a true slowpath that isn't invoked frequently.

Agreed, we really don't want to over-optimize the worker

I'm fine with this, thanks!

Paolo

#4 lore raw

Hi Florian, Paolo,

Quoted 6 lines · Paolo Abeni
Quoted 5 lines · Florian Westphal
Quoted 4 lines · Paolo Abeni
Quoted 3 lines · Florian Westphal

The function is short and won't sleep, so this can use the _fast version.

Signed-off-by Florian Westphal <fw(a)strlen.de>

(...)

Quoted 13 lines
Quoted 7 lines
Quoted 5 lines

Good catch! the patch LGTM, thanks!

Do you think it could useful do the same also in mptcp_sendmsg() and mptcp_worker()? (since mptcp_sendmsg_frag() does not sleep, should be possible...)

sendmsg path might sleep (it copies data from userspace).

Whoops I missed that.

Quoted 3 lines

mptcp_worker might work, but I think we would need to make sure mptcp_ext_cache_refill() uses atomic allocations for this to work.

Quoted 6 lines
Quoted 2 lines

Not sure this is a good idea. For work queue case I think its better to try to make it a true slowpath that isn't invoked frequently.

Agreed, we really don't want to over-optimize the worker

I'm fine with this, thanks!

Thank you for the patch and the review!

Just added at the end of the series!

Tests + export are in progress.

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net