Skip to content

Commit a7c428e

Browse files
edumazetkuba-moo
authored andcommitted
tcp/dccp: remove icsk->icsk_timeout
icsk->icsk_timeout can be replaced by icsk->icsk_retransmit_timer.expires This saves 8 bytes in TCP/DCCP sockets and helps for better cache locality. Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7bd2e6b commit a7c428e

File tree

10 files changed

+28
-24
lines changed

10 files changed

+28
-24
lines changed

Documentation/networking/net_cachelines/inet_connection_sock.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ struct inet_sock icsk_inet read_mostly r
1212
struct request_sock_queue icsk_accept_queue
1313
struct inet_bind_bucket icsk_bind_hash read_mostly tcp_set_state
1414
struct inet_bind2_bucket icsk_bind2_hash read_mostly tcp_set_state,inet_put_port
15-
unsigned_long icsk_timeout read_mostly inet_csk_reset_xmit_timer,tcp_connect
16-
struct timer_list icsk_retransmit_timer read_mostly inet_csk_reset_xmit_timer,tcp_connect
15+
struct timer_list icsk_retransmit_timer read_write inet_csk_reset_xmit_timer,tcp_connect
1716
struct timer_list icsk_delack_timer read_mostly inet_csk_reset_xmit_timer,tcp_connect
1817
u32 icsk_rto read_write tcp_cwnd_validate,tcp_schedule_loss_probe,tcp_connect_init,tcp_connect,tcp_write_xmit,tcp_push_one
1918
u32 icsk_rto_min

include/net/inet_connection_sock.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ struct inet_connection_sock_af_ops {
5656
* @icsk_accept_queue: FIFO of established children
5757
* @icsk_bind_hash: Bind node
5858
* @icsk_bind2_hash: Bind node in the bhash2 table
59-
* @icsk_timeout: Timeout
6059
* @icsk_retransmit_timer: Resend (no ack)
6160
* @icsk_rto: Retransmit timeout
6261
* @icsk_pmtu_cookie Last pmtu seen by socket
@@ -82,7 +81,6 @@ struct inet_connection_sock {
8281
struct request_sock_queue icsk_accept_queue;
8382
struct inet_bind_bucket *icsk_bind_hash;
8483
struct inet_bind2_bucket *icsk_bind2_hash;
85-
unsigned long icsk_timeout;
8684
struct timer_list icsk_retransmit_timer;
8785
struct timer_list icsk_delack_timer;
8886
__u32 icsk_rto;
@@ -187,6 +185,12 @@ static inline void inet_csk_delack_init(struct sock *sk)
187185
memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
188186
}
189187

188+
static inline unsigned long
189+
icsk_timeout(const struct inet_connection_sock *icsk)
190+
{
191+
return READ_ONCE(icsk->icsk_retransmit_timer.expires);
192+
}
193+
190194
static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
191195
{
192196
struct inet_connection_sock *icsk = inet_csk(sk);
@@ -225,8 +229,8 @@ static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
225229
if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
226230
what == ICSK_TIME_LOSS_PROBE || what == ICSK_TIME_REO_TIMEOUT) {
227231
smp_store_release(&icsk->icsk_pending, what);
228-
icsk->icsk_timeout = jiffies + when;
229-
sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
232+
when += jiffies;
233+
sk_reset_timer(sk, &icsk->icsk_retransmit_timer, when);
230234
} else if (what == ICSK_TIME_DACK) {
231235
smp_store_release(&icsk->icsk_ack.pending,
232236
icsk->icsk_ack.pending | ICSK_ACK_TIMER);

net/dccp/timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ static void dccp_write_timer(struct timer_list *t)
139139
if (sk->sk_state == DCCP_CLOSED || !icsk->icsk_pending)
140140
goto out;
141141

142-
if (time_after(icsk->icsk_timeout, jiffies)) {
142+
if (time_after(icsk_timeout(icsk), jiffies)) {
143143
sk_reset_timer(sk, &icsk->icsk_retransmit_timer,
144-
icsk->icsk_timeout);
144+
icsk_timeout(icsk));
145145
goto out;
146146
}
147147

net/ipv4/inet_diag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
315315
r->idiag_timer = 1;
316316
r->idiag_retrans = icsk->icsk_retransmits;
317317
r->idiag_expires =
318-
jiffies_delta_to_msecs(icsk->icsk_timeout - jiffies);
318+
jiffies_delta_to_msecs(icsk_timeout(icsk) - jiffies);
319319
} else if (icsk_pending == ICSK_TIME_PROBE0) {
320320
r->idiag_timer = 4;
321321
r->idiag_retrans = icsk->icsk_probes_out;
322322
r->idiag_expires =
323-
jiffies_delta_to_msecs(icsk->icsk_timeout - jiffies);
323+
jiffies_delta_to_msecs(icsk_timeout(icsk) - jiffies);
324324
} else if (timer_pending(&sk->sk_timer)) {
325325
r->idiag_timer = 2;
326326
r->idiag_retrans = icsk->icsk_probes_out;

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,10 +2923,10 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
29232923
icsk_pending == ICSK_TIME_REO_TIMEOUT ||
29242924
icsk_pending == ICSK_TIME_LOSS_PROBE) {
29252925
timer_active = 1;
2926-
timer_expires = icsk->icsk_timeout;
2926+
timer_expires = icsk_timeout(icsk);
29272927
} else if (icsk_pending == ICSK_TIME_PROBE0) {
29282928
timer_active = 4;
2929-
timer_expires = icsk->icsk_timeout;
2929+
timer_expires = icsk_timeout(icsk);
29302930
} else if (timer_pending(&sk->sk_timer)) {
29312931
timer_active = 2;
29322932
timer_expires = sk->sk_timer.expires;

net/ipv4/tcp_timer.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk,
509509
* and tp->rcv_tstamp might very well have been written recently.
510510
* rcv_delta can thus be negative.
511511
*/
512-
rcv_delta = icsk->icsk_timeout - tp->rcv_tstamp;
512+
rcv_delta = icsk_timeout(icsk) - tp->rcv_tstamp;
513513
if (rcv_delta <= timeout)
514514
return false;
515515

@@ -685,7 +685,8 @@ out:;
685685
}
686686

687687
/* Called with bottom-half processing disabled.
688-
Called by tcp_write_timer() */
688+
* Called by tcp_write_timer() and tcp_release_cb().
689+
*/
689690
void tcp_write_timer_handler(struct sock *sk)
690691
{
691692
struct inet_connection_sock *icsk = inet_csk(sk);
@@ -695,11 +696,11 @@ void tcp_write_timer_handler(struct sock *sk)
695696
!icsk->icsk_pending)
696697
return;
697698

698-
if (time_after(icsk->icsk_timeout, jiffies)) {
699-
sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
699+
if (time_after(icsk_timeout(icsk), jiffies)) {
700+
sk_reset_timer(sk, &icsk->icsk_retransmit_timer,
701+
icsk_timeout(icsk));
700702
return;
701703
}
702-
703704
tcp_mstamp_refresh(tcp_sk(sk));
704705
event = icsk->icsk_pending;
705706

net/ipv6/tcp_ipv6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,10 +2195,10 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
21952195
icsk_pending == ICSK_TIME_REO_TIMEOUT ||
21962196
icsk_pending == ICSK_TIME_LOSS_PROBE) {
21972197
timer_active = 1;
2198-
timer_expires = icsk->icsk_timeout;
2198+
timer_expires = icsk_timeout(icsk);
21992199
} else if (icsk_pending == ICSK_TIME_PROBE0) {
22002200
timer_active = 4;
2201-
timer_expires = icsk->icsk_timeout;
2201+
timer_expires = icsk_timeout(icsk);
22022202
} else if (timer_pending(&sp->sk_timer)) {
22032203
timer_active = 2;
22042204
timer_expires = sp->sk_timer.expires;

net/mptcp/protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl
422422
const struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
423423

424424
return inet_csk(ssk)->icsk_pending && !subflow->stale_count ?
425-
inet_csk(ssk)->icsk_timeout - jiffies : 0;
425+
icsk_timeout(inet_csk(ssk)) - jiffies : 0;
426426
}
427427

428428
static void mptcp_set_timeout(struct sock *sk)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ static int dump_tcp_sock(struct seq_file *seq, struct tcp_sock *tp,
9999
icsk->icsk_pending == ICSK_TIME_REO_TIMEOUT ||
100100
icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) {
101101
timer_active = 1;
102-
timer_expires = icsk->icsk_timeout;
102+
timer_expires = icsk->icsk_retransmit_timer.expires;
103103
} else if (icsk->icsk_pending == ICSK_TIME_PROBE0) {
104104
timer_active = 4;
105-
timer_expires = icsk->icsk_timeout;
105+
timer_expires = icsk->icsk_retransmit_timer.expires;
106106
} else if (timer_pending(&sp->sk_timer)) {
107107
timer_active = 2;
108108
timer_expires = sp->sk_timer.expires;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ static int dump_tcp6_sock(struct seq_file *seq, struct tcp6_sock *tp,
9999
icsk->icsk_pending == ICSK_TIME_REO_TIMEOUT ||
100100
icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) {
101101
timer_active = 1;
102-
timer_expires = icsk->icsk_timeout;
102+
timer_expires = icsk->icsk_retransmit_timer.expires;
103103
} else if (icsk->icsk_pending == ICSK_TIME_PROBE0) {
104104
timer_active = 4;
105-
timer_expires = icsk->icsk_timeout;
105+
timer_expires = icsk->icsk_retransmit_timer.expires;
106106
} else if (timer_pending(&sp->sk_timer)) {
107107
timer_active = 2;
108108
timer_expires = sp->sk_timer.expires;

0 commit comments

Comments
 (0)