Skip to content

Commit b8e4001

Browse files
David Morleyopsiff
authored andcommitted
tcp: record last received ipv6 flowlabel
mainline inclusion from mainline-v6.7-rc1 category: performance In order to better estimate whether a data packet has been retransmitted or is the result of a TLP, we save the last received ipv6 flowlabel. To make space for this field we resize the "ato" field in inet_connection_sock as the current value of TCP_DELACK_MAX can be fully contained in 8 bits and add a compile_time_assert ensuring this field is the required size. v2: addressed kernel bot feedback about dccp_delack_timer() v3: addressed build error introduced by commit bbf80d7 ("tcp: derive delack_max from rto_min") Signed-off-by: David Morley <morleyd@google.com> Signed-off-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: Yuchung Cheng <ycheng@google.com> Tested-by: David Morley <morleyd@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> (cherry picked from commit 95b9a87) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 3b6791c commit b8e4001

6 files changed

Lines changed: 26 additions & 6 deletions

File tree

include/net/inet_connection_sock.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ struct inet_connection_sock {
117117
__u8 quick; /* Scheduled number of quick acks */
118118
__u8 pingpong; /* The session is interactive */
119119
__u8 retry; /* Number of attempts */
120-
__u32 ato; /* Predicted tick of soft clock */
120+
#define ATO_BITS 8
121+
__u32 ato:ATO_BITS, /* Predicted tick of soft clock */
122+
lrcv_flowlabel:20, /* last received ipv6 flowlabel */
123+
unused:4;
121124
unsigned long timeout; /* Currently scheduled timeout */
122125
__u32 lrcvtime; /* timestamp of last received data packet */
123126
__u16 last_seg_size; /* Size of last incoming segment */

include/net/tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
133133
#define TCP_FIN_TIMEOUT_MAX (120 * HZ) /* max TCP_LINGER2 value (two minutes) */
134134

135135
#define TCP_DELACK_MAX ((unsigned)(HZ/5)) /* maximal time to delay before sending an ACK */
136+
static_assert((1 << ATO_BITS) > TCP_DELACK_MAX);
137+
136138
#if HZ >= 100
137139
#define TCP_DELACK_MIN ((unsigned)(HZ/25)) /* minimal time to delay before sending an ACK */
138140
#define TCP_ATO_MIN ((unsigned)(HZ/25))

net/dccp/timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ static void dccp_delack_timer(struct timer_list *t)
196196
if (inet_csk_ack_scheduled(sk)) {
197197
if (!inet_csk_in_pingpong_mode(sk)) {
198198
/* Delayed ACK missed: inflate ATO. */
199-
icsk->icsk_ack.ato = min(icsk->icsk_ack.ato << 1,
200-
icsk->icsk_rto);
199+
icsk->icsk_ack.ato = min_t(u32, icsk->icsk_ack.ato << 1,
200+
icsk->icsk_rto);
201201
} else {
202202
/* Delayed ACK missed: leave pingpong mode and
203203
* deflate ATO.

net/ipv4/tcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3813,8 +3813,8 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
38133813
info->tcpi_options |= TCPI_OPT_SYN_DATA;
38143814

38153815
info->tcpi_rto = jiffies_to_usecs(icsk->icsk_rto);
3816-
info->tcpi_ato = jiffies_to_usecs(min(icsk->icsk_ack.ato,
3817-
tcp_delack_max(sk)));
3816+
info->tcpi_ato = jiffies_to_usecs(min_t(u32, icsk->icsk_ack.ato,
3817+
tcp_delack_max(sk)));
38183818
info->tcpi_snd_mss = tp->mss_cache;
38193819
info->tcpi_rcv_mss = icsk->icsk_ack.rcv_mss;
38203820

net/ipv4/tcp_input.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,16 @@ void tcp_rcv_space_adjust(struct sock *sk)
805805
tp->rcvq_space.time = tp->tcp_mstamp;
806806
}
807807

808+
static void tcp_save_lrcv_flowlabel(struct sock *sk, const struct sk_buff *skb)
809+
{
810+
#if IS_ENABLED(CONFIG_IPV6)
811+
struct inet_connection_sock *icsk = inet_csk(sk);
812+
813+
if (skb->protocol == htons(ETH_P_IPV6))
814+
icsk->icsk_ack.lrcv_flowlabel = ntohl(ip6_flowlabel(ipv6_hdr(skb)));
815+
#endif
816+
}
817+
808818
/* There is something which you must keep in mind when you analyze the
809819
* behavior of the tp->ato delayed ack timeout interval. When a
810820
* connection starts up, we want to ack as quickly as possible. The
@@ -853,6 +863,7 @@ static void tcp_event_data_recv(struct sock *sk, struct sk_buff *skb)
853863
}
854864
}
855865
icsk->icsk_ack.lrcvtime = now;
866+
tcp_save_lrcv_flowlabel(sk, skb);
856867

857868
tcp_ecn_check_ce(sk, skb);
858869

@@ -4608,6 +4619,9 @@ static void tcp_rcv_spurious_retrans(struct sock *sk, const struct sk_buff *skb)
46084619
if (TCP_SKB_CB(skb)->seq == tcp_sk(sk)->duplicate_sack[0].start_seq &&
46094620
sk_rethink_txhash(sk))
46104621
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPDUPLICATEDATAREHASH);
4622+
4623+
/* Save last flowlabel after a spurious retrans. */
4624+
tcp_save_lrcv_flowlabel(sk, skb);
46114625
}
46124626

46134627
static void tcp_send_dupack(struct sock *sk, const struct sk_buff *skb)
@@ -4924,6 +4938,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
49244938
u32 seq, end_seq;
49254939
bool fragstolen;
49264940

4941+
tcp_save_lrcv_flowlabel(sk, skb);
49274942
tcp_ecn_check_ce(sk, skb);
49284943

49294944
if (unlikely(tcp_try_rmem_schedule(sk, skb, skb->truesize))) {

net/ipv4/tcp_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void tcp_delack_timer_handler(struct sock *sk)
318318
if (inet_csk_ack_scheduled(sk)) {
319319
if (!inet_csk_in_pingpong_mode(sk)) {
320320
/* Delayed ACK missed: inflate ATO. */
321-
icsk->icsk_ack.ato = min(icsk->icsk_ack.ato << 1, icsk->icsk_rto);
321+
icsk->icsk_ack.ato = min_t(u32, icsk->icsk_ack.ato << 1, icsk->icsk_rto);
322322
} else {
323323
/* Delayed ACK missed: leave pingpong mode and
324324
* deflate ATO.

0 commit comments

Comments
 (0)