mptcp: adjust mptcp receive buffer limit if subflow has larger one
Subsystems (2)
Florian Westphal
PATCH 1/1 mptcp: adjust mptcp receive buffer limit if subflow has larger one
In addition to tcp autotuning during read, it may also increase the receive buffer in tcp_clamp_window().
In this case, mptcp should adjust its receive buffer size as well so it can pull all pending skbs at once.
At this time, when TCP grows its receive buffer, it may have more skbs ready for processing than what mptcp allows.
In the mptcp case, the receive window is derived from free space of the mptcp parent socket instead of the individual subflows. Following the subflow allows mptcp to grow its receive buffer.
This is especially noticable for loopback traffic, when even two skbs are enough to fill the initial receive window.
--- net/mptcp/protocol.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +11 -4
@@ -603,6 +603,7 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);struct mptcp_sock *msk =mptcp_sk (sk); +int sk_rbuf, ssk_rbuf;bool wake;/* move_skbs_to_msk below can legitly clear the data_avail flag,
@@ -613,12 +614,18 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)if (wake)set_bit (MPTCP_DATA_READY , &msk->flags); -if (atomic_read (&sk->sk_rmem_alloc) <READ_ONCE (sk->sk_rcvbuf) && -move_skbs_to_msk (msk, ssk)) + sk_rbuf =READ_ONCE (sk->sk_rcvbuf); + ssk_rbuf =READ_ONCE (ssk->sk_rcvbuf); +if (ssk_rbuf > sk_rbuf) { +WRITE_ONCE (sk->sk_rcvbuf, ssk_rbuf); + sk_rbuf = ssk_rbuf; + } + +/* over limit? can't append more skbs to msk */ +if (atomic_read (&sk->sk_rmem_alloc) > sk_rbuf) goto wake; -/* don't schedule if mptcp sk is (still) over limit */ -if (atomic_read (&sk->sk_rmem_alloc) >READ_ONCE (sk->sk_rcvbuf)) +if (move_skbs_to_msk (msk, ssk)) goto wake;/* mptcp socket is owned, release_cb should retry */
Signature · 1 line
2.26.2
Mat Martineau
Quoted 34 lines · Florian Westphal
In addition to tcp autotuning during read, it may also increase the receive buffer in
tcp_clamp_window().In this case, mptcp should adjust its receive buffer size as well so it can pull all pending skbs at once.
At this time, when TCP grows its receive buffer, it may have more skbs ready for processing than what mptcp allows.
In the mptcp case, the receive window is derived from free space of the mptcp parent socket instead of the individual subflows. Following the subflow allows mptcp to grow its receive buffer.
This is especially noticable for loopback traffic, when even two skbs are enough to fill the initial receive window.
Signed-off-by Florian Westphal <fw(a)strlen.de>---
net/mptcp/protocol.c| 15 +++++++++++----1 file changed, 11 insertions(+), 4 deletions(-)net/mptcp/protocol.c +1
-0@@ -603,6 +603,7 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);struct mptcp_sock *msk =mptcp_sk (sk); +int sk_rbuf, ssk_rbuf;bool wake;/* move_skbs_to_msk below can legitly clear the data_avail flag,
net/mptcp/protocol.c void mptcp_data_ready(struct sock *sk, struct sock *ssk) · line 620
Quoted 9 lines
net/mptcp/protocol.c +4
-2@@ -613,12 +614,18 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)if (wake)set_bit (MPTCP_DATA_READY , &msk->flags); -if (atomic_read (&sk->sk_rmem_alloc) <READ_ONCE (sk->sk_rcvbuf) && -move_skbs_to_msk (msk, ssk)) + sk_rbuf =READ_ONCE (sk->sk_rcvbuf); + ssk_rbuf =READ_ONCE (ssk->sk_rcvbuf); +if (ssk_rbuf > sk_rbuf) { +WRITE_ONCE (sk->sk_rcvbuf, ssk_rbuf);
Any concern about this racing with updates to sk->sk_rcvbuf assignment (with lock held) in mptcp_rcv_space_adjust() or other subflows concurrently calling mptcp_data_ready?
Quoted 15 lines
net/mptcp/protocol.c +6
-2+ sk_rbuf = ssk_rbuf; + } + +/* over limit? can't append more skbs to msk */ +if (atomic_read (&sk->sk_rmem_alloc) > sk_rbuf) goto wake; -/* don't schedule if mptcp sk is (still) over limit */ -if (atomic_read (&sk->sk_rmem_alloc) >READ_ONCE (sk->sk_rcvbuf)) +if (move_skbs_to_msk (msk, ssk)) goto wake;/* mptcp socket is owned, release_cb should retry */ Signature · 1 line
2.26.2
--
Mat Martineau
Intel
Florian Westphal
Quoted 37 lines · Mat Martineau
Quoted 37 lines
In addition to tcp autotuning during read, it may also increase the receive buffer in
tcp_clamp_window().In this case, mptcp should adjust its receive buffer size as well so it can pull all pending skbs at once.
At this time, when TCP grows its receive buffer, it may have more skbs ready for processing than what mptcp allows.
In the mptcp case, the receive window is derived from free space of the mptcp parent socket instead of the individual subflows. Following the subflow allows mptcp to grow its receive buffer.
This is especially noticable for loopback traffic, when even two skbs are enough to fill the initial receive window.
Signed-off-by Florian Westphal <fw(a)strlen.de>---
net/mptcp/protocol.c| 15 +++++++++++----1 file changed, 11 insertions(+), 4 deletions(-)net/mptcp/protocol.c +1
-0@@ -603,6 +603,7 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);struct mptcp_sock *msk =mptcp_sk (sk); +int sk_rbuf, ssk_rbuf;bool wake;/* move_skbs_to_msk below can legitly clear the data_avail flag, @@ -613,12 +614,18 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)if (wake)set_bit (MPTCP_DATA_READY , &msk->flags);
Quoted 10 lines
net/mptcp/protocol.c void mptcp_data_ready(struct sock *sk, struct sock *ssk) · line 620
Quoted 6 lines
net/mptcp/protocol.c +4
-2-if (atomic_read (&sk->sk_rmem_alloc) <READ_ONCE (sk->sk_rcvbuf) && -move_skbs_to_msk (msk, ssk)) + sk_rbuf =READ_ONCE (sk->sk_rcvbuf); + ssk_rbuf =READ_ONCE (ssk->sk_rcvbuf); +if (ssk_rbuf > sk_rbuf) { +WRITE_ONCE (sk->sk_rcvbuf, ssk_rbuf);Any concern about this racing with updates to
sk->sk_rcvbufassignment (with lock held) inmptcp_rcv_space_adjust()or other subflows concurrently callingmptcp_data_ready?
THe only option I see ATM is to move the adjustment to when we move skbs from subflow to mptcp socket, since thats the only spot where we hold both mptcp and subflow socket locks.
Quoted 6 lines
net/mptcp/protocol.c void mptcp_data_ready(struct sock *sk, struct sock *ssk) · line 626
Quoted 6 lines
net/mptcp/protocol.c +5
-0+ sk_rbuf = ssk_rbuf; + } + +/* over limit? can't append more skbs to msk */ +if (atomic_read (&sk->sk_rmem_alloc) > sk_rbuf) goto wake;
To avoid this from short-ciruiting early, what about calculating the diff of ssk rcvbuf vs. mpcp rcvbuf space and use that as a "cushion"?
I think that this would avoid any racing access without adding complexity.
I'll give it a try.