Skip to content

Commit b1e014a

Browse files
edumazetkuba-moo
authored andcommitted
tcp: add newval parameter to tcp_rcvbuf_grow()
This patch has no functional change, and prepares the following one. tcp_rcvbuf_grow() will need to have access to tp->rcvq_space.space old and new values. Change mptcp_rcvbuf_grow() in a similar way. Signed-off-by: Eric Dumazet <edumazet@google.com> [ Moved 'oldval' declaration to the next patch to avoid warnings at build time. ] Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Reviewed-by: Neal Cardwell <ncardwell@google.com> Link: https://patch.msgid.link/20251028-net-tcp-recv-autotune-v3-3-74b43ba4c84c@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 24990d8 commit b1e014a

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

include/net/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void tcp_delack_timer_handler(struct sock *sk);
370370
int tcp_ioctl(struct sock *sk, int cmd, int *karg);
371371
enum skb_drop_reason tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb);
372372
void tcp_rcv_established(struct sock *sk, struct sk_buff *skb);
373-
void tcp_rcvbuf_grow(struct sock *sk);
373+
void tcp_rcvbuf_grow(struct sock *sk, u32 newval);
374374
void tcp_rcv_space_adjust(struct sock *sk);
375375
int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp);
376376
void tcp_twsk_destructor(struct sock *sk);

net/ipv4/tcp_input.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -891,18 +891,20 @@ static inline void tcp_rcv_rtt_measure_ts(struct sock *sk,
891891
}
892892
}
893893

894-
void tcp_rcvbuf_grow(struct sock *sk)
894+
void tcp_rcvbuf_grow(struct sock *sk, u32 newval)
895895
{
896896
const struct net *net = sock_net(sk);
897897
struct tcp_sock *tp = tcp_sk(sk);
898-
int rcvwin, rcvbuf, cap;
898+
u32 rcvwin, rcvbuf, cap;
899+
900+
tp->rcvq_space.space = newval;
899901

900902
if (!READ_ONCE(net->ipv4.sysctl_tcp_moderate_rcvbuf) ||
901903
(sk->sk_userlocks & SOCK_RCVBUF_LOCK))
902904
return;
903905

904906
/* slow start: allow the sender to double its rate. */
905-
rcvwin = tp->rcvq_space.space << 1;
907+
rcvwin = newval << 1;
906908

907909
if (!RB_EMPTY_ROOT(&tp->out_of_order_queue))
908910
rcvwin += TCP_SKB_CB(tp->ooo_last_skb)->end_seq - tp->rcv_nxt;
@@ -943,9 +945,7 @@ void tcp_rcv_space_adjust(struct sock *sk)
943945

944946
trace_tcp_rcvbuf_grow(sk, time);
945947

946-
tp->rcvq_space.space = copied;
947-
948-
tcp_rcvbuf_grow(sk);
948+
tcp_rcvbuf_grow(sk, copied);
949949

950950
new_measure:
951951
tp->rcvq_space.seq = tp->copied_seq;
@@ -5270,7 +5270,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
52705270
}
52715271
/* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */
52725272
if (sk->sk_socket)
5273-
tcp_rcvbuf_grow(sk);
5273+
tcp_rcvbuf_grow(sk, tp->rcvq_space.space);
52745274
}
52755275

52765276
static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,

net/mptcp/protocol.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,18 @@ static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
194194
* - mptcp does not maintain a msk-level window clamp
195195
* - returns true when the receive buffer is actually updated
196196
*/
197-
static bool mptcp_rcvbuf_grow(struct sock *sk)
197+
static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval)
198198
{
199199
struct mptcp_sock *msk = mptcp_sk(sk);
200200
const struct net *net = sock_net(sk);
201-
int rcvwin, rcvbuf, cap;
201+
u32 rcvwin, rcvbuf, cap;
202202

203+
msk->rcvq_space.space = newval;
203204
if (!READ_ONCE(net->ipv4.sysctl_tcp_moderate_rcvbuf) ||
204205
(sk->sk_userlocks & SOCK_RCVBUF_LOCK))
205206
return false;
206207

207-
rcvwin = msk->rcvq_space.space << 1;
208+
rcvwin = newval << 1;
208209

209210
if (!RB_EMPTY_ROOT(&msk->out_of_order_queue))
210211
rcvwin += MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq - msk->ack_seq;
@@ -334,7 +335,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
334335
skb_set_owner_r(skb, sk);
335336
/* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */
336337
if (sk->sk_socket)
337-
mptcp_rcvbuf_grow(sk);
338+
mptcp_rcvbuf_grow(sk, msk->rcvq_space.space);
338339
}
339340

340341
static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
@@ -2049,10 +2050,7 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)
20492050
if (msk->rcvq_space.copied <= msk->rcvq_space.space)
20502051
goto new_measure;
20512052

2052-
msk->rcvq_space.space = msk->rcvq_space.copied;
2053-
if (mptcp_rcvbuf_grow(sk)) {
2054-
int copied = msk->rcvq_space.copied;
2055-
2053+
if (mptcp_rcvbuf_grow(sk, msk->rcvq_space.copied)) {
20562054
/* Make subflows follow along. If we do not do this, we
20572055
* get drops at subflow level if skbs can't be moved to
20582056
* the mptcp rx queue fast enough (announced rcv_win can
@@ -2065,10 +2063,8 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)
20652063
ssk = mptcp_subflow_tcp_sock(subflow);
20662064
slow = lock_sock_fast(ssk);
20672065
/* subflows can be added before tcp_init_transfer() */
2068-
if (tcp_sk(ssk)->rcvq_space.space) {
2069-
tcp_sk(ssk)->rcvq_space.space = copied;
2070-
tcp_rcvbuf_grow(ssk);
2071-
}
2066+
if (tcp_sk(ssk)->rcvq_space.space)
2067+
tcp_rcvbuf_grow(ssk, msk->rcvq_space.copied);
20722068
unlock_sock_fast(ssk, slow);
20732069
}
20742070
}

0 commit comments

Comments
 (0)