Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tcp: Set pingpong threshold via sysctl

TCP pingpong threshold is 1 by default. But some applications, like SQL DB
may prefer a higher pingpong threshold to activate delayed acks in quick
ack mode for better performance.

The pingpong threshold and related code were changed to 3 in the year
2019 in:
commit 4a41f453bedf ("tcp: change pingpong threshold to 3")
And reverted to 1 in the year 2022 in:
commit 4d8f24eeedc5 ("Revert "tcp: change pingpong threshold to 3"")

There is no single value that fits all applications.
Add net.ipv4.tcp_pingpong_thresh sysctl tunable, so it can be tuned for
optimal performance based on the application needs.

Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/1697056244-21888-1-git-send-email-haiyangz@microsoft.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Haiyang Zhang and committed by
Jakub Kicinski
562b1fdf 39d08b91

+39 -6
+13
Documentation/networking/ip-sysctl.rst
··· 1183 1183 1184 1184 Default: 128 1185 1185 1186 + tcp_pingpong_thresh - INTEGER 1187 + The number of estimated data replies sent for estimated incoming data 1188 + requests that must happen before TCP considers that a connection is a 1189 + "ping-pong" (request-response) connection for which delayed 1190 + acknowledgments can provide benefits. 1191 + 1192 + This threshold is 1 by default, but some applications may need a higher 1193 + threshold for optimal performance. 1194 + 1195 + Possible Values: 1 - 255 1196 + 1197 + Default: 1 1198 + 1186 1199 UDP variables 1187 1200 ============= 1188 1201
+12 -4
include/net/inet_connection_sock.h
··· 328 328 329 329 struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu); 330 330 331 - #define TCP_PINGPONG_THRESH 1 332 - 333 331 static inline void inet_csk_enter_pingpong_mode(struct sock *sk) 334 332 { 335 - inet_csk(sk)->icsk_ack.pingpong = TCP_PINGPONG_THRESH; 333 + inet_csk(sk)->icsk_ack.pingpong = 334 + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_pingpong_thresh); 336 335 } 337 336 338 337 static inline void inet_csk_exit_pingpong_mode(struct sock *sk) ··· 341 342 342 343 static inline bool inet_csk_in_pingpong_mode(struct sock *sk) 343 344 { 344 - return inet_csk(sk)->icsk_ack.pingpong >= TCP_PINGPONG_THRESH; 345 + return inet_csk(sk)->icsk_ack.pingpong >= 346 + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_pingpong_thresh); 347 + } 348 + 349 + static inline void inet_csk_inc_pingpong_cnt(struct sock *sk) 350 + { 351 + struct inet_connection_sock *icsk = inet_csk(sk); 352 + 353 + if (icsk->icsk_ack.pingpong < U8_MAX) 354 + icsk->icsk_ack.pingpong++; 345 355 } 346 356 347 357 static inline bool inet_csk_has_ulp(const struct sock *sk)
+2
include/net/netns/ipv4.h
··· 133 133 u8 sysctl_tcp_migrate_req; 134 134 u8 sysctl_tcp_comp_sack_nr; 135 135 u8 sysctl_tcp_backlog_ack_defer; 136 + u8 sysctl_tcp_pingpong_thresh; 137 + 136 138 int sysctl_tcp_reordering; 137 139 u8 sysctl_tcp_retries1; 138 140 u8 sysctl_tcp_retries2;
+8
net/ipv4/sysctl_net_ipv4.c
··· 1498 1498 .extra1 = SYSCTL_ZERO, 1499 1499 .extra2 = SYSCTL_ONE, 1500 1500 }, 1501 + { 1502 + .procname = "tcp_pingpong_thresh", 1503 + .data = &init_net.ipv4.sysctl_tcp_pingpong_thresh, 1504 + .maxlen = sizeof(u8), 1505 + .mode = 0644, 1506 + .proc_handler = proc_dou8vec_minmax, 1507 + .extra1 = SYSCTL_ONE, 1508 + }, 1501 1509 { } 1502 1510 }; 1503 1511
+2
net/ipv4/tcp_ipv4.c
··· 3288 3288 net->ipv4.sysctl_tcp_syn_linear_timeouts = 4; 3289 3289 net->ipv4.sysctl_tcp_shrink_window = 0; 3290 3290 3291 + net->ipv4.sysctl_tcp_pingpong_thresh = 1; 3292 + 3291 3293 return 0; 3292 3294 } 3293 3295
+2 -2
net/ipv4/tcp_output.c
··· 170 170 tp->lsndtime = now; 171 171 172 172 /* If it is a reply for ato after last received 173 - * packet, enter pingpong mode. 173 + * packet, increase pingpong count. 174 174 */ 175 175 if ((u32)(now - icsk->icsk_ack.lrcvtime) < icsk->icsk_ack.ato) 176 - inet_csk_enter_pingpong_mode(sk); 176 + inet_csk_inc_pingpong_cnt(sk); 177 177 } 178 178 179 179 /* Account for an ACK we sent. */