CBS(8)
โจ NAME โจ
okay bestie, this page is all about CBS, the Credit Based Shaper ๐ It's a qdisc (a queueing discipline), and it's lowkey iconic for traffic control on Linux ๐ง
๐ SYNOPSIS ๐
tc qdisc ... dev dev parent classid [ handle major: ] cbs idleslope
idleslope sendslope sendslope hicredit hicredit locredit locredit [
offload 0|1 ]
๐ฆ DESCRIPTION ๐ฆ
so the CBS (Credit Based Shaper) qdisc runs the shaping algorithm from IEEE 802.1Q-2014 Section 8.6.8.2. It's a well-defined way to rate limit your traffic, and it's giving precision ๐
this one is made for TSN (Time Sensitive Networking) apps ๐ง The CBS parameters come straight from Annex L of the IEEE 802.1Q-2014 spec. The algorithm and how it affects latency are explained there, so go read it if you're curious ๐ธ
CBS is supposed to sit under another qdisc that maps packet flows to traffic classes. One example is mqprio(8) โจ
๐ PARAMETERS ๐
idleslope
ok this is the main tunable of the whole CBS algorithm ๐ฅ idleslope is the rate at which credits pile up, measured in kilobits per second, whenever there's at least one packet waiting to go. Packets get transmitted when the current credits are equal to or greater than zero. If there's nothing to send, the credits get reset to zero. This value basically decides how much bandwidth gets eaten.
โ ๏ธ also, when you calculate idleslope, you have to count the entire packet size, including headers from every layer (MAC framing plus any physical layer overhead). See IEEE 802.1Q-2014 section 34.4.
here's an example ๐ Say you've got an ethernet frame with 284 bytes of payload and no VLAN tags. You add 14 bytes for the Ethernet headers, 4 bytes for the Frame check sequence (CRC), and 20 bytes for the L1 overhead (that's 12 bytes of interpacket gap, 7 bytes of preamble, and 1 byte of start of frame delimiter). That gives you 322 bytes total, and that's the number used for the idleslope calculation ๐
sendslope
sendslope is the rate at which credits get used up while a transmission is happening ๐ It should be a negative number of kilobits per second. You calculate it like this (IEEE 802.1Q-2014 Section 8.6.8.2 item g):
sendslope = idleslope - port_transmit_rate
hicredit
hicredit is the maximum amount of credits (in bytes) that can build up ๐ It depends on the traffic that's interfering with you. max_interference_size is the biggest burst of traffic that can hold up a frame waiting to go out for this traffic class (IEEE 802.1Q-2014 Annex L, Equation L-3):
hicredit = max_interference_size * (idleslope / port_transmit_rate)
locredit
locredit is the minimum amount of credits that can be reached ๐ It depends on the traffic going through this qdisc (IEEE 802.1Q-2014 Annex L, Equation L-2):
locredit = max_frame_size * (sendslope / port_transmit_rate)
offload
when offload is 1, cbs(8) will try to configure the network interface so the CBS algorithm runs on the controller ๐ง The default is 0.
๐ EXAMPLES ๐
CBS is how you enforce Quality of Service by limiting the data rate of a traffic class ๐ To split packets into traffic classes, you can use mqprio(8), and you set it up like this:
# tc qdisc add dev eth0 handle 100: parent root mqprio num_tc 3 \
map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \
queues 1@0 1@1 2@2 \
hw 0
Next, to replace the current queueing discipline on traffic class number 0 with CBS, run:
# tc qdisc replace dev eth0 parent 100:4 cbs \
locredit -1470 hicredit 30 sendslope -980000 idleslope 20000
those values come from these parameters: idleslope is 20mbit/s, the transmission rate is 1Gbit/s, and the maximum interfering frame size is 1500 bytes ๐ซถ
๐ AUTHORS ๐
Vinicius Costa Gomes <vinicius.gomes@intel.com> ๐ธ
okay that's the whole CBS tea โ From iproute2, dated 18 Sept 2017. Go forth and shape your traffic, bestie ๐๐ฆโจ
๐ฆ where this page comes from
- alpine 3.22: iproute2-doc 6.15.0-r0 ยท GPL-2.0-or-later
- alpine 3.23: iproute2-doc 6.17.0-r0 ยท GPL-2.0-or-later
- alpine 3.24: iproute2-doc 7.0.0-r0 ยท GPL-2.0-or-later
- arch rolling: iproute2 7.2.0-1
- arch rolling: iproute2 7.3.0-1 ยท GPL-2.0-or-later
- centos-stream 10: iproute-tc 7.0.0-2.el10 ยท GPL-2.0-or-later
- centos-stream 9: iproute-tc 6.17.0-3.el9 ยท GPL-2.0-or-later
- debian bookworm: iproute2 6.1.0-3 ยท GPL-2.0-only
- debian trixie: iproute2 6.15.0-1 ยท GPL-2.0-only
- fedora 43: iproute-tc 6.14.0-2.fc43 ยท GPL-2.0-or-later
- fedora 44: iproute-tc 6.17.0-2.fc44 ยท GPL-2.0-or-later
- nixos 26.05: iproute2 7.0.0
- nixpkgs unstable: iproute2 7.2.0
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- ubuntu jammy: iproute2 5.15.0-1ubuntu2 ยท GPL-2.0-only
- ubuntu jammy: iproute2 5.15.0-1ubuntu2.2 ยท GPL-2.0-only
- ubuntu noble: iproute2 6.1.0-1ubuntu6 ยท GPL-2.0-only
- ubuntu noble: iproute2 6.1.0-1ubuntu6.4 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2
- ubuntu questing: iproute2 6.16.0-1ubuntu2.1 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2.2
- ubuntu resolute: iproute2 6.19.0-1ubuntu1 ยท GPL-2.0-only
- ubuntu resolute: iproute2 6.19.0-1ubuntu1.1 ยท GPL-2.0-only
- ubuntu stonking: iproute2 7.2.0-1ubuntu1 ยท GPL-2.0-only
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms