Skip to content

Commit

Permalink
Fix inflightHi_ and bandwidthHi_ logic
Browse files Browse the repository at this point in the history
Summary: bandwidthHi_ and inflightHi_ should only be set after loss has occured.

Reviewed By: mjoras

Differential Revision: D49784760

fbshipit-source-id: 99bfb98a7d07849e10fb89aaccf5ff51437d400b
  • Loading branch information
jbeshay authored and facebook-github-bot committed Oct 2, 2023
1 parent 04b0fb5 commit 8a96e08
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
43 changes: 26 additions & 17 deletions quic/congestion_control/Bbr2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void Bbr2CongestionController::resetCongestionSignals() {
}

void Bbr2CongestionController::resetLowerBounds() {
bandwidthLo_ = Bandwidth(std::numeric_limits<uint64_t>::max(), 1us);
bandwidthLo_.reset();
inflightLo_.reset();
}
void Bbr2CongestionController::enterStartup() {
Expand All @@ -234,7 +234,7 @@ void Bbr2CongestionController::setPacing() {
uint64_t pacingWindow =
bandwidth_ * minRtt_ * pacingGain_ * (100 - kPacingMarginPercent) / 100;
VLOG(6) << fmt::format(
"Setting pacing to {}. From bandwdith_={} pacingGain_={} kPacingMarginPercent={} units={} interval={}",
"Setting pacing to {}. From bandwidth_={} pacingGain_={} kPacingMarginPercent={} units={} interval={}",
Bandwidth(pacingWindow, minRtt_).normalizedDescribe(),
bandwidth_.normalizedDescribe(),
pacingGain_,
Expand Down Expand Up @@ -390,15 +390,15 @@ void Bbr2CongestionController::updateCongestionSignals(
}
if (lossBytesInRound_ > 0 && !conn_.transportSettings.ccaConfig.ignoreLoss) {
// InitLowerBounds
if (!bandwidthLo_) {
if (!bandwidthLo_.has_value()) {
bandwidthLo_ = maxBwFilter_.GetBest();
}
if (!inflightLo_.has_value()) {
inflightLo_ = cwndBytes_;
}

// LossLowerBounds
bandwidthLo_ = std::max(bandwidthLatest_, bandwidthLo_ * kBeta);
bandwidthLo_ = std::max(bandwidthLatest_, *bandwidthLo_ * kBeta);
inflightLo_ =
std::max(inflightLatest_, static_cast<uint64_t>(*inflightLo_ * kBeta));
}
Expand Down Expand Up @@ -429,7 +429,6 @@ void Bbr2CongestionController::checkStartupDone() {
checkStartupHighLoss();

if (state_ == State::Startup && filledPipe_) {
bandwidthHi_ = maxBwFilter_.GetBest();
enterDrain();
}
}
Expand Down Expand Up @@ -559,12 +558,17 @@ void Bbr2CongestionController::adaptUpperBounds(
}

if (!checkInflightTooHigh(inflightBytesAtLargestAckedPacket, lostBytes)) {
/* Loss rate is safe. Adjust upper bounds upward. */
if (!inflightHi_.has_value() ||
inflightBytesAtLargestAckedPacket > *inflightHi_) {
if (!inflightHi_.has_value() || !bandwidthHi_.has_value()) {
// No loss has occurred yet so these values are not set and do not need to
// be raised.
return;
}
/* There is loss but it's at safe levels. The limits are populated so we
* update them */
if (inflightBytesAtLargestAckedPacket > *inflightHi_) {
inflightHi_ = inflightBytesAtLargestAckedPacket;
}
if (bandwidthLatest_ > bandwidthHi_) {
if (bandwidthLatest_ > *bandwidthHi_) {
bandwidthHi_ = bandwidthLatest_;
}
if (state_ == State::ProbeBw_Up) {
Expand Down Expand Up @@ -628,6 +632,7 @@ void Bbr2CongestionController::handleInFlightTooHigh(
inflightBytesAtLargestAckedPacket,
static_cast<uint64_t>(
static_cast<float>(getTargetInflightWithGain()) * kBeta));
bandwidthHi_ = maxBwFilter_.GetBest();
}
if (state_ == State::ProbeBw_Up) {
startProbeBwDown();
Expand All @@ -651,9 +656,10 @@ uint64_t Bbr2CongestionController::getTargetInflightWithHeadroom() const {
}

void Bbr2CongestionController::probeInflightHiUpward(uint64_t ackedBytes) {
CHECK(inflightHi_.has_value()) << "probing inflight high before it's set";
if (!cwndLimitedInRound_ || cwndBytes_ < *inflightHi_) {
return; /* not fully using inflight_hi, so don't grow it */
if (!inflightHi_.has_value() || !cwndLimitedInRound_ ||
cwndBytes_ < *inflightHi_) {
return; /* no inflight_hi set or not fully using inflight_hi, so don't grow
it */
}
probeUpAcks_ += ackedBytes;
if (probeUpAcks_ >= probeUpCount_) {
Expand Down Expand Up @@ -750,11 +756,14 @@ void Bbr2CongestionController::boundCwndForProbeRTT() {
}

void Bbr2CongestionController::boundBwForModel() {
if (state_ == State::Startup) {
bandwidth_ = maxBwFilter_.GetBest();
} else {
bandwidth_ =
std::min(std::min(maxBwFilter_.GetBest(), bandwidthLo_), bandwidthHi_);
bandwidth_ = maxBwFilter_.GetBest();
if (state_ != State::Startup) {
if (bandwidthLo_.has_value()) {
bandwidth_ = std::min(bandwidth_, *bandwidthLo_);
}
if (bandwidthHi_.has_value()) {
bandwidth_ = std::min(bandwidth_, *bandwidthHi_);
}
}
if (conn_.qLogger) {
conn_.qLogger->addBandwidthEstUpdate(bandwidth_.units, bandwidth_.interval);
Expand Down
3 changes: 2 additions & 1 deletion quic/congestion_control/Bbr2.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class Bbr2CongestionController : public CongestionController {
// Data Rate Model Parameters
WindowedFilter<Bandwidth, MaxFilter<Bandwidth>, uint64_t, uint64_t>
maxBwFilter_;
Bandwidth bandwidthHi_, bandwidthLo_, bandwidth_;
Bandwidth bandwidth_;
folly::Optional<Bandwidth> bandwidthHi_, bandwidthLo_;
uint64_t cycleCount_{0}; // TODO: this can be one bit

// Data Volume Model Parameters
Expand Down

0 comments on commit 8a96e08

Please sign in to comment.