CBQ(8)
โจ NAME โจ
Okay bestie, this is CBQ(8) from the Linux manual, and it's lowkey iconic. ๐
CBQ โ Class Based Queueing
๐ฆ SYNOPSIS ๐ฆ
Two moods, bestie: one for setting up the qdisc, one for making classes. Copy these exactly, no typos, periodt. โจ
tc qdisc ... dev dev ( parent classid | root) [ handle major: ] cbq [
allot bytes ] avpkt bytes bandwidth rate [ cell bytes ] [ ewma log ] [
mpu bytes ]
tc class ... dev dev parent major:[minor] [ classid major:minor ] cbq
allot bytes [ bandwidth rate ] [ rate rate ] prio priority [ weight
weight ] [ minburst packets ] [ maxburst packets ] [ ewma log ] [ cell
bytes ] avpkt bytes [ mpu bytes ] [ bounded isolated ] [ split handle &
defmap defmap ] [ estimator interval timeconstant ]
๐ DESCRIPTION ๐
Class Based Queueing is a classful qdisc that implements a rich linksharing hierarchy of classes. It's giving shaping elements AND prioritizing capabilities. Shaping is performed using link idle time calculations based on the timing of dequeue events and underlying link bandwidth. No cap. ๐ฆ
๐ SHAPING ALGORITHM ๐
When shaping a 10mbit/s connection to 1mbit/s, the link will be idle 90% of the time. If it isn't, it needs to be throttled so that it IS idle 90% of the time. Like, it's not optional. ๐ญ
During operations, the effective idletime is measured using an exponential weighted moving average (EWMA), which considers recent packets to be exponentially more important than past ones. The Unix loadaverage is calculated in the same way. Fr fr.
The calculated idle time is subtracted from the EWMA measured one, the resulting number is called avgidle. A perfectly loaded link has an avgidle of zero: packets arrive exactly at the calculated interval. Iconic behavior. โจ
An overloaded link has a negative avgidle and if it gets too negative, CBQ throttles and is then overlimit. It's giving overwhelmed. ๐
Conversely, an idle link might amass a huge avgidle, which would then allow infinite bandwidths after a few hours of silence. To prevent this, avgidle is capped at maxidle. Thank u, next. ๐ซถ
If overlimit, in theory, the CBQ could throttle itself for exactly the amount of time that was calculated to pass between packets, and then pass one packet, and throttle again. Due to timer resolution constraints, this may not be feasible, see the minburst parameter below. Don't come for me, that's literally what it says. ๐
๐ CLASSIFICATION ๐
Within the one CBQ instance many classes may exist. Each of these classes contains another qdisc, by default tc-pfifo(8). Cute. ๐
When enqueueing a packet, CBQ starts at the root and uses various methods to determine which class should receive the data. Main character energy.
In the absence of uncommon configuration options, the process is rather easy. At each node we look for an instruction, and then go to the class the instruction refers us to. If the class found is a barren leaf-node (without children), we enqueue the packet there. If it is not yet a leaf node, we do the whole thing over again starting from that node. Recursion? We love to see it. ๐
The following actions are performed, in order at each node we visit, until one sends us to another node, or terminates the process. Vibe check, in order:
- (i) Consult filters attached to the class. If sent to a leafnode, we are done. Otherwise, restart.
- (ii) Consult the
defmapfor the priority assigned to this packet, which depends on the TOS bits. Check if the referral is leafless, otherwise restart. - (iii) Ask the
defmapfor instructions for the'best effort'priority. Check the answer for leafness, otherwise restart. - (iv) If none of the above returned with an instruction, enqueue at this node.
This algorithm makes sure that a packet always ends up somewhere, even while you are busy building your configuration. Periodt. ๐
For more details, see tc-cbq-details(8). Iykyk.
๐ LINK SHARING ALGORITHM ๐
When dequeuing for sending to the network device, CBQ decides which of its classes will be allowed to send. It does so with a Weighted Round Robin process in which each class with packets gets a chance to send in turn. The WRR process starts by asking the highest priority classes (lowest numerically - highest semantically) for packets, and will continue to do so until they have no more data to offer, in which case the process repeats for lower priorities. It's giving fair but with hierarchy. ๐
Classes by default borrow bandwidth from their siblings. A class can be prevented from doing so by declaring it bounded. A class can also indicate its unwillingness to lend out bandwidth by being isolated. Boundaries, bestie. ๐ฆ
๐ QDISC ๐
The root of a CBQ qdisc class tree has the following parameters. Obsessed with a parameter list, ngl. โจ
parent major:minor | rootโ This mandatory parameter determines the place of the CBQ instance, either at the root of an interface or within an existing class. Mandatory, so no skipping. ๐handle major:โ Like all other qdiscs, the CBQ can be assigned a handle. Should consist only of a major number, followed by a colon. Optional, but very useful if classes will be generated within this qdisc. Lowkey a glow-up for your setup. ๐allot bytesโ This allotment is the'chunkiness'of link sharing and is used for determining packet transmission time tables. The qdisc allot differs slightly from the class allot discussed below. Optional. Defaults to a reasonable value, related toavpkt. Chunkiness? Iconic word. ๐avpkt bytesโ The average size of a packet is needed for calculatingmaxidle, and is also used for making sure'allot'has a safe value. Mandatory. No avpkt, no vibe. ๐ญbandwidth rateโ To determine the idle time, CBQ must know the bandwidth of your underlying physical interface, or parent qdisc. This is a vital parameter, more about it later. Mandatory. Vital, bestie, like water. ๐งcellโ The cell size determines the granularity of packet transmission time calculations. Has a sensible default. Slay. โจmpuโ A zero sized packet may still take time to transmit. This value is the lower cap for packet transmission time calculations - packets smaller than this value are still deemed to have this size. Defaults to zero. Zero-sized but still taking time? The way that works. ๐ewma logโ When CBQ needs to measure the average idle time, it does so using an Exponentially Weighted Moving Average which smooths out measurements into a moving average. The EWMA LOG determines how much smoothing occurs. Lower values imply greater sensitivity. Must be between0and31. Defaults to5. Smoothing, sensitivity, range, default. We love a well-behaved parameter. ๐ซถ
A CBQ qdisc does not shape out of its own accord. It only needs to know certain parameters about the underlying link. Actual shaping is done in classes. So like, the qdisc is the planner, classes do the work. ๐
๐ CLASSES ๐
okay bestie, classes are where the actual โจmagicโจ happens โ each one has a whole lil wardrobe of parameters to tune how it operates. let's get into it ๐
parent major:minorโ where this class sits in the family tree ๐ณ. if it's attached straight onto a qdisc and not to another class, you can dip out on theminorpart. this one is Mandatory, no skipping.classid major:minorโ just like qdiscs, classes get names too ๐ท๏ธ. the catch: themajornumber has to match the major number of the qdisc it belongs to, no cap. it's Optionalโฆ but bestie, if this class is ever gonna have children, you need it.weight weightโ when we're dequeuing to the interface, classes get tried round-robin style ๐. classes with a higher configured qdisc will generally have more traffic to offer during each round, so it lowkey makes sense to let them dequeue more. all the weights under a class get normalized, so only the ratios matter, iykyk. it Defaults to the configured rate โ unless this class's priority is maximal, in which case it's set to1. iconic.allot bytesโ tells you how many bytes a qdisc can dequeue during each round of the process. this param gets weighted using the renormalized class weight from above โ๏ธ. and it gets Silently capped at a minimum of3/2 avpkt. Mandatory fr fr.prio priorityโ in the round-robin process, classes with the lowest priority field get tried for packets first ๐ฅ. Mandatory.avpktโ see the QDISC section, bestie, it's all there ๐.rate rateโ the max rate this class and all its children combined can send at ๐ฆ. Mandatory.bandwidth rateโ โ ๏ธ heads up, this is different from the bandwidth you specify when creating a CBQ disc!! it's only used to determinemaxidleandofftime, and those only get calculated when you specifymaxburstorminburst. Mandatory if specifying maxburst or minburst.maxburstโ this number of packets is used to calculatemaxidle, so that whenavgidleis atmaxidle, this many average packets can burst beforeavgidledrops to0๐ฅ. set it higher if you wanna be more tolerant of bursts. you literally can't setmaxidledirectly โ only via this parameter. periodt.minburstโ as mentioned before, CBQ has to throttle when there's an overlimit. the ideal solution is to throttle for exactly the calculated idle time and pass1packet. but ๐ญ Unix kernels generally have a hard time scheduling events shorter than10ms, so it's better to throttle for a longer period, then passminburstpackets in one go, and then sleepminbursttimes longer.
the time to wait is called the offtime. higher values of minburst lead to more accurate shaping in the long term, but bigger bursts at millisecond timescales. Optional.
minidleโ ifavgidleis below0, we're overlimits and gotta wait untilavgidleis big enough to send one packet ๐ซ . and to prevent a sudden burst from shutting down the link for a prolonged period of time,avgidlegets reset tominidleif it gets too low.
minidle is specified in negative microseconds, so 10 means avgidle is capped at -10us. Optional.
boundedโ signifies that this class will not borrow bandwidth from its siblings ๐ซ.isolatedโ means this class will not borrow bandwidth to its siblings.split major:minor&defmap bitmap[/bitmap]โ so if consulting the filters attached to a class didn't give a verdict, CBQ can also classify based on the packet's priority โจ. there are16priorities available, numbered from0to15.
the defmap specifies which priorities this class wants to receive, as a bitmap ๐บ๏ธ. the Least Significant Bit corresponds to priority zero. the split parameter tells CBQ at which class the decision must be made โ and that should be a (grand)parent of the class you're adding.
as an example, this here:
tc class add ... classid 10:1 cbq .. split 10:0 defmap c0
configures class 10:0 to send packets with priorities 6 and 7 to 10:1.
and the complimentary configuration would then be:
tc class add ... classid 10:2 cbq ... split 10:0 defmap 3f
which would send all packets 0, 1, 2, 3, 4 and 5 to 10:1. slay ๐
estimator interval timeconstantโ CBQ can measure how much bandwidth each class is using ๐, and tc filters can use that to classify packets with. to determine the bandwidth it uses a very simple estimator that measures once everyintervalmicroseconds how much traffic has passed. this again is a EWMA, for which thetimeconstantcan be specified, also in microseconds. the time constant corresponds to the sluggishness of the measurement โ or, conversely, to the sensitivity of the average to short bursts. higher values mean less sensitivity. got it? got it ๐
๐ BUGS ๐
not everything is giving flawless, bestie, so let's be real:
- the actual bandwidth of the underlying link may not be known ๐ญ โ for example with
PPoEorPPTPconnections, which in fact may send over a pipe instead of over a physical device. CBQ is quite resilient to major errors in the configured bandwidth, probably at the cost of coarser shaping. - default kernels rely on coarse timing information for making decisions. these may make shaping precise in the long term, but inaccurate on second long scales โณ.
- see
tc-cbq-details(8)for hints on how to improve this ๐ซถ
๐ SOURCES ๐
the receipts, bestie ๐งพ:
- Sally Floyd and Van Jacobson, "Link-sharing and Resource Management Models for Packet Networks", IEEE/ACM Transactions on Networking, Vol.3, No.4, 1995
- Sally Floyd, "Notes on CBQ and Guaranteed Service", 1995
- Sally Floyd, "Notes on Class-Based Queueing: Setting Parameters", 1996
- Sally Floyd and Michael Speer, "Experimental Results for Class-Based Queueing", 1998, not published.
๐ SEE ALSO ๐
๐ AUTHOR ๐
- Alexey N. Kuznetsov,
<kuznet@ms2.inr.ac.ru>. This manpage maintained by bert hubert<ahu@ds9a.nl>
and that's a wrap on CBQ(8) bestie ๐ this one's from the iproute2 crew, dated 16 December 2001. go forth and shape that traffic responsibly, mwah ๐
โจ๐ฆ
๐ฆ where this page comes from
- debian bookworm: iproute2 6.1.0-3 ยท 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
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms