Commit 08dfe370 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski
Browse files

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: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20251124175013.1473655-4-edumazet@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 27e8257a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ struct inet_bind_bucket icsk_bind_hash read_mostly
struct inet_bind2_bucket            icsk_bind2_hash        read_mostly                             tcp_set_state,inet_put_port
struct timer_list                   icsk_retransmit_timer  read_write                              inet_csk_reset_xmit_timer,tcp_connect
struct timer_list                   icsk_delack_timer      read_mostly                             inet_csk_reset_xmit_timer,tcp_connect
struct timer_list                   icsk_keepalive_timer
u32                                 icsk_rto               read_write                              tcp_cwnd_validate,tcp_schedule_loss_probe,tcp_connect_init,tcp_connect,tcp_write_xmit,tcp_push_one
u32                                 icsk_rto_min
u32                                 icsk_rto_max           read_mostly                             tcp_reset_xmit_timer
+9 −2
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ struct inet_connection_sock_af_ops {
 * @icsk_bind_hash:	   Bind node
 * @icsk_bind2_hash:	   Bind node in the bhash2 table
 * @icsk_retransmit_timer: Resend (no ack)
 * @icsk_delack_timer:     Delayed ACK timer
 * @icsk_keepalive_timer:  Keepalive timer
 * @mptcp_tout_timer: mptcp timer
 * @icsk_rto:		   Retransmit timeout
 * @icsk_pmtu_cookie	   Last pmtu seen by socket
 * @icsk_ca_ops		   Pluggable congestion control hook
@@ -83,6 +86,10 @@ struct inet_connection_sock {
	struct inet_bind2_bucket  *icsk_bind2_hash;
	struct timer_list	  icsk_retransmit_timer;
	struct timer_list	  icsk_delack_timer;
	union {
		struct timer_list icsk_keepalive_timer;
		struct timer_list mptcp_tout_timer;
	};
	__u32			  icsk_rto;
	__u32                     icsk_rto_min;
	u32			  icsk_rto_max;
+3 −3
Original line number Diff line number Diff line
@@ -739,7 +739,7 @@ void inet_csk_init_xmit_timers(struct sock *sk,

	timer_setup(&icsk->icsk_retransmit_timer, retransmit_handler, 0);
	timer_setup(&icsk->icsk_delack_timer, delack_handler, 0);
	timer_setup(&sk->sk_timer, keepalive_handler, 0);
	timer_setup(&icsk->icsk_keepalive_timer, keepalive_handler, 0);
	icsk->icsk_pending = icsk->icsk_ack.pending = 0;
}

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

	sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
	sk_stop_timer(sk, &icsk->icsk_delack_timer);
	sk_stop_timer(sk, &sk->sk_timer);
	sk_stop_timer(sk, &icsk->icsk_keepalive_timer);
}

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

	sk_stop_timer_sync(sk, &icsk->icsk_retransmit_timer);
	sk_stop_timer_sync(sk, &icsk->icsk_delack_timer);
	sk_stop_timer_sync(sk, &sk->sk_timer);
	sk_stop_timer_sync(sk, &icsk->icsk_keepalive_timer);
}

struct dst_entry *inet_csk_route_req(const struct sock *sk,
+2 −2
Original line number Diff line number Diff line
@@ -293,11 +293,11 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
		r->idiag_retrans = READ_ONCE(icsk->icsk_probes_out);
		r->idiag_expires =
			jiffies_delta_to_msecs(tcp_timeout_expires(sk) - jiffies);
	} else if (timer_pending(&sk->sk_timer)) {
	} else if (timer_pending(&icsk->icsk_keepalive_timer)) {
		r->idiag_timer = 2;
		r->idiag_retrans = READ_ONCE(icsk->icsk_probes_out);
		r->idiag_expires =
			jiffies_delta_to_msecs(sk->sk_timer.expires - jiffies);
			jiffies_delta_to_msecs(icsk->icsk_keepalive_timer.expires - jiffies);
	}

	if ((ext & (1 << (INET_DIAG_INFO - 1))) && handler->idiag_info_size) {
+2 −2
Original line number Diff line number Diff line
@@ -2873,9 +2873,9 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
	} else if (icsk_pending == ICSK_TIME_PROBE0) {
		timer_active	= 4;
		timer_expires	= tcp_timeout_expires(sk);
	} else if (timer_pending(&sk->sk_timer)) {
	} else if (timer_pending(&icsk->icsk_keepalive_timer)) {
		timer_active	= 2;
		timer_expires	= sk->sk_timer.expires;
		timer_expires	= icsk->icsk_keepalive_timer.expires;
	} else {
		timer_active	= 0;
		timer_expires = jiffies;
Loading