* [MPTCP] [PATCH v3 3/6] mptcp: add rmem queue accounting
@ 2020-02-20 14:34 Florian Westphal
0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2020-02-20 14:34 UTC (permalink / raw)
To: mptcp
[-- Attachment #1: Type: text/plain, Size: 2017 bytes --]
If userspace never drains the receive buffers we must stop draining
the subflow socket(s) at some point.
This adds the needed rmem accouting for this.
If the threshold is reached, we stop draining the subflows.
Signed-off-by: Florian Westphal <fw(a)strlen.de>
---
net/mptcp/protocol.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 85d7f73ca804..ac81283d5ec3 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -172,6 +172,10 @@ void mptcp_data_ready(struct sock *sk)
if (test_and_set_bit(MPTCP_WORK_DATA_READY, &msk->flags))
return;
+ /* don't schedule if mptcp sk is (still) over limit */
+ if (atomic_read(&sk->sk_rmem_alloc) > READ_ONCE(sk->sk_rcvbuf))
+ return;
+
sock_hold(sk);
if (!schedule_work(&msk->rtx_work))
sock_put(sk);
@@ -699,7 +703,7 @@ static void __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
struct sock *sk = (struct sock *)msk;
__skb_unlink(skb, &ssk->sk_receive_queue);
- skb_orphan(skb);
+ skb_set_owner_r(skb, sk);
__skb_queue_tail(&sk->sk_receive_queue, skb);
msk->ack_seq += copy_len;
@@ -717,6 +721,7 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
struct sock *ssk;
bool more_data_avail;
struct tcp_sock *tp;
+ int rcvbuf;
ssk = mptcp_subflow_recv_lookup(msk);
if (!ssk)
@@ -726,6 +731,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
lock_sock(ssk);
+ rcvbuf = max(ssk->sk_rcvbuf, sk->sk_rcvbuf);
+ if (rcvbuf > sk->sk_rcvbuf)
+ sk->sk_rcvbuf = rcvbuf;
+
tp = tcp_sk(ssk);
do {
u32 map_remaining, offset;
@@ -741,6 +750,11 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
if (!skb)
break;
+ if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
+ done = true;
+ break;
+ }
+
offset = seq - TCP_SKB_CB(skb)->seq;
fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
if (fin) {
--
2.24.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* [MPTCP] [PATCH v3 3/6] mptcp: add rmem queue accounting
@ 2020-02-18 12:21 Florian Westphal
0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2020-02-18 12:21 UTC (permalink / raw)
To: mptcp
[-- Attachment #1: Type: text/plain, Size: 1836 bytes --]
v2: adjust rcvbuf outside of loop.
Signed-off-by: Florian Westphal <fw(a)strlen.de>
---
net/mptcp/protocol.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 85d7f73ca804..ac81283d5ec3 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -172,6 +172,10 @@ void mptcp_data_ready(struct sock *sk)
if (test_and_set_bit(MPTCP_WORK_DATA_READY, &msk->flags))
return;
+ /* don't schedule if mptcp sk is (still) over limit */
+ if (atomic_read(&sk->sk_rmem_alloc) > READ_ONCE(sk->sk_rcvbuf))
+ return;
+
sock_hold(sk);
if (!schedule_work(&msk->rtx_work))
sock_put(sk);
@@ -699,7 +703,7 @@ static void __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
struct sock *sk = (struct sock *)msk;
__skb_unlink(skb, &ssk->sk_receive_queue);
- skb_orphan(skb);
+ skb_set_owner_r(skb, sk);
__skb_queue_tail(&sk->sk_receive_queue, skb);
msk->ack_seq += copy_len;
@@ -717,6 +721,7 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
struct sock *ssk;
bool more_data_avail;
struct tcp_sock *tp;
+ int rcvbuf;
ssk = mptcp_subflow_recv_lookup(msk);
if (!ssk)
@@ -726,6 +731,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
lock_sock(ssk);
+ rcvbuf = max(ssk->sk_rcvbuf, sk->sk_rcvbuf);
+ if (rcvbuf > sk->sk_rcvbuf)
+ sk->sk_rcvbuf = rcvbuf;
+
tp = tcp_sk(ssk);
do {
u32 map_remaining, offset;
@@ -741,6 +750,11 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
if (!skb)
break;
+ if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
+ done = true;
+ break;
+ }
+
offset = seq - TCP_SKB_CB(skb)->seq;
fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
if (fin) {
--
2.24.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-20 14:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-20 14:34 [MPTCP] [PATCH v3 3/6] mptcp: add rmem queue accounting Florian Westphal
-- strict thread matches above, loose matches on Subject: below --
2020-02-18 12:21 Florian Westphal
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.