tcp: update window_clamp when SO_RCVBUF is set
Subsystems (4)
Jakub Kicinski
maintainerPATCH 1/1 tcp: update window_clamp when SO_RCVBUF is set
Commit under Fixes moved recomputing the window clamp to tcp_measure_rcv_mss() (when scaling_ratio changes). I suspect it missed the fact that we don't recompute the clamp when rcvbuf is set. Until scaling_ratio changes we are stuck with the old window clamp which may be based on the small initial buffer. scaling_ratio may never change.
Inspired by Eric's recent commit d1361840f8c5 ("tcp: fix SO_RCVLOWAT and RCVBUF autotuning") plumb the user action thru to TCP and have it update the clamp.
A smaller fix would be to just have tcp_rcvbuf_grow() adjust the clamp even if SOCK_RCVBUF_LOCK is set. But IIUC this is what we were trying to get away from in the first place.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- include/linux/net.h | 1 + include/net/tcp.h | 1 + net/core/sock.c | 9 +++++++++ net/ipv4/af_inet.c | 1 + net/ipv4/tcp.c | 5 +++++ net/ipv6/af_inet6.c | 1 + 6 files changed, 18 insertions(+)
include/linux/net.h +1 -0
@@ -223,6 +223,7 @@ struct proto_ops {int (*sendmsg_locked)(struct sock *sk,struct msghdr *msg,size_t size);int (*set_rcvlowat)(struct sock *sk,int val); +void (*set_rcvbuf)(struct sock *sk,int val); };#define DECLARE_SOCKADDR (type, dst, src) \
include/net/tcp.h +1 -0
@@ -516,6 +516,7 @@ void tcp_syn_ack_timeout(const struct request_sock *req);int tcp_recvmsg (struct sock *sk,struct msghdr *msg,size_t len,int flags);int tcp_set_rcvlowat (struct sock *sk,int val); +void tcp_set_rcvbuf (struct sock *sk,int val);int tcp_set_window_clamp (struct sock *sk,int val); static inline void
net/core/sock.c +9 -0
@@ -973,6 +973,8 @@ EXPORT_SYMBOL(sock_set_keepalive);static void __sock_set_rcvbuf (struct sock *sk,int val) { +struct socket *sock = sk->sk_socket; +/* Ensure val * 2 fits into an int, to prevent max_t() from treating it * as a negative value. */
@@ -990,6 +992,13 @@ static void __sock_set_rcvbuf(struct sock *sk, int val)* we actually used in getsockopt is the most desirable behavior. */ WRITE_ONCE (sk->sk_rcvbuf,max_t (int, val *2 ,SOCK_MIN_RCVBUF )); + +if (sock) { +const struct proto_ops *ops =READ_ONCE (sock->ops); + +if (ops->set_rcvbuf) + ops->set_rcvbuf (sk, sk->sk_rcvbuf); + } }void sock_set_rcvbuf (struct sock *sk,int val)
net/ipv4/af_inet.c +1 -0
@@ -1091,6 +1091,7 @@ const struct proto_ops inet_stream_ops = { .compat_ioctl = inet_compat_ioctl, #endif .set_rcvlowat = tcp_set_rcvlowat, + .set_rcvbuf = tcp_set_rcvbuf, };EXPORT_SYMBOL (inet_stream_ops);
net/ipv4/tcp.c +5 -0
@@ -1858,6 +1858,11 @@ int tcp_set_rcvlowat(struct sock *sk, int val)return 0 ; } +void tcp_set_rcvbuf (struct sock *sk,int val) +{ +tcp_set_window_clamp (sk,tcp_win_from_space (sk, val)); +} +#ifdef CONFIG_MMU static const struct vm_operations_struct tcp_vm_ops = { };
net/ipv6/af_inet6.c +1 -0
@@ -690,6 +690,7 @@ const struct proto_ops inet6_stream_ops = { .compat_ioctl = inet6_compat_ioctl, #endif .set_rcvlowat = tcp_set_rcvlowat, + .set_rcvbuf = tcp_set_rcvbuf, };EXPORT_SYMBOL_GPL (inet6_stream_ops);
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerQuoted 7 lines · On Tue, 7 Apr 2026 17:14:38 -0700 Jakub Kicinski wrote:
Commit under Fixes moved recomputing the window clamp to
tcp_measure_rcv_mss()(whenscaling_ratiochanges). I suspect it missed the fact that we don't recompute the clamp when rcvbuf is set. Untilscaling_ratiochanges we are stuck with the old window clamp which may be based on the small initial buffer.scaling_ratiomay never change.
Quoted 8 lines
Inspired by Eric's recent commit
d1361840f8c5("tcp: fixSO_RCVLOWATand RCVBUF autotuning") plumb the user action thru to TCP and have it update the clamp.A smaller fix would be to just have
tcp_rcvbuf_grow()adjust the clamp even ifSOCK_RCVBUF_LOCKis set. But IIUC this is what we were trying to get away from in the first place.
Hi Eric, any thoughts?
I always assume you are displeased if you don't reply within 8 hours :)
I should say that everyone has obviously discouraged the team that run into this from using SO_RCVBUF. I'm fascinated by how they decided that it helps since it clearly doesn't work. AI sure makes it easy for people to "try things". Sigh.
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Tue, 7 Apr 2026 17:14:38 -0700 Jakub Kicinski wrote:
Commit under Fixes moved recomputing the window clamp to
tcp_measure_rcv_mss()(whenscaling_ratiochanges). I suspect it missed the fact that we don't recompute the clamp when rcvbuf is set. Untilscaling_ratiochanges we are stuck with the old window clamp which may be based on the small initial buffer.scaling_ratiomay never change.Inspired by Eric's recent commit
d1361840f8c5("tcp: fixSO_RCVLOWATand RCVBUF autotuning") plumb the user action thru to TCP and have it update the clamp.
Quoted 8 lines
Quoted 4 lines
A smaller fix would be to just have
tcp_rcvbuf_grow()adjust the clamp even ifSOCK_RCVBUF_LOCKis set. But IIUC this is what we were trying to get away from in the first place.Hi Eric, any thoughts?
I always assume you are displeased if you don't reply within 8 hours :)
Not at all, I simply missed this patch. Too many emails to triage.
I will take a look asap.
Quoted 4 lines
I should say that everyone has obviously discouraged the team that run into this from using
SO_RCVBUF. I'm fascinated by how they decided that it helps since it clearly doesn't work. AI sure makes it easy for people to "try things". Sigh.
Quoted 12 lines · Jakub Kicinski
Commit under Fixes moved recomputing the window clamp to
tcp_measure_rcv_mss()(whenscaling_ratiochanges). I suspect it missed the fact that we don't recompute the clamp when rcvbuf is set. Untilscaling_ratiochanges we are stuck with the old window clamp which may be based on the small initial buffer.scaling_ratiomay never change.Inspired by Eric's recent commit
d1361840f8c5("tcp: fixSO_RCVLOWATand RCVBUF autotuning") plumb the user action thru to TCP and have it update the clamp.
Quoted 7 lines
A smaller fix would be to just have
tcp_rcvbuf_grow()adjust the clamp even ifSOCK_RCVBUF_LOCKis set. But IIUC this is what we were trying to get away from in the first place.Fixes a2cbb1603943 ("tcp: Update window clamping condition")Signed-off-by Jakub Kicinski <[email protected]>
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Tue, 7 Apr 2026 17:14:38 -0700 you wrote:
Commit under Fixes moved recomputing the window clamp to
tcp_measure_rcv_mss()(whenscaling_ratiochanges). I suspect it missed the fact that we don't recompute the clamp when rcvbuf is set. Untilscaling_ratiochanges we are stuck with the old window clamp which may be based on the small initial buffer.scaling_ratiomay never change.[...]
Here is the summary with links:
- [net] tcp: update window_clamp when SO_RCVBUF is set
https://git.kernel.org/netdev/net-next/c/b025461303d8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html