Skip to content

Commit

Permalink
tcp: try to avoid safer when ACKs are thinned
Browse files Browse the repository at this point in the history
  • Loading branch information
minuscat committed Jul 16, 2024
1 parent 79efc31 commit 11bba80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/linux/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ struct tcp_sock {
prev_ecnfield:2,/* ECN bits from the previous segment */
accecn_opt_demand:2,/* Demand AccECN option for n next ACKs */
estimate_ecnfield:2;/* ECN field for AccECN delivered estimates */
u16 pkts_acked_ewma;/* EWMA of packets acked for AccECN cep heuristic */
u64 accecn_opt_tstamp; /* Last AccECN option sent timestamp */
u32 lost; /* Total data packets lost incl. rexmits */
u32 app_limited; /* limited until "delivered" reaches this val */
Expand Down
1 change: 1 addition & 0 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,7 @@ int tcp_disconnect(struct sock *sk, int flags)
tcp_accecn_init_counters(tp);
tp->prev_ecnfield = 0;
tp->accecn_opt_tstamp = 0;
tp->pkts_acked_ewma = 0;
if (icsk->icsk_ca_ops->release)
icsk->icsk_ca_ops->release(sk);
memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
Expand Down
20 changes: 19 additions & 1 deletion net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ static void tcp_count_delivered(struct tcp_sock *tp, u32 delivered,
tcp_count_delivered_ce(tp, delivered);
}

#define PKTS_ACKED_WEIGHT 6
#define PKTS_ACKED_PREC 6
#define ACK_COMP_THRESH 4

/* Returns the ECN CE delta */
static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,
u32 delivered_pkts, u32 delivered_bytes, int flag)
Expand All @@ -701,6 +705,19 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,

opt_deltas_valid = tcp_accecn_process_option(tp, skb, delivered_bytes, flag);

if (delivered_pkts) {
if (!tp->pkts_acked_ewma) {
tp->pkts_acked_ewma = delivered_pkts << PKTS_ACKED_PREC;
} else {
u32 ewma = tp->pkts_acked_ewma;

ewma = (((ewma << PKTS_ACKED_WEIGHT) - ewma) +
(delivered_pkts << PKTS_ACKED_PREC)) >>
PKTS_ACKED_WEIGHT;
tp->pkts_acked_ewma = min_t(u32, ewma, 0xFFFFU);
}
}

if (!(flag & FLAG_SLOWPATH)) {
/* AccECN counter might overflow on large ACKs */
if (delivered_pkts <= TCP_ACCECN_CEP_ACE_MASK)
Expand Down Expand Up @@ -752,7 +769,8 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,
return safe_delta;
if (d_ceb < safe_delta * tp->mss_cache >> TCP_ACCECN_SAFETY_SHIFT)
return delta;
}
} else if (tp->pkts_acked_ewma > (ACK_COMP_THRESH << PKTS_ACKED_PREC))
return delta;

return safe_delta;
}
Expand Down

0 comments on commit 11bba80

Please sign in to comment.