tcp: cache RTAX_QUICKACK metric in a hot cache line
Subsystems (4)
PATCH 1/1 tcp: cache RTAX_QUICKACK metric in a hot cache line
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.
--- include/net/inet_connection_sock.h | 3 ++- net/core/sock.c | 6 +++++- net/ipv4/tcp_input.c | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-)
include/net/inet_connection_sock.h +2 -1
@@ -117,7 +117,8 @@ struct inet_connection_sock {#define ATO_BITS 8 __u32 ato:ATO_BITS, /* Predicted tick of soft clock */ lrcv_flowlabel:20, /* last received ipv6 flowlabel */ - unused:4; + dst_quick_ack:1, /* cache dst RTAX_QUICKACK */ + unused:3;unsigned long timeout;/* Currently scheduled timeout */ __u32 lrcvtime;/* timestamp of last received data packet */ __u16 last_seg_size;/* Size of last incoming segment */
net/core/sock.c +5 -1
@@ -2565,8 +2565,12 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)u32 max_segs =1 ; sk->sk_route_caps = dst->dev->features; -if (sk_is_tcp (sk)) +if (sk_is_tcp (sk)) { +struct inet_connection_sock *icsk =inet_csk (sk); + sk->sk_route_caps |=NETIF_F_GSO ; + icsk->icsk_ack.dst_quick_ack =dst_metric (dst,RTAX_QUICKACK ); + }if (sk->sk_route_caps &NETIF_F_GSO ) sk->sk_route_caps |=NETIF_F_GSO_SOFTWARE ;if (unlikely (sk->sk_gso_disabled))
net/ipv4/tcp_input.c +1 -2
@@ -333,9 +333,8 @@ static void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks)static bool tcp_in_quickack_mode (struct sock *sk) {const struct inet_connection_sock *icsk =inet_csk (sk); -const struct dst_entry *dst =__sk_dst_get (sk); -return (dst &&dst_metric (dst,RTAX_QUICKACK )) || +return icsk->icsk_ack.dst_quick_ack || (icsk->icsk_ack.quick && !inet_csk_in_pingpong_mode (sk)); }
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Quoted 8 lines · Eric Dumazet
tcp_in_quickack_mode()is called from input path for small packets.It calls
__sk_dst_get()which readssk->sk_dst_cachewhich has been put insock_read_txgroup (for good reasons).Then
dst_metric(dst, RTAX_QUICKACK)also needs extra cache line misses.
Quoted 7 lines
Cache
RTAX_QUICKACKinicsk->icsk_ack.dst_quick_ackto 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_txgroup.Signed-off-by Eric Dumazet <[email protected]>
Quoted 8 lines · Eric Dumazet
tcp_in_quickack_mode()is called from input path for small packets.It calls
__sk_dst_get()which readssk->sk_dst_cachewhich has been put insock_read_txgroup (for good reasons).Then
dst_metric(dst, RTAX_QUICKACK)also needs extra cache line misses.
Quoted 8 lines
Cache
RTAX_QUICKACKinicsk->icsk_ack.dst_quick_ackto 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_txgroup.Signed-off-by Eric Dumazet <[email protected]>---
Great! Indeed, from double-checking the code, it looks like with this change there are no fetches of dst RTAX_ values outside of the connection initialization code paths. That's great. Thanks, Eric!
neal
From: Eric Dumazet <[email protected]>
Date: Wed, 12 Mar 2025 08:39:07 +0000
Quoted 7 lines
tcp_in_quickack_mode()is called from input path for small packets.It calls
__sk_dst_get()which readssk->sk_dst_cachewhich has been put insock_read_txgroup (for good reasons).Then
dst_metric(dst, RTAX_QUICKACK)also needs extra cache line misses.
Quoted 7 lines
Cache
RTAX_QUICKACKinicsk->icsk_ack.dst_quick_ackto 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_txgroup.Signed-off-by Eric Dumazet <[email protected]>
Paolo Abeni
maintainerQuoted 8 lines · Eric Dumazet
net/core/sock.c +0
-0@@ -2565,8 +2565,12 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)u32 max_segs =1 ; sk->sk_route_caps = dst->dev->features;
net/core/sock.c void sk_setup_caps(struct sock *sk, struct dst_entry *dst) · line 2576
Quoted 10 lines
net/core/sock.c +5
-1-if (sk_is_tcp (sk)) +if (sk_is_tcp (sk)) { +struct inet_connection_sock *icsk =inet_csk (sk); + sk->sk_route_caps |=NETIF_F_GSO ; + icsk->icsk_ack.dst_quick_ack =dst_metric (dst,RTAX_QUICKACK ); + }if (sk->sk_route_caps &NETIF_F_GSO ) sk->sk_route_caps |=NETIF_F_GSO_SOFTWARE ;if (unlikely (sk->sk_gso_disabled))
Not strictly related with this patch, but I'm wondering if in case of ipv4_sk_update_pmtu() racing with a re-route, we could end-up with the first updating the sk dst cache instead of the latter, missing the sk status update. Should ipv4_sk_update_pmtu() call sk_setup_caps() instead?
Thanks,
Paolo
Quoted 9 lines · Paolo Abeni
Quoted 7 lines · Eric Dumazet
net/core/sock.c +0
-0@@ -2565,8 +2565,12 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)u32 max_segs =1 ;
Quoted 16 lines
net/core/sock.c void sk_setup_caps(struct sock *sk, struct dst_entry *dst) · line 2576
Quoted 11 lines
net/core/sock.c +5
-1sk->sk_route_caps = dst->dev->features; -if (sk_is_tcp (sk)) +if (sk_is_tcp (sk)) { +struct inet_connection_sock *icsk =inet_csk (sk); + sk->sk_route_caps |=NETIF_F_GSO ; + icsk->icsk_ack.dst_quick_ack =dst_metric (dst,RTAX_QUICKACK ); + }if (sk->sk_route_caps &NETIF_F_GSO ) sk->sk_route_caps |=NETIF_F_GSO_SOFTWARE ;if (unlikely (sk->sk_gso_disabled))Not strictly related with this patch, but I'm wondering if in case of
ipv4_sk_update_pmtu()racing with a re-route, we could end-up with the first updating the sk dst cache instead of the latter, missing the sk status update. Shouldipv4_sk_update_pmtu()callsk_setup_caps()instead?
This indeed looks strange. IPv6 seems fine at a first glance.
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Wed, 12 Mar 2025 08:39:07 +0000 you wrote:
tcp_in_quickack_mode()is called from input path for small packets.It calls
__sk_dst_get()which readssk->sk_dst_cachewhich has been put insock_read_txgroup (for good reasons).Then
dst_metric(dst, RTAX_QUICKACK)also needs extra cache line misses.[...]
Here is the summary with links:
- [net-next] tcp: cache RTAX_QUICKACK metric in a hot cache line
https://git.kernel.org/netdev/net-next/c/15492700ac41
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html