Skip to content

Commit deafd84

Browse files
edumazetopsiff
authored andcommitted
tcp: cache RTAX_QUICKACK metric in a hot cache line
mainline inclusion from mainline-v6.15-rc1 category: performance tcp_in_quickack_mode() is called from input path for small packets. It calls __sk_dst_get() which reads sk->sk_dst_cache which has been put in sock_read_tx group (for good reasons). Then dst_metric(dst, RTAX_QUICKACK) also needs extra cache line misses. Cache RTAX_QUICKACK in icsk->icsk_ack.dst_quick_ack to no longer pull these cache lines for the cases a delayed ACK is scheduled. After this patch TCP receive path does not longer access sock_read_tx group. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Jason Xing <kerneljasonxing@gmail.com> Reviewed-by: Neal Cardwell <ncardwell@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250312083907.1931644-1-edumazet@google.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> (cherry picked from commit 1549270) Signed-off-by: Wentao Guan <guanwentao@uniontech.com> Change-Id: Ie4afef568644ab39555e776c10592200736a522f
1 parent 5a761eb commit deafd84

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

include/net/inet_connection_sock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ struct inet_connection_sock {
120120
#define ATO_BITS 8
121121
__u32 ato:ATO_BITS, /* Predicted tick of soft clock */
122122
lrcv_flowlabel:20, /* last received ipv6 flowlabel */
123-
unused:4;
123+
dst_quick_ack:1, /* cache dst RTAX_QUICKACK */
124+
unused:3;
124125
unsigned long timeout; /* Currently scheduled timeout */
125126
__u32 lrcvtime; /* timestamp of last received data packet */
126127
__u16 last_seg_size; /* Size of last incoming segment */

net/core/sock.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2446,8 +2446,12 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
24462446
u32 max_segs = 1;
24472447

24482448
sk->sk_route_caps = dst->dev->features;
2449-
if (sk_is_tcp(sk))
2449+
if (sk_is_tcp(sk)) {
2450+
struct inet_connection_sock *icsk = inet_csk(sk);
2451+
24502452
sk->sk_route_caps |= NETIF_F_GSO;
2453+
icsk->icsk_ack.dst_quick_ack = dst_metric(dst, RTAX_QUICKACK);
2454+
}
24512455
if (sk->sk_route_caps & NETIF_F_GSO)
24522456
sk->sk_route_caps |= NETIF_F_GSO_SOFTWARE;
24532457
if (unlikely(sk->sk_gso_disabled))

net/ipv4/tcp_input.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,8 @@ static void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks)
337337
static bool tcp_in_quickack_mode(struct sock *sk)
338338
{
339339
const struct inet_connection_sock *icsk = inet_csk(sk);
340-
const struct dst_entry *dst = __sk_dst_get(sk);
341340

342-
return (dst && dst_metric(dst, RTAX_QUICKACK)) ||
341+
return icsk->icsk_ack.dst_quick_ack ||
343342
(icsk->icsk_ack.quick && !inet_csk_in_pingpong_mode(sk));
344343
}
345344

0 commit comments

Comments
 (0)