Skip to content

Commit 08dfe37

Browse files
edumazetkuba-moo
authored andcommitted
tcp: introduce icsk->icsk_keepalive_timer
sk->sk_timer has been used for TCP keepalives. Keepalive timers are not in fast path, we want to use sk->sk_timer storage for retransmit timers, for better cache locality. Create icsk->icsk_keepalive_timer and change keepalive code to no longer use sk->sk_timer. Added space is reclaimed in the following patch. This includes changes to MPTCP, which was also using sk_timer. Alias icsk->mptcp_tout_timer and icsk->icsk_keepalive_timer for inet_sk_diag_fill() sake. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20251124175013.1473655-4-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 27e8257 commit 08dfe37

File tree

11 files changed

+35
-24
lines changed

11 files changed

+35
-24
lines changed

Documentation/networking/net_cachelines/inet_connection_sock.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct inet_bind_bucket icsk_bind_hash read_mostly
1414
struct inet_bind2_bucket icsk_bind2_hash read_mostly tcp_set_state,inet_put_port
1515
struct timer_list icsk_retransmit_timer read_write inet_csk_reset_xmit_timer,tcp_connect
1616
struct timer_list icsk_delack_timer read_mostly inet_csk_reset_xmit_timer,tcp_connect
17+
struct timer_list icsk_keepalive_timer
1718
u32 icsk_rto read_write tcp_cwnd_validate,tcp_schedule_loss_probe,tcp_connect_init,tcp_connect,tcp_write_xmit,tcp_push_one
1819
u32 icsk_rto_min
1920
u32 icsk_rto_max read_mostly tcp_reset_xmit_timer

include/net/inet_connection_sock.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ struct inet_connection_sock_af_ops {
5757
* @icsk_bind_hash: Bind node
5858
* @icsk_bind2_hash: Bind node in the bhash2 table
5959
* @icsk_retransmit_timer: Resend (no ack)
60+
* @icsk_delack_timer: Delayed ACK timer
61+
* @icsk_keepalive_timer: Keepalive timer
62+
* @mptcp_tout_timer: mptcp timer
6063
* @icsk_rto: Retransmit timeout
6164
* @icsk_pmtu_cookie Last pmtu seen by socket
6265
* @icsk_ca_ops Pluggable congestion control hook
@@ -81,8 +84,12 @@ struct inet_connection_sock {
8184
struct request_sock_queue icsk_accept_queue;
8285
struct inet_bind_bucket *icsk_bind_hash;
8386
struct inet_bind2_bucket *icsk_bind2_hash;
84-
struct timer_list icsk_retransmit_timer;
85-
struct timer_list icsk_delack_timer;
87+
struct timer_list icsk_retransmit_timer;
88+
struct timer_list icsk_delack_timer;
89+
union {
90+
struct timer_list icsk_keepalive_timer;
91+
struct timer_list mptcp_tout_timer;
92+
};
8693
__u32 icsk_rto;
8794
__u32 icsk_rto_min;
8895
u32 icsk_rto_max;

net/ipv4/inet_connection_sock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ void inet_csk_init_xmit_timers(struct sock *sk,
739739

740740
timer_setup(&icsk->icsk_retransmit_timer, retransmit_handler, 0);
741741
timer_setup(&icsk->icsk_delack_timer, delack_handler, 0);
742-
timer_setup(&sk->sk_timer, keepalive_handler, 0);
742+
timer_setup(&icsk->icsk_keepalive_timer, keepalive_handler, 0);
743743
icsk->icsk_pending = icsk->icsk_ack.pending = 0;
744744
}
745745

@@ -752,7 +752,7 @@ void inet_csk_clear_xmit_timers(struct sock *sk)
752752

753753
sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
754754
sk_stop_timer(sk, &icsk->icsk_delack_timer);
755-
sk_stop_timer(sk, &sk->sk_timer);
755+
sk_stop_timer(sk, &icsk->icsk_keepalive_timer);
756756
}
757757

758758
void inet_csk_clear_xmit_timers_sync(struct sock *sk)
@@ -767,7 +767,7 @@ void inet_csk_clear_xmit_timers_sync(struct sock *sk)
767767

768768
sk_stop_timer_sync(sk, &icsk->icsk_retransmit_timer);
769769
sk_stop_timer_sync(sk, &icsk->icsk_delack_timer);
770-
sk_stop_timer_sync(sk, &sk->sk_timer);
770+
sk_stop_timer_sync(sk, &icsk->icsk_keepalive_timer);
771771
}
772772

773773
struct dst_entry *inet_csk_route_req(const struct sock *sk,

net/ipv4/inet_diag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
293293
r->idiag_retrans = READ_ONCE(icsk->icsk_probes_out);
294294
r->idiag_expires =
295295
jiffies_delta_to_msecs(tcp_timeout_expires(sk) - jiffies);
296-
} else if (timer_pending(&sk->sk_timer)) {
296+
} else if (timer_pending(&icsk->icsk_keepalive_timer)) {
297297
r->idiag_timer = 2;
298298
r->idiag_retrans = READ_ONCE(icsk->icsk_probes_out);
299299
r->idiag_expires =
300-
jiffies_delta_to_msecs(sk->sk_timer.expires - jiffies);
300+
jiffies_delta_to_msecs(icsk->icsk_keepalive_timer.expires - jiffies);
301301
}
302302

303303
if ((ext & (1 << (INET_DIAG_INFO - 1))) && handler->idiag_info_size) {

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,9 +2873,9 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
28732873
} else if (icsk_pending == ICSK_TIME_PROBE0) {
28742874
timer_active = 4;
28752875
timer_expires = tcp_timeout_expires(sk);
2876-
} else if (timer_pending(&sk->sk_timer)) {
2876+
} else if (timer_pending(&icsk->icsk_keepalive_timer)) {
28772877
timer_active = 2;
2878-
timer_expires = sk->sk_timer.expires;
2878+
timer_expires = icsk->icsk_keepalive_timer.expires;
28792879
} else {
28802880
timer_active = 0;
28812881
timer_expires = jiffies;

net/ipv4/tcp_timer.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,12 @@ void tcp_syn_ack_timeout(const struct request_sock *req)
755755

756756
void tcp_reset_keepalive_timer(struct sock *sk, unsigned long len)
757757
{
758-
sk_reset_timer(sk, &sk->sk_timer, jiffies + len);
758+
sk_reset_timer(sk, &inet_csk(sk)->icsk_keepalive_timer, jiffies + len);
759759
}
760760

761761
static void tcp_delete_keepalive_timer(struct sock *sk)
762762
{
763-
sk_stop_timer(sk, &sk->sk_timer);
763+
sk_stop_timer(sk, &inet_csk(sk)->icsk_keepalive_timer);
764764
}
765765

766766
void tcp_set_keepalive(struct sock *sk, int val)
@@ -777,8 +777,9 @@ EXPORT_IPV6_MOD_GPL(tcp_set_keepalive);
777777

778778
static void tcp_keepalive_timer(struct timer_list *t)
779779
{
780-
struct sock *sk = timer_container_of(sk, t, sk_timer);
781-
struct inet_connection_sock *icsk = inet_csk(sk);
780+
struct inet_connection_sock *icsk =
781+
timer_container_of(icsk, t, icsk_keepalive_timer);
782+
struct sock *sk = &icsk->icsk_inet.sk;
782783
struct tcp_sock *tp = tcp_sk(sk);
783784
u32 elapsed;
784785

net/ipv6/tcp_ipv6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,9 +2167,9 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
21672167
} else if (icsk_pending == ICSK_TIME_PROBE0) {
21682168
timer_active = 4;
21692169
timer_expires = tcp_timeout_expires(sp);
2170-
} else if (timer_pending(&sp->sk_timer)) {
2170+
} else if (timer_pending(&icsk->icsk_keepalive_timer)) {
21712171
timer_active = 2;
2172-
timer_expires = sp->sk_timer.expires;
2172+
timer_expires = icsk->icsk_keepalive_timer.expires;
21732173
} else {
21742174
timer_active = 0;
21752175
timer_expires = jiffies;

net/mptcp/protocol.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,9 @@ static void mptcp_retransmit_timer(struct timer_list *t)
23742374

23752375
static void mptcp_tout_timer(struct timer_list *t)
23762376
{
2377-
struct sock *sk = timer_container_of(sk, t, sk_timer);
2377+
struct inet_connection_sock *icsk =
2378+
timer_container_of(icsk, t, mptcp_tout_timer);
2379+
struct sock *sk = &icsk->icsk_inet.sk;
23782380

23792381
mptcp_schedule_work(sk);
23802382
sock_put(sk);
@@ -2828,7 +2830,7 @@ void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout)
28282830
*/
28292831
timeout = inet_csk(sk)->icsk_mtup.probe_timestamp ? close_timeout : fail_tout;
28302832

2831-
sk_reset_timer(sk, &sk->sk_timer, timeout);
2833+
sk_reset_timer(sk, &inet_csk(sk)->mptcp_tout_timer, timeout);
28322834
}
28332835

28342836
static void mptcp_mp_fail_no_response(struct mptcp_sock *msk)
@@ -2974,7 +2976,7 @@ static void __mptcp_init_sock(struct sock *sk)
29742976

29752977
/* re-use the csk retrans timer for MPTCP-level retrans */
29762978
timer_setup(&msk->sk.icsk_retransmit_timer, mptcp_retransmit_timer, 0);
2977-
timer_setup(&sk->sk_timer, mptcp_tout_timer, 0);
2979+
timer_setup(&msk->sk.mptcp_tout_timer, mptcp_tout_timer, 0);
29782980
}
29792981

29802982
static void mptcp_ca_reset(struct sock *sk)
@@ -3176,7 +3178,7 @@ static void __mptcp_destroy_sock(struct sock *sk)
31763178
might_sleep();
31773179

31783180
mptcp_stop_rtx_timer(sk);
3179-
sk_stop_timer(sk, &sk->sk_timer);
3181+
sk_stop_timer(sk, &inet_csk(sk)->mptcp_tout_timer);
31803182
msk->pm.status = 0;
31813183
mptcp_release_sched(msk);
31823184

net/mptcp/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static inline void mptcp_stop_tout_timer(struct sock *sk)
892892
if (!inet_csk(sk)->icsk_mtup.probe_timestamp)
893893
return;
894894

895-
sk_stop_timer(sk, &sk->sk_timer);
895+
sk_stop_timer(sk, &inet_csk(sk)->mptcp_tout_timer);
896896
inet_csk(sk)->icsk_mtup.probe_timestamp = 0;
897897
}
898898

tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ static int dump_tcp_sock(struct seq_file *seq, struct tcp_sock *tp,
103103
} else if (icsk->icsk_pending == ICSK_TIME_PROBE0) {
104104
timer_active = 4;
105105
timer_expires = icsk->icsk_retransmit_timer.expires;
106-
} else if (timer_pending(&sp->sk_timer)) {
106+
} else if (timer_pending(&icsk->icsk_keepalive_timer)) {
107107
timer_active = 2;
108-
timer_expires = sp->sk_timer.expires;
108+
timer_expires = icsk->icsk_keepalive_timer.expires;
109109
} else {
110110
timer_active = 0;
111111
timer_expires = bpf_jiffies64();

0 commit comments

Comments
 (0)