Skip to content

Commit 3b78429

Browse files
edumazetkuba-moo
authored andcommitted
tcp: add a fast path in tcp_write_timer()
retransmit timer is not stopped from inet_csk_clear_xmit_timer() because we do not define INET_CSK_CLEAR_TIMERS. This is a conscious choice : for active TCP flows, it is better to only call mod_timer(), because there is more chances of keeping the timer unchanged. Also inet_csk_clear_xmit_timer() is often called from another cpu, and calling del_timer() would cause false sharing and lock contention. This means that very often, tcp_write_timer() is called at the timer expiration, while there is nothing to retransmit. This can be detected very early, avoiding the socket spinlock. Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20241002173042.917928-3-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5a9071a commit 3b78429

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

net/ipv4/tcp_timer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ static void tcp_write_timer(struct timer_list *t)
717717
from_timer(icsk, t, icsk_retransmit_timer);
718718
struct sock *sk = &icsk->icsk_inet.sk;
719719

720+
/* Avoid locking the socket when there is no pending event. */
721+
if (!smp_load_acquire(&icsk->icsk_pending))
722+
goto out;
723+
720724
bh_lock_sock(sk);
721725
if (!sock_owned_by_user(sk)) {
722726
tcp_write_timer_handler(sk);
@@ -726,6 +730,7 @@ static void tcp_write_timer(struct timer_list *t)
726730
sock_hold(sk);
727731
}
728732
bh_unlock_sock(sk);
733+
out:
729734
sock_put(sk);
730735
}
731736

0 commit comments

Comments
 (0)