Skip to content

Commit a337531

Browse files
yuchungchengdavem330
authored andcommitted
tcp: up initial rmem to 128KB and SYN rwin to around 64KB
Previously TCP initial receive buffer is ~87KB by default and the initial receive window is ~29KB (20 MSS). This patch changes the two numbers to 128KB and ~64KB (rounding down to the multiples of MSS) respectively. The patch also simplifies the calculations s.t. the two numbers are directly controlled by sysctl tcp_rmem[1]: 1) Initial receiver buffer budget (sk_rcvbuf): while this should be configured via sysctl tcp_rmem[1], previously tcp_fixup_rcvbuf() always override and set a larger size when a new connection establishes. 2) Initial receive window in SYN: previously it is set to 20 packets if MSS <= 1460. The number 20 was based on the initial congestion window of 10: the receiver needs twice amount to avoid being limited by the receive window upon out-of-order delivery in the first window burst. But since this only applies if the receiving MSS <= 1460, connection using large MTU (e.g. to utilize receiver zero-copy) may be limited by the receive window. With this patch TCP memory configuration is more straight-forward and more properly sized to modern high-speed networks by default. Several popular stacks have been announcing 64KB rwin in SYNs as well. Signed-off-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: Wei Wang <weiwan@google.com> Signed-off-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3ff6cde commit a337531

File tree

3 files changed

+8
-46
lines changed

3 files changed

+8
-46
lines changed

net/ipv4/tcp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3896,8 +3896,8 @@ void __init tcp_init(void)
38963896
init_net.ipv4.sysctl_tcp_wmem[2] = max(64*1024, max_wshare);
38973897

38983898
init_net.ipv4.sysctl_tcp_rmem[0] = SK_MEM_QUANTUM;
3899-
init_net.ipv4.sysctl_tcp_rmem[1] = 87380;
3900-
init_net.ipv4.sysctl_tcp_rmem[2] = max(87380, max_rshare);
3899+
init_net.ipv4.sysctl_tcp_rmem[1] = 131072;
3900+
init_net.ipv4.sysctl_tcp_rmem[2] = max(131072, max_rshare);
39013901

39023902
pr_info("Hash tables configured (established %u bind %u)\n",
39033903
tcp_hashinfo.ehash_mask + 1, tcp_hashinfo.bhash_size);

net/ipv4/tcp_input.c

+2-23
Original file line numberDiff line numberDiff line change
@@ -426,26 +426,7 @@ static void tcp_grow_window(struct sock *sk, const struct sk_buff *skb)
426426
}
427427
}
428428

429-
/* 3. Tuning rcvbuf, when connection enters established state. */
430-
static void tcp_fixup_rcvbuf(struct sock *sk)
431-
{
432-
u32 mss = tcp_sk(sk)->advmss;
433-
int rcvmem;
434-
435-
rcvmem = 2 * SKB_TRUESIZE(mss + MAX_TCP_HEADER) *
436-
tcp_default_init_rwnd(mss);
437-
438-
/* Dynamic Right Sizing (DRS) has 2 to 3 RTT latency
439-
* Allow enough cushion so that sender is not limited by our window
440-
*/
441-
if (sock_net(sk)->ipv4.sysctl_tcp_moderate_rcvbuf)
442-
rcvmem <<= 2;
443-
444-
if (sk->sk_rcvbuf < rcvmem)
445-
sk->sk_rcvbuf = min(rcvmem, sock_net(sk)->ipv4.sysctl_tcp_rmem[2]);
446-
}
447-
448-
/* 4. Try to fixup all. It is made immediately after connection enters
429+
/* 3. Try to fixup all. It is made immediately after connection enters
449430
* established state.
450431
*/
451432
void tcp_init_buffer_space(struct sock *sk)
@@ -454,8 +435,6 @@ void tcp_init_buffer_space(struct sock *sk)
454435
struct tcp_sock *tp = tcp_sk(sk);
455436
int maxwin;
456437

457-
if (!(sk->sk_userlocks & SOCK_RCVBUF_LOCK))
458-
tcp_fixup_rcvbuf(sk);
459438
if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK))
460439
tcp_sndbuf_expand(sk);
461440

@@ -485,7 +464,7 @@ void tcp_init_buffer_space(struct sock *sk)
485464
tp->snd_cwnd_stamp = tcp_jiffies32;
486465
}
487466

488-
/* 5. Recalculate window clamp after socket hit its memory bounds. */
467+
/* 4. Recalculate window clamp after socket hit its memory bounds. */
489468
static void tcp_clamp_window(struct sock *sk)
490469
{
491470
struct tcp_sock *tp = tcp_sk(sk);

net/ipv4/tcp_output.c

+4-21
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,6 @@ static inline void tcp_event_ack_sent(struct sock *sk, unsigned int pkts,
195195
inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
196196
}
197197

198-
199-
u32 tcp_default_init_rwnd(u32 mss)
200-
{
201-
/* Initial receive window should be twice of TCP_INIT_CWND to
202-
* enable proper sending of new unsent data during fast recovery
203-
* (RFC 3517, Section 4, NextSeg() rule (2)). Further place a
204-
* limit when mss is larger than 1460.
205-
*/
206-
u32 init_rwnd = TCP_INIT_CWND * 2;
207-
208-
if (mss > 1460)
209-
init_rwnd = max((1460 * init_rwnd) / mss, 2U);
210-
return init_rwnd;
211-
}
212-
213198
/* Determine a window scaling and initial window to offer.
214199
* Based on the assumption that the given amount of space
215200
* will be offered. Store the results in the tp structure.
@@ -244,7 +229,10 @@ void tcp_select_initial_window(const struct sock *sk, int __space, __u32 mss,
244229
if (sock_net(sk)->ipv4.sysctl_tcp_workaround_signed_windows)
245230
(*rcv_wnd) = min(space, MAX_TCP_WINDOW);
246231
else
247-
(*rcv_wnd) = space;
232+
(*rcv_wnd) = min_t(u32, space, U16_MAX);
233+
234+
if (init_rcv_wnd)
235+
*rcv_wnd = min(*rcv_wnd, init_rcv_wnd * mss);
248236

249237
(*rcv_wscale) = 0;
250238
if (wscale_ok) {
@@ -257,11 +245,6 @@ void tcp_select_initial_window(const struct sock *sk, int __space, __u32 mss,
257245
(*rcv_wscale)++;
258246
}
259247
}
260-
261-
if (!init_rcv_wnd) /* Use default unless specified otherwise */
262-
init_rcv_wnd = tcp_default_init_rwnd(mss);
263-
*rcv_wnd = min(*rcv_wnd, init_rcv_wnd * mss);
264-
265248
/* Set the clamp no higher than max representable value */
266249
(*window_clamp) = min_t(__u32, U16_MAX << (*rcv_wscale), *window_clamp);
267250
}

0 commit comments

Comments
 (0)