Skip to content

Commit 05f76b2

Browse files
Subash Abhinov Kasiviswanathandavem330
authored andcommitted
tcp: Adjust clamping window for applications specifying SO_RCVBUF
tp->scaling_ratio is not updated based on skb->len/skb->truesize once SO_RCVBUF is set leading to the maximum window scaling to be 25% of rcvbuf after commit dfa2f04 ("tcp: get rid of sysctl_tcp_adv_win_scale") and 50% of rcvbuf after commit 697a6c8 ("tcp: increase the default TCP scaling ratio"). 50% tries to emulate the behavior of older kernels using sysctl_tcp_adv_win_scale with default value. Systems which were using a different values of sysctl_tcp_adv_win_scale in older kernels ended up seeing reduced download speeds in certain cases as covered in https://lists.openwall.net/netdev/2024/05/15/13 While the sysctl scheme is no longer acceptable, the value of 50% is a bit conservative when the skb->len/skb->truesize ratio is later determined to be ~0.66. Applications not specifying SO_RCVBUF update the window scaling and the receiver buffer every time data is copied to userspace. This computation is now used for applications setting SO_RCVBUF to update the maximum window scaling while ensuring that the receive buffer is within the application specified limit. Fixes: dfa2f04 ("tcp: get rid of sysctl_tcp_adv_win_scale") Signed-off-by: Sean Tranchetti <[email protected]> Signed-off-by: Subash Abhinov Kasiviswanathan <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e96a79b commit 05f76b2

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

net/ipv4/tcp_input.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,7 @@ void tcp_rcv_space_adjust(struct sock *sk)
754754
* <prev RTT . ><current RTT .. ><next RTT .... >
755755
*/
756756

757-
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_moderate_rcvbuf) &&
758-
!(sk->sk_userlocks & SOCK_RCVBUF_LOCK)) {
757+
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_moderate_rcvbuf)) {
759758
u64 rcvwin, grow;
760759
int rcvbuf;
761760

@@ -771,12 +770,22 @@ void tcp_rcv_space_adjust(struct sock *sk)
771770

772771
rcvbuf = min_t(u64, tcp_space_from_win(sk, rcvwin),
773772
READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[2]));
774-
if (rcvbuf > sk->sk_rcvbuf) {
775-
WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
773+
if (!(sk->sk_userlocks & SOCK_RCVBUF_LOCK)) {
774+
if (rcvbuf > sk->sk_rcvbuf) {
775+
WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
776776

777-
/* Make the window clamp follow along. */
778-
WRITE_ONCE(tp->window_clamp,
779-
tcp_win_from_space(sk, rcvbuf));
777+
/* Make the window clamp follow along. */
778+
WRITE_ONCE(tp->window_clamp,
779+
tcp_win_from_space(sk, rcvbuf));
780+
}
781+
} else {
782+
/* Make the window clamp follow along while being bounded
783+
* by SO_RCVBUF.
784+
*/
785+
int clamp = tcp_win_from_space(sk, min(rcvbuf, sk->sk_rcvbuf));
786+
787+
if (clamp > tp->window_clamp)
788+
WRITE_ONCE(tp->window_clamp, clamp);
780789
}
781790
}
782791
tp->rcvq_space.space = copied;

0 commit comments

Comments
 (0)