]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tcp: add newval parameter to tcp_rcvbuf_grow()
authorEric Dumazet <edumazet@google.com>
Tue, 28 Oct 2025 11:58:01 +0000 (12:58 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 30 Oct 2025 00:30:19 +0000 (17:30 -0700)
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>
include/net/tcp.h
net/ipv4/tcp_input.c
net/mptcp/protocol.c

index 5ca230ed526ae02711e8d2a409b91664b73390f2..ab20f549b8f9143671b75ed0a3f87d64b9e73583 100644 (file)
@@ -370,7 +370,7 @@ void tcp_delack_timer_handler(struct sock *sk);
 int tcp_ioctl(struct sock *sk, int cmd, int *karg);
 enum skb_drop_reason tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb);
 void tcp_rcv_established(struct sock *sk, struct sk_buff *skb);
-void tcp_rcvbuf_grow(struct sock *sk);
+void tcp_rcvbuf_grow(struct sock *sk, u32 newval);
 void tcp_rcv_space_adjust(struct sock *sk);
 int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp);
 void tcp_twsk_destructor(struct sock *sk);
index 31ea5af49f2dc8a6f95f3f8c24065369765b8987..cb4e07f84ae2e4fd33555f36e8bf7919d34b550b 100644 (file)
@@ -891,18 +891,20 @@ static inline void tcp_rcv_rtt_measure_ts(struct sock *sk,
        }
 }
 
-void tcp_rcvbuf_grow(struct sock *sk)
+void tcp_rcvbuf_grow(struct sock *sk, u32 newval)
 {
        const struct net *net = sock_net(sk);
        struct tcp_sock *tp = tcp_sk(sk);
-       int rcvwin, rcvbuf, cap;
+       u32 rcvwin, rcvbuf, cap;
+
+       tp->rcvq_space.space = newval;
 
        if (!READ_ONCE(net->ipv4.sysctl_tcp_moderate_rcvbuf) ||
            (sk->sk_userlocks & SOCK_RCVBUF_LOCK))
                return;
 
        /* slow start: allow the sender to double its rate. */
-       rcvwin = tp->rcvq_space.space << 1;
+       rcvwin = newval << 1;
 
        if (!RB_EMPTY_ROOT(&tp->out_of_order_queue))
                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)
 
        trace_tcp_rcvbuf_grow(sk, time);
 
-       tp->rcvq_space.space = copied;
-
-       tcp_rcvbuf_grow(sk);
+       tcp_rcvbuf_grow(sk, copied);
 
 new_measure:
        tp->rcvq_space.seq = tp->copied_seq;
@@ -5270,7 +5270,7 @@ end:
        }
        /* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */
        if (sk->sk_socket)
-               tcp_rcvbuf_grow(sk);
+               tcp_rcvbuf_grow(sk, tp->rcvq_space.space);
 }
 
 static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,
index a8a3bdf955437e90ff58624cff4e4b9d54daf015..052a0c62023ffcc2cc17e81fd15b3ec0ad5107c0 100644 (file)
@@ -194,17 +194,18 @@ static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
  * - mptcp does not maintain a msk-level window clamp
  * - returns true when  the receive buffer is actually updated
  */
-static bool mptcp_rcvbuf_grow(struct sock *sk)
+static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval)
 {
        struct mptcp_sock *msk = mptcp_sk(sk);
        const struct net *net = sock_net(sk);
-       int rcvwin, rcvbuf, cap;
+       u32 rcvwin, rcvbuf, cap;
 
+       msk->rcvq_space.space = newval;
        if (!READ_ONCE(net->ipv4.sysctl_tcp_moderate_rcvbuf) ||
            (sk->sk_userlocks & SOCK_RCVBUF_LOCK))
                return false;
 
-       rcvwin = msk->rcvq_space.space << 1;
+       rcvwin = newval << 1;
 
        if (!RB_EMPTY_ROOT(&msk->out_of_order_queue))
                rcvwin += MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq - msk->ack_seq;
@@ -334,7 +335,7 @@ end:
        skb_set_owner_r(skb, sk);
        /* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */
        if (sk->sk_socket)
-               mptcp_rcvbuf_grow(sk);
+               mptcp_rcvbuf_grow(sk, msk->rcvq_space.space);
 }
 
 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)
        if (msk->rcvq_space.copied <= msk->rcvq_space.space)
                goto new_measure;
 
-       msk->rcvq_space.space = msk->rcvq_space.copied;
-       if (mptcp_rcvbuf_grow(sk)) {
-               int copied = msk->rcvq_space.copied;
-
+       if (mptcp_rcvbuf_grow(sk, msk->rcvq_space.copied)) {
                /* Make subflows follow along.  If we do not do this, we
                 * get drops at subflow level if skbs can't be moved to
                 * 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)
                        ssk = mptcp_subflow_tcp_sock(subflow);
                        slow = lock_sock_fast(ssk);
                        /* subflows can be added before tcp_init_transfer() */
-                       if (tcp_sk(ssk)->rcvq_space.space) {
-                               tcp_sk(ssk)->rcvq_space.space = copied;
-                               tcp_rcvbuf_grow(ssk);
-                       }
+                       if (tcp_sk(ssk)->rcvq_space.space)
+                               tcp_rcvbuf_grow(ssk, msk->rcvq_space.copied);
                        unlock_sock_fast(ssk, slow);
                }
        }