All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] [PRE-RFC 3/6] mptcp: update msk unacked sequence in sendmsg()
@ 2019-08-16 16:48 Paolo Abeni
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Abeni @ 2019-08-16 16:48 UTC (permalink / raw)
  To: mptcp 

[-- Attachment #1: Type: text/plain, Size: 3235 bytes --]

We need to walk all the subflows to update the msk unacked; so we
try to avoid doing it too often using the following heuristic:
we do the update only when the current value is outside the current
subflow's window size.

Note that any retransmission policy must be consistent with the above
heuristic.

Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 38 ++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h |  1 +
 2 files changed, 39 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 5b7ddbe64e4b..b7468f770d25 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -67,6 +67,40 @@ static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,
 	return mpext && mpext->data_seq + mpext->data_len == msk->write_seq;
 }
 
+static u64 mptcp_update_msk_una(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct subflow_context *subflow;
+	u64 snd_una = msk->snd_una;
+
+	mptcp_for_each_subflow(msk, subflow) {
+		u64 subflow_snd_una = READ_ONCE(subflow->snd_una);
+
+		if (after64(subflow_snd_una, snd_una))
+			snd_una = subflow_snd_una;
+	}
+	msk->snd_una = snd_una;
+	return snd_una;
+}
+
+static void mptcp_update_subflow_una(struct sock *sk, struct sock *ssk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct subflow_context *subflow;
+	u64 snd_una = msk->snd_una;
+
+	/* heuristic to avoid doing the expensive data ack update frequently */
+	if (snd_una + tcp_sk(sk)->snd_cwnd <= msk->write_seq)
+		snd_una = mptcp_update_msk_una(sk);
+
+	/* if we msk just switched to this subflow, update subflow's una
+	 * to allow 32 bit ack update to be more accurate
+	 */
+	subflow = subflow_ctx(ssk);
+	if (after64(snd_una, subflow->snd_una))
+		subflow->snd_una = snd_una;
+}
+
 static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 			      struct msghdr *msg, long *timeo, int *pmss_now,
 			      int *ps_goal)
@@ -209,6 +243,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	}
 
 	lock_sock(ssk);
+	mptcp_update_subflow_una(sk, ssk);
+
 	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
 	while (msg_data_left(msg)) {
 		ret = mptcp_sendmsg_frag(sk, ssk, msg, &timeo, &mss_now,
@@ -668,6 +704,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
+		msk->snd_una = msk->write_seq;
 		ack_seq++;
 		msk->ack_seq = ack_seq;
 		subflow->map_seq = ack_seq;
@@ -804,6 +841,7 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
+		msk->snd_una = msk->write_seq;
 		ack_seq++;
 		msk->ack_seq = ack_seq;
 		subflow->map_seq = ack_seq;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index e37fd4bcd904..9220afe0d362 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -116,6 +116,7 @@ struct mptcp_sock {
 	u64		remote_key;
 	u64		write_seq;
 	u64		ack_seq;
+	u64		snd_una;
 	u32		token;
 	u16		dport;
 	struct list_head conn_list;
-- 
2.20.1


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

* Re: [MPTCP] [PRE-RFC 3/6] mptcp: update msk unacked sequence in sendmsg()
@ 2019-08-19 11:09 Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2019-08-19 11:09 UTC (permalink / raw)
  To: mptcp 

[-- Attachment #1: Type: text/plain, Size: 560 bytes --]

Paolo Abeni <pabeni(a)redhat.com> wrote:
> +	/* heuristic to avoid doing the expensive data ack update frequently */
> +	if (snd_una + tcp_sk(sk)->snd_cwnd <= msk->write_seq)
> +		snd_una = mptcp_update_msk_una(sk);

I think this will need to protect against sequence wraparound.

> +	/* if we msk just switched to this subflow, update subflow's una
> +	 * to allow 32 bit ack update to be more accurate
> +	 */
> +	subflow = subflow_ctx(ssk);
> +	if (after64(snd_una, subflow->snd_una))
> +		subflow->snd_una = snd_una;

... like you did here.

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

end of thread, other threads:[~2019-08-19 11:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-19 11:09 [MPTCP] [PRE-RFC 3/6] mptcp: update msk unacked sequence in sendmsg() Florian Westphal
  -- strict thread matches above, loose matches on Subject: below --
2019-08-16 16:48 Paolo Abeni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.