Skip to content

Commit

Permalink
Revert "tcp: get rid of sysctl_tcp_adv_win_scale"
Browse files Browse the repository at this point in the history
This reverts commit dfa2f04.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
  • Loading branch information
Geliang Tang committed May 2, 2024
1 parent 09137a5 commit 8014fce
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
1 change: 0 additions & 1 deletion Documentation/networking/ip-sysctl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ tcp_abort_on_overflow - BOOLEAN
option can harm clients of your server.

tcp_adv_win_scale - INTEGER
Obsolete since linux-6.6
Count buffering overhead as bytes/2^tcp_adv_win_scale
(if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale),
if it is <= 0.
Expand Down
2 changes: 1 addition & 1 deletion include/net/netns/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct netns_ipv4 {
u8 sysctl_tcp_abort_on_overflow;
u8 sysctl_tcp_fack; /* obsolete */
int sysctl_tcp_max_reordering;
int sysctl_tcp_adv_win_scale; /* obsolete */
int sysctl_tcp_adv_win_scale;
u8 sysctl_tcp_dsack;
u8 sysctl_tcp_app_win;
u8 sysctl_tcp_frto;
Expand Down
6 changes: 5 additions & 1 deletion include/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,11 @@ static inline int __tcp_win_from_space(u8 scaling_ratio, int space)

static inline int tcp_win_from_space(const struct sock *sk, int space)
{
return __tcp_win_from_space(tcp_sk(sk)->scaling_ratio, space);
int tcp_adv_win_scale = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_adv_win_scale);

return tcp_adv_win_scale <= 0 ?
(space>>(-tcp_adv_win_scale)) :
space - (space>>tcp_adv_win_scale);
}

/* inverse of __tcp_win_from_space() */
Expand Down
10 changes: 5 additions & 5 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ EXPORT_SYMBOL(tcp_peek_len);
/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */
int tcp_set_rcvlowat(struct sock *sk, int val)
{
int space, cap;
int cap;

if (sk->sk_userlocks & SOCK_RCVBUF_LOCK)
cap = sk->sk_rcvbuf >> 1;
Expand All @@ -1722,10 +1722,10 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
if (sk->sk_userlocks & SOCK_RCVBUF_LOCK)
return 0;

space = tcp_space_from_win(sk, val);
if (space > sk->sk_rcvbuf) {
WRITE_ONCE(sk->sk_rcvbuf, space);
WRITE_ONCE(tcp_sk(sk)->window_clamp, val);
val <<= 1;
if (val > sk->sk_rcvbuf) {
WRITE_ONCE(sk->sk_rcvbuf, val);
WRITE_ONCE(tcp_sk(sk)->window_clamp, tcp_win_from_space(sk, val));
}
return 0;
}
Expand Down
19 changes: 7 additions & 12 deletions net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,6 @@ static void tcp_measure_rcv_mss(struct sock *sk, const struct sk_buff *skb)
*/
len = skb_shinfo(skb)->gso_size ? : skb->len;
if (len >= icsk->icsk_ack.rcv_mss) {
/* Note: divides are still a bit expensive.
* For the moment, only adjust scaling_ratio
* when we update icsk_ack.rcv_mss.
*/
if (unlikely(len != icsk->icsk_ack.rcv_mss)) {
u64 val = (u64)skb->len << TCP_RMEM_TO_WIN_SCALE;

do_div(val, skb->truesize);
tcp_sk(sk)->scaling_ratio = val ? val : 1;
}
icsk->icsk_ack.rcv_mss = min_t(unsigned int, len,
tcp_sk(sk)->advmss);
/* Account for possibly-removed options */
Expand Down Expand Up @@ -756,8 +746,8 @@ void tcp_rcv_space_adjust(struct sock *sk)

if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_moderate_rcvbuf) &&
!(sk->sk_userlocks & SOCK_RCVBUF_LOCK)) {
int rcvmem, rcvbuf;
u64 rcvwin, grow;
int rcvbuf;

/* minimal window to cope with packet losses, assuming
* steady state. Add some cushion because of small variations.
Expand All @@ -769,7 +759,12 @@ void tcp_rcv_space_adjust(struct sock *sk)
do_div(grow, tp->rcvq_space.space);
rcvwin += (grow << 1);

rcvbuf = min_t(u64, tcp_space_from_win(sk, rcvwin),
rcvmem = SKB_TRUESIZE(tp->advmss + MAX_TCP_HEADER);
while (tcp_win_from_space(sk, rcvmem) < tp->advmss)
rcvmem += 128;

do_div(rcvwin, tp->advmss);
rcvbuf = min_t(u64, rcvwin * rcvmem,
READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[2]));
if (rcvbuf > sk->sk_rcvbuf) {
WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
Expand Down

0 comments on commit 8014fce

Please sign in to comment.