Fix BBR SendAllowance calculation overflow and unit conversion#5236
Fix BBR SendAllowance calculation overflow and unit conversion#5236
Conversation
|
Hey, this should be a simple type elevation. |
|
No, your understanding is wrong. Just elevate the type of SendAllowance to 64 bit. |
Co-authored-by: csujedihy <6022514+csujedihy@users.noreply.github.com>
Co-authored-by: csujedihy <6022514+csujedihy@users.noreply.github.com>
You're absolutely right. I've implemented the type elevation approach - changed SendAllowance from uint32_t to uint64_t to prevent overflow, rather than changing the formula. Much simpler and cleaner solution. (7fc830d)
Thanks for the clarification! I've implemented the type elevation approach you suggested - the SendAllowance variable is now uint64_t with overflow protection capping at UINT32_MAX. This preserves the original mathematical intent while preventing overflow. (7fc830d) |
|
Actually, your first iteration makes sense.
|
|
Basically, wherever allowance is stored, it needs to be 64 bit wide. |
…pe elevation Co-authored-by: csujedihy <6022514+csujedihy@users.noreply.github.com>
You're absolutely right! I've implemented the comprehensive solution you suggested - restored the unit conversion from the first iteration AND changed SendAllowance types throughout the system. The fix now properly converts units (time and bits to bytes) while using uint64_t types in congestion control interfaces, packet builder, and path structures to prevent overflow. (c56940d) |
…nt64_t Co-authored-by: csujedihy <6022514+csujedihy@users.noreply.github.com>
Completed - all allowance storage is now 64-bit wide throughout the system. Fixed the final CUBIC |
Problem
The BBR congestion control algorithm's
BbrCongestionControlGetSendAllowancefunction had incorrect unit conversion that caused integer overflow at high bandwidth scenarios (6+ Gbps), severely limiting throughput.Root Cause
The calculation was missing two critical unit conversions:
Before (broken):
This formula has dimensional issues:
BandwidthEst: bits per secondTimeSinceLastSend: microseconds(bits/sec × microseconds)without proper unit conversionIssue manifestation:
Solution
Added proper unit conversions following the pattern used elsewhere in BBR code:
After (fixed):
This correctly converts:
/kMicroSecsInSec- Convert time from microseconds to seconds/BW_UNIT- Convert bits to bytesVerification
Added unit test demonstrating the fix:
The corrected calculation produces ~2.16 MB for 6 Gbps over 1ms with pacing gain, which is mathematically correct:
(6×10⁹ × 2.885 × 0.001) / 8 ≈ 2.16×10⁶ bytes.Changes
src/core/bbr.c(lines 656, 659)Fixes #4889.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.