From: Florian Westphal <fw@strlen.de>
To: <netdev@vger.kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>, Florian Westphal <fw@strlen.de>
Subject: [PATCH net-next 7/7] mptcp: defer work schedule until mptcp lock is released
Date: Wed, 26 Feb 2020 10:14:52 +0100 [thread overview]
Message-ID: <20200226091452.1116-8-fw@strlen.de> (raw)
In-Reply-To: <20200226091452.1116-1-fw@strlen.de>
From: Paolo Abeni <pabeni@redhat.com>
Don't schedule the work queue right away, instead defer this
to the lock release callback.
This has the advantage that it will give recv path a chance to
complete -- this might have moved all pending packets from the
subflow to the mptcp receive queue, which allows to avoid the
schedule_work().
Co-developed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/mptcp/protocol.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 70f20c8eddbd..044295707bbf 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -238,9 +238,16 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)
if (atomic_read(&sk->sk_rmem_alloc) > READ_ONCE(sk->sk_rcvbuf))
goto wake;
- if (schedule_work(&msk->work))
- sock_hold((struct sock *)msk);
+ /* mptcp socket is owned, release_cb should retry */
+ if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED,
+ &sk->sk_tsq_flags)) {
+ sock_hold(sk);
+ /* need to try again, its possible release_cb() has already
+ * been called after the test_and_set_bit() above.
+ */
+ move_skbs_to_msk(msk, ssk);
+ }
wake:
sk->sk_data_ready(sk);
}
@@ -941,6 +948,32 @@ static int mptcp_getsockopt(struct sock *sk, int level, int optname,
return -EOPNOTSUPP;
}
+#define MPTCP_DEFERRED_ALL TCPF_DELACK_TIMER_DEFERRED
+
+/* this is very alike tcp_release_cb() but we must handle differently a
+ * different set of events
+ */
+static void mptcp_release_cb(struct sock *sk)
+{
+ unsigned long flags, nflags;
+
+ do {
+ flags = sk->sk_tsq_flags;
+ if (!(flags & MPTCP_DEFERRED_ALL))
+ return;
+ nflags = flags & ~MPTCP_DEFERRED_ALL;
+ } while (cmpxchg(&sk->sk_tsq_flags, flags, nflags) != flags);
+
+ if (flags & TCPF_DELACK_TIMER_DEFERRED) {
+ struct mptcp_sock *msk = mptcp_sk(sk);
+ struct sock *ssk;
+
+ ssk = mptcp_subflow_recv_lookup(msk);
+ if (!ssk || !schedule_work(&msk->work))
+ __sock_put(sk);
+ }
+}
+
static int mptcp_get_port(struct sock *sk, unsigned short snum)
{
struct mptcp_sock *msk = mptcp_sk(sk);
@@ -1016,6 +1049,7 @@ static struct proto mptcp_prot = {
.destroy = mptcp_destroy,
.sendmsg = mptcp_sendmsg,
.recvmsg = mptcp_recvmsg,
+ .release_cb = mptcp_release_cb,
.hash = inet_hash,
.unhash = inet_unhash,
.get_port = mptcp_get_port,
--
2.24.1
next prev parent reply other threads:[~2020-02-26 9:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-26 9:14 [PATCH net-next 0/7] mptcp: update mptcp ack sequence outside of recv path Florian Westphal
2020-02-26 9:14 ` [PATCH net-next 1/7] mptcp: add and use mptcp_data_ready helper Florian Westphal
2020-02-27 0:09 ` Mat Martineau
2020-02-26 9:14 ` [PATCH net-next 2/7] mptcp: add work queue skeleton Florian Westphal
2020-02-27 0:10 ` Mat Martineau
2020-02-26 9:14 ` [PATCH net-next 3/7] mptcp: update mptcp ack sequence from work queue Florian Westphal
2020-02-27 0:10 ` Mat Martineau
2020-02-26 9:14 ` [PATCH net-next 4/7] mptcp: add rmem queue accounting Florian Westphal
2020-02-27 0:11 ` Mat Martineau
2020-02-26 9:14 ` [PATCH net-next 5/7] mptcp: remove mptcp_read_actor Florian Westphal
2020-02-27 0:11 ` Mat Martineau
2020-02-26 9:14 ` [PATCH net-next 6/7] mptcp: avoid work queue scheduling if possible Florian Westphal
2020-02-27 0:11 ` Mat Martineau
2020-02-26 9:14 ` Florian Westphal [this message]
2020-02-27 0:12 ` [PATCH net-next 7/7] mptcp: defer work schedule until mptcp lock is released Mat Martineau
2020-02-27 4:47 ` [PATCH net-next 0/7] mptcp: update mptcp ack sequence outside of recv path David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200226091452.1116-8-fw@strlen.de \
--to=fw@strlen.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).