diff options
Diffstat (limited to 'sys/netinet/cc/cc_cubic.c')
-rw-r--r-- | sys/netinet/cc/cc_cubic.c | 226 |
1 files changed, 105 insertions, 121 deletions
diff --git a/sys/netinet/cc/cc_cubic.c b/sys/netinet/cc/cc_cubic.c index b4050326ae31..b3e15009244d 100644 --- a/sys/netinet/cc/cc_cubic.c +++ b/sys/netinet/cc/cc_cubic.c @@ -38,7 +38,7 @@ /* * An implementation of the CUBIC congestion control algorithm for FreeBSD, - * based on the Internet Draft "draft-rhee-tcpm-cubic-02" by Rhee, Xu and Ha. + * based on the Internet RFC9438 by Xu, Ha, Rhee, Goel, and Eggert. * Originally released as part of the NewTCP research project at Swinburne * University of Technology's Centre for Advanced Internet Architectures, * Melbourne, Australia, which was made possible in part by a grant from the @@ -81,7 +81,7 @@ static void cubic_conn_init(struct cc_var *ccv); static int cubic_mod_init(void); static void cubic_post_recovery(struct cc_var *ccv); static void cubic_record_rtt(struct cc_var *ccv); -static void cubic_ssthresh_update(struct cc_var *ccv, uint32_t maxseg); +static uint32_t cubic_get_ssthresh(struct cc_var *ccv, uint32_t maxseg); static void cubic_after_idle(struct cc_var *ccv); static size_t cubic_data_sz(void); static void cubic_newround(struct cc_var *ccv, uint32_t round_cnt); @@ -125,7 +125,7 @@ cubic_log_hystart_event(struct cc_var *ccv, struct cubic *cubicd, uint8_t mod, u if (hystart_bblogs == 0) return; - tp = ccv->ccvc.tcp; + tp = ccv->tp; if (tcp_bblogging_on(tp)) { union tcp_log_stackspecific log; struct timeval tv; @@ -168,7 +168,8 @@ cubic_does_slow_start(struct cc_var *ccv, struct cubic *cubicd) * doesn't rely on tcpcb vars. */ u_int cw = CCV(ccv, snd_cwnd); - u_int incr = CCV(ccv, t_maxseg); + uint32_t mss = tcp_fixed_maxseg(ccv->tp); + u_int incr = mss; uint16_t abc_val; cubicd->flags |= CUBICFLAG_IN_SLOWSTART; @@ -216,10 +217,9 @@ cubic_does_slow_start(struct cc_var *ccv, struct cubic *cubicd) } if (CCV(ccv, snd_nxt) == CCV(ccv, snd_max)) incr = min(ccv->bytes_this_ack, - ccv->nsegs * abc_val * - CCV(ccv, t_maxseg)); + ccv->nsegs * abc_val * mss); else - incr = min(ccv->bytes_this_ack, CCV(ccv, t_maxseg)); + incr = min(ccv->bytes_this_ack, mss); /* Only if Hystart is enabled will the flag get set */ if (cubicd->flags & CUBICFLAG_HYSTART_IN_CSS) { @@ -236,9 +236,11 @@ static void cubic_ack_received(struct cc_var *ccv, ccsignal_t type) { struct cubic *cubic_data; - unsigned long W_est, W_cubic; + uint32_t W_est, W_cubic, cwin, target, incr; int usecs_since_epoch; + uint32_t mss = tcp_fixed_maxseg(ccv->tp); + cwin = CCV(ccv, snd_cwnd); cubic_data = ccv->cc_data; cubic_record_rtt(ccv); @@ -249,7 +251,7 @@ cubic_ack_received(struct cc_var *ccv, ccsignal_t type) if (type == CC_ACK && !IN_RECOVERY(CCV(ccv, t_flags)) && (ccv->flags & CCF_CWND_LIMITED)) { /* Use the logic in NewReno ack_received() for slow start. */ - if (CCV(ccv, snd_cwnd) <= CCV(ccv, snd_ssthresh) || + if (cwin <= CCV(ccv, snd_ssthresh) || cubic_data->min_rtt_usecs == TCPTV_SRTTBASE) { cubic_does_slow_start(ccv, cubic_data); } else { @@ -264,21 +266,32 @@ cubic_ack_received(struct cc_var *ccv, ccsignal_t type) cubic_data->flags &= ~CUBICFLAG_HYSTART_ENABLED; cubic_log_hystart_event(ccv, cubic_data, 11, CCV(ccv, snd_ssthresh)); } - if ((cubic_data->flags & CUBICFLAG_RTO_EVENT) && - (cubic_data->flags & CUBICFLAG_IN_SLOWSTART)) { - /* RFC8312 Section 4.7 */ - cubic_data->flags &= ~(CUBICFLAG_RTO_EVENT | - CUBICFLAG_IN_SLOWSTART); - cubic_data->W_max = CCV(ccv, snd_cwnd); - cubic_data->t_epoch = ticks; - cubic_data->K = 0; - } else if (cubic_data->flags & (CUBICFLAG_IN_SLOWSTART | + if (cubic_data->flags & (CUBICFLAG_IN_SLOWSTART | + CUBICFLAG_CONG_EVENT | CUBICFLAG_IN_APPLIMIT)) { + /* + * At the beginning of the current congestion + * avoidance stage, The epoch variables + * (t_epoch, cwnd_epoch, K) are updated in the + * following three cases: + * 1) just exited the slow start + * 2) after a congestion event + * 3) application-limited + */ + cubic_data->t_epoch = ticks; + cubic_data->cwnd_epoch = cwin; + cubic_data->K = cubic_k(cubic_data->W_max / mss, + cubic_data->cwnd_epoch / mss); cubic_data->flags &= ~(CUBICFLAG_IN_SLOWSTART | + CUBICFLAG_CONG_EVENT | CUBICFLAG_IN_APPLIMIT); - cubic_data->t_epoch = ticks; - cubic_data->K = cubic_k(cubic_data->W_max / - CCV(ccv, t_maxseg)); + + if (cubic_data->flags & CUBICFLAG_RTO_EVENT) { + /* RFC9438 Section 4.8: Timeout */ + cubic_data->flags &= ~CUBICFLAG_RTO_EVENT; + cubic_data->W_max = cwin; + cubic_data->K = 0; + } } usecs_since_epoch = (ticks - cubic_data->t_epoch) * tick; if (usecs_since_epoch < 0) { @@ -288,52 +301,35 @@ cubic_ack_received(struct cc_var *ccv, ccsignal_t type) usecs_since_epoch = INT_MAX; cubic_data->t_epoch = ticks - INT_MAX; } + W_est = tf_cwnd(ccv); /* - * The mean RTT is used to best reflect the equations in - * the I-D. Using min_rtt in the tf_cwnd calculation - * causes W_est to grow much faster than it should if the - * RTT is dominated by network buffering rather than - * propagation delay. + * The mean RTT is used to best reflect the equations. */ - W_est = tf_cwnd(usecs_since_epoch, cubic_data->mean_rtt_usecs, - cubic_data->W_max, CCV(ccv, t_maxseg)); - W_cubic = cubic_cwnd(usecs_since_epoch + cubic_data->mean_rtt_usecs, cubic_data->W_max, - CCV(ccv, t_maxseg), + mss, cubic_data->K); - ccv->flags &= ~CCF_ABC_SENTAWND; - if (W_cubic < W_est) { + /* RFC9438 Section 4.3: Reno-friendly region */ + CCV(ccv, snd_cwnd) = W_est; + cubic_data->flags |= CUBICFLAG_IN_TF; + } else { /* - * TCP-friendly region, follow tf - * cwnd growth. - */ - if (CCV(ccv, snd_cwnd) < W_est) - CCV(ccv, snd_cwnd) = ulmin(W_est, INT_MAX); - } else if (CCV(ccv, snd_cwnd) < W_cubic) { - /* - * Concave or convex region, follow CUBIC - * cwnd growth. - * Only update snd_cwnd, if it doesn't shrink. + * RFC9438 Section 4.4 or 4.5: + * Concave or Convex Region */ - CCV(ccv, snd_cwnd) = ulmin(W_cubic, INT_MAX); - } - - /* - * If we're not in slow start and we're probing for a - * new cwnd limit at the start of a connection - * (happens when hostcache has a relevant entry), - * keep updating our current estimate of the - * W_max. - */ - if (((cubic_data->flags & CUBICFLAG_CONG_EVENT) == 0) && - cubic_data->W_max < CCV(ccv, snd_cwnd)) { - cubic_data->W_max = CCV(ccv, snd_cwnd); - cubic_data->K = cubic_k(cubic_data->W_max / - CCV(ccv, t_maxseg)); + if (W_cubic < cwin) { + target = cwin; + } else if (W_cubic > ((cwin * 3) >> 1)) { + target = (cwin * 3) >> 1; + } else { + target = W_cubic; + } + incr = (((target - cwin) << CUBIC_SHIFT) / + cwin * mss) >> CUBIC_SHIFT; + CCV(ccv, snd_cwnd) = cwin + incr; } } } else if (type == CC_ACK && !IN_RECOVERY(CCV(ccv, t_flags)) && @@ -350,12 +346,11 @@ cubic_ack_received(struct cc_var *ccv, ccsignal_t type) static void cubic_after_idle(struct cc_var *ccv) { - struct cubic *cubic_data; - - cubic_data = ccv->cc_data; + struct cubic *cubic_data = ccv->cc_data; + uint32_t mss = tcp_fixed_maxseg(ccv->tp); cubic_data->W_max = ulmax(cubic_data->W_max, CCV(ccv, snd_cwnd)); - cubic_data->K = cubic_k(cubic_data->W_max / CCV(ccv, t_maxseg)); + cubic_data->K = cubic_k(cubic_data->W_max / mss, cubic_data->cwnd_epoch / mss); if ((cubic_data->flags & CUBICFLAG_HYSTART_ENABLED) == 0) { /* * Re-enable hystart if we have been idle. @@ -385,7 +380,7 @@ cubic_cb_init(struct cc_var *ccv, void *ptr) { struct cubic *cubic_data; - INP_WLOCK_ASSERT(tptoinpcb(ccv->ccvc.tcp)); + INP_WLOCK_ASSERT(tptoinpcb(ccv->tp)); if (ptr == NULL) { cubic_data = malloc(sizeof(struct cubic), M_CC_MEM, M_NOWAIT|M_ZERO); if (cubic_data == NULL) @@ -394,7 +389,9 @@ cubic_cb_init(struct cc_var *ccv, void *ptr) cubic_data = ptr; /* Init some key variables with sensible defaults. */ - cubic_data->t_epoch = ticks; + cubic_data->t_epoch = 0; + cubic_data->cwnd_epoch = 0; + cubic_data->K = 0; cubic_data->min_rtt_usecs = TCPTV_SRTTBASE; cubic_data->mean_rtt_usecs = 1; @@ -421,10 +418,10 @@ static void cubic_cong_signal(struct cc_var *ccv, ccsignal_t type) { struct cubic *cubic_data; - uint32_t mss, pipe; + uint32_t mss, pipe, ssthresh; cubic_data = ccv->cc_data; - mss = tcp_fixed_maxseg(ccv->ccvc.tcp); + mss = tcp_fixed_maxseg(ccv->tp); switch (type) { case CC_NDUPACK: @@ -436,10 +433,13 @@ cubic_cong_signal(struct cc_var *ccv, ccsignal_t type) } if (!IN_FASTRECOVERY(CCV(ccv, t_flags))) { if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) { - cubic_ssthresh_update(ccv, mss); + ssthresh = cubic_get_ssthresh(ccv, mss); + CCV(ccv, snd_ssthresh) = max(ssthresh, 2 * mss); + /* + * The congestion flag will recalculate K at the + * beginning of the congestion avoidance stage. + */ cubic_data->flags |= CUBICFLAG_CONG_EVENT; - cubic_data->t_epoch = ticks; - cubic_data->K = cubic_k(cubic_data->W_max / mss); } ENTER_RECOVERY(CCV(ccv, t_flags)); } @@ -453,17 +453,20 @@ cubic_cong_signal(struct cc_var *ccv, ccsignal_t type) cubic_log_hystart_event(ccv, cubic_data, 9, CCV(ccv, snd_ssthresh)); } if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) { - cubic_ssthresh_update(ccv, mss); + ssthresh = cubic_get_ssthresh(ccv, mss); + CCV(ccv, snd_ssthresh) = max(ssthresh, 2 * mss); + CCV(ccv, snd_cwnd) = max(ssthresh, mss); + /* + * The congestion flag will recalculate K at the + * beginning of the congestion avoidance stage. + */ cubic_data->flags |= CUBICFLAG_CONG_EVENT; - cubic_data->t_epoch = ticks; - cubic_data->K = cubic_k(cubic_data->W_max / mss); - CCV(ccv, snd_cwnd) = CCV(ccv, snd_ssthresh); ENTER_CONGRECOVERY(CCV(ccv, t_flags)); } break; case CC_RTO: - /* RFC8312 Section 4.7 */ + /* RFC9438 Section 4.8: Timeout */ if (CCV(ccv, t_rxtshift) == 1) { /* * Remember the state only for the first RTO event. This @@ -473,34 +476,25 @@ cubic_cong_signal(struct cc_var *ccv, ccsignal_t type) */ cubic_data->undo_t_epoch = cubic_data->t_epoch; cubic_data->undo_cwnd_epoch = cubic_data->cwnd_epoch; - cubic_data->undo_W_est = cubic_data->W_est; - cubic_data->undo_cwnd_prior = cubic_data->cwnd_prior; cubic_data->undo_W_max = cubic_data->W_max; cubic_data->undo_K = cubic_data->K; - if (V_tcp_do_newsack) { - pipe = tcp_compute_pipe(ccv->ccvc.tcp); - } else { - pipe = CCV(ccv, snd_max) - - CCV(ccv, snd_fack) + - CCV(ccv, sackhint.sack_bytes_rexmit); - } + pipe = tcp_compute_pipe(ccv->tp); CCV(ccv, snd_ssthresh) = max(2, (((uint64_t)min(CCV(ccv, snd_wnd), pipe) * CUBIC_BETA) >> CUBIC_SHIFT) / mss) * mss; } - cubic_data->flags |= CUBICFLAG_CONG_EVENT | CUBICFLAG_RTO_EVENT; - cubic_data->undo_W_max = cubic_data->W_max; - cubic_data->num_cong_events++; + /* + * The RTO flag will recalculate K at the + * beginning of the congestion avoidance stage. + */ + cubic_data->flags |= CUBICFLAG_RTO_EVENT; CCV(ccv, snd_cwnd) = mss; break; case CC_RTO_ERR: - cubic_data->flags &= ~(CUBICFLAG_CONG_EVENT | CUBICFLAG_RTO_EVENT); - cubic_data->num_cong_events--; + cubic_data->flags &= ~CUBICFLAG_RTO_EVENT; cubic_data->K = cubic_data->undo_K; - cubic_data->cwnd_prior = cubic_data->undo_cwnd_prior; cubic_data->W_max = cubic_data->undo_W_max; - cubic_data->W_est = cubic_data->undo_W_est; cubic_data->cwnd_epoch = cubic_data->undo_cwnd_epoch; cubic_data->t_epoch = cubic_data->undo_t_epoch; break; @@ -521,7 +515,7 @@ cubic_conn_init(struct cc_var *ccv) * this here bad things happen when entries from the TCP hostcache * get used. */ - cubic_data->W_max = CCV(ccv, snd_cwnd); + cubic_data->W_max = UINT_MAX; } static int @@ -538,6 +532,7 @@ cubic_post_recovery(struct cc_var *ccv) { struct cubic *cubic_data; int pipe; + uint32_t mss = tcp_fixed_maxseg(ccv->tp); cubic_data = ccv->cc_data; pipe = 0; @@ -547,26 +542,19 @@ cubic_post_recovery(struct cc_var *ccv) * If inflight data is less than ssthresh, set cwnd * conservatively to avoid a burst of data, as suggested in * the NewReno RFC. Otherwise, use the CUBIC method. - * - * XXXLAS: Find a way to do this without needing curack */ - if (V_tcp_do_newsack) - pipe = tcp_compute_pipe(ccv->ccvc.tcp); - else - pipe = CCV(ccv, snd_max) - ccv->curack; - + pipe = tcp_compute_pipe(ccv->tp); if (pipe < CCV(ccv, snd_ssthresh)) /* * Ensure that cwnd does not collapse to 1 MSS under * adverse conditions. Implements RFC6582 */ - CCV(ccv, snd_cwnd) = max(pipe, CCV(ccv, t_maxseg)) + - CCV(ccv, t_maxseg); + CCV(ccv, snd_cwnd) = max(pipe, mss) + mss; else /* Update cwnd based on beta and adjusted W_max. */ CCV(ccv, snd_cwnd) = max(((uint64_t)cubic_data->W_max * CUBIC_BETA) >> CUBIC_SHIFT, - 2 * CCV(ccv, t_maxseg)); + 2 * mss); } /* Calculate the average RTT between congestion epochs. */ @@ -592,7 +580,7 @@ cubic_record_rtt(struct cc_var *ccv) /* Ignore srtt until a min number of samples have been taken. */ if (CCV(ccv, t_rttupdated) >= CUBIC_MIN_RTT_SAMPLES) { cubic_data = ccv->cc_data; - t_srtt_usecs = tcp_get_srtt(ccv->ccvc.tcp, + t_srtt_usecs = tcp_get_srtt(ccv->tp, TCP_TMR_GRANULARITY_USEC); /* * Record the current SRTT as our minrtt if it's the smallest @@ -627,40 +615,36 @@ cubic_record_rtt(struct cc_var *ccv) } /* - * Update the ssthresh in the event of congestion. + * Return the new value for ssthresh in the event of a congestion. */ -static void -cubic_ssthresh_update(struct cc_var *ccv, uint32_t maxseg) +static uint32_t +cubic_get_ssthresh(struct cc_var *ccv, uint32_t maxseg) { struct cubic *cubic_data; - uint32_t ssthresh; - uint32_t cwnd; + uint32_t cwnd, pipe; cubic_data = ccv->cc_data; cwnd = CCV(ccv, snd_cwnd); - /* Fast convergence heuristic. */ + /* RFC9438 Section 4.7: Fast convergence */ if (cwnd < cubic_data->W_max) { cwnd = ((uint64_t)cwnd * CUBIC_FC_FACTOR) >> CUBIC_SHIFT; } - cubic_data->undo_W_max = cubic_data->W_max; cubic_data->W_max = cwnd; - /* - * On the first congestion event, set ssthresh to cwnd * 0.5 - * and reduce W_max to cwnd * beta. This aligns the cubic concave - * region appropriately. On subsequent congestion events, set - * ssthresh to cwnd * beta. - */ - if ((cubic_data->flags & CUBICFLAG_CONG_EVENT) == 0) { - ssthresh = cwnd >> 1; - cubic_data->W_max = ((uint64_t)cwnd * - CUBIC_BETA) >> CUBIC_SHIFT; + if (cubic_data->flags & CUBICFLAG_IN_TF) { + /* If in the TCP friendly region, follow what newreno does. */ + return (newreno_cc_cwnd_on_multiplicative_decrease(ccv, maxseg)); + } else { - ssthresh = ((uint64_t)cwnd * - CUBIC_BETA) >> CUBIC_SHIFT; + /* + * RFC9438 Section 4.6: Multiplicative Decrease + * Outside the TCP friendly region, set ssthresh to the size of + * inflight_size * beta. + */ + pipe = tcp_compute_pipe(ccv->tp); + return ((pipe * CUBIC_BETA) >> CUBIC_SHIFT); } - CCV(ccv, snd_ssthresh) = max(ssthresh, 2 * maxseg); } static void |