Commit da51aef5 authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

mptcp: basic sndbuf autotuning

Let the msk sendbuf track the size of the larger subflow's
send window, so that we ensure mptcp_sendmsg() does not
exceed MPTCP-level send window.

The update is performed just before try to send any data.
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Reviewed-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6719331c
...@@ -856,7 +856,8 @@ static void mptcp_nospace(struct mptcp_sock *msk) ...@@ -856,7 +856,8 @@ static void mptcp_nospace(struct mptcp_sock *msk)
} }
} }
static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk) static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk,
u32 *sndbuf)
{ {
struct mptcp_subflow_context *subflow; struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk; struct sock *sk = (struct sock *)msk;
...@@ -865,6 +866,7 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk) ...@@ -865,6 +866,7 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
sock_owned_by_me(sk); sock_owned_by_me(sk);
*sndbuf = 0;
if (!mptcp_ext_cache_refill(msk)) if (!mptcp_ext_cache_refill(msk))
return NULL; return NULL;
...@@ -877,6 +879,7 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk) ...@@ -877,6 +879,7 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
return NULL; return NULL;
} }
*sndbuf = max(tcp_sk(ssk)->snd_wnd, *sndbuf);
if (subflow->backup) { if (subflow->backup) {
if (!backup) if (!backup)
backup = ssk; backup = ssk;
...@@ -903,6 +906,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -903,6 +906,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
struct page_frag *pfrag; struct page_frag *pfrag;
size_t copied = 0; size_t copied = 0;
struct sock *ssk; struct sock *ssk;
u32 sndbuf;
bool tx_ok; bool tx_ok;
long timeo; long timeo;
...@@ -929,7 +933,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -929,7 +933,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
} }
__mptcp_flush_join_list(msk); __mptcp_flush_join_list(msk);
ssk = mptcp_subflow_get_send(msk); ssk = mptcp_subflow_get_send(msk, &sndbuf);
while (!sk_stream_memory_free(sk) || while (!sk_stream_memory_free(sk) ||
!ssk || !ssk ||
!mptcp_page_frag_refill(ssk, pfrag)) { !mptcp_page_frag_refill(ssk, pfrag)) {
...@@ -953,13 +957,18 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -953,13 +957,18 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
mptcp_clean_una(sk); mptcp_clean_una(sk);
ssk = mptcp_subflow_get_send(msk); ssk = mptcp_subflow_get_send(msk, &sndbuf);
if (list_empty(&msk->conn_list)) { if (list_empty(&msk->conn_list)) {
ret = -ENOTCONN; ret = -ENOTCONN;
goto out; goto out;
} }
} }
/* do auto tuning */
if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK) &&
sndbuf > READ_ONCE(sk->sk_sndbuf))
WRITE_ONCE(sk->sk_sndbuf, sndbuf);
pr_debug("conn_list->subflow=%p", ssk); pr_debug("conn_list->subflow=%p", ssk);
lock_sock(ssk); lock_sock(ssk);
...@@ -1547,7 +1556,7 @@ static int mptcp_init_sock(struct sock *sk) ...@@ -1547,7 +1556,7 @@ static int mptcp_init_sock(struct sock *sk)
sk_sockets_allocated_inc(sk); sk_sockets_allocated_inc(sk);
sk->sk_rcvbuf = sock_net(sk)->ipv4.sysctl_tcp_rmem[1]; sk->sk_rcvbuf = sock_net(sk)->ipv4.sysctl_tcp_rmem[1];
sk->sk_sndbuf = sock_net(sk)->ipv4.sysctl_tcp_wmem[2]; sk->sk_sndbuf = sock_net(sk)->ipv4.sysctl_tcp_wmem[1];
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment