CBQ(8)
๐ CBQ(8) โ Class Based Queueing ๐
okay bestie, sit down, hydrate, because we're about to talk about the Linux traffic control page for CBQ โ Class Based Queueing โ and it's giving main character energy the whole way through. ๐ this is a big one, so buckle up. it comes in multiple parts and this is part one. let's go. โจ
๐ธ NAME ๐ธ
CBQ โ Class Based Queueing. that's it, that's the name, periodt. ๐
๐ฆ SYNOPSIS ๐ฆ
tc qdisc ... dev dev ( parent classid | root) [ handle major: ] cbq
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 ]
like, copy those exactly, bestie, do not freestyle the flags. ๐
๐ DESCRIPTION ๐
so. Class Based Queueing is a classful qdisc, which is just a fancy way of saying it implements a rich linksharing hierarchy of classes. it's giving organizational chart but for packets. ๐
it's got shaping elements and prioritizing capabilities, so it can do both at once, which, iconic honestly.
the shaping part? it's done using link idle time calculations, based on the timing of dequeue events and the underlying link bandwidth. that's the whole vibe. ๐ฐ๏ธ
๐ฅ SHAPING ALGORITHM ๐ฅ
okay so shaping is done using link idle time calculations, and then actions get taken if those calculations deviate from the set limits. simple enough, right? bestie, it is not simple enough.
picture this: when you're shaping a 10mbit/s connection down to 1mbit/s, the link will be idle 90% of the time. and if it isn't idle 90% of the time? it needs to be throttled so that it IS idle 90% of the time. that's the assignment. ๐
from the kernel's perspective this is genuinely hard to measure, so CBQ instead derives the idle time from the number of microseconds (in fact, jiffies) that elapse between requests from the device driver for more data. combine that with knowledge of packet sizes, and you get an approximation of how full or empty the link is. no cap.
ngl, this is rather circumspect and it doesn't always arrive at proper results. for example: what even is the actual link speed of an interface that isn't really able to transmit the full 100mbit/s of data, maybe because of a badly implemented driver? ๐ค a PCMCIA network card will also never achieve 100mbit/s because of the way the bus is designed โ so again, how do we calculate the idle time? nobody knows, babe.
and the physical link bandwidth may be ill defined in the case of not-quite-real network devices like PPP over Ethernet or PPTP over TCP/IP. in that case the effective bandwidth is probably determined by the efficiency of pipes to userspace โ which, and I cannot stress this enough, is not defined. ๐ซ
during operations, the effective idletime is measured using an exponential weighted moving average (EWMA), which treats recent packets as exponentially more important than past ones. the Unix loadaverage is calculated in the same way. so it's the same technique your uptime is doing. slay, I guess. โญ
the calculated idle time gets subtracted from the EWMA-measured one, and the resulting number is called avgidle. a perfectly loaded link has an avgidle of zero โ packets arrive exactly at the calculated interval. chef's kiss. ๐
an overloaded link has a negative avgidle, and if it gets too negative, CBQ throttles and is then 'overlimit'.
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.
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 then throttle again. in theory. but due to timer resolution constraints, this may not be feasible โ see the minburst parameter below. ๐
๐ CLASSIFICATION ๐
within the one CBQ instance, many classes may exist. and each of these classes contains another qdisc โ by default, tc-pfifo(8). it's classes all the way down. ๐ข
when enqueueing a packet, CBQ starts at the root and uses various methods to figure out which class should receive the data. if a verdict is reached, this process is repeated for the recipient class, which might have further means of classifying traffic to its children, if any. recursion, but make it networking. โจ
CBQ has the following methods available to classify a packet to any child classes:
skb->priorityclass encoding. can be set from userspace by an application with theSO_PRIORITYsetsockopt. theskb->priorityclass encoding only applies if theskb->priorityholds amajor:minorhandle of an existing class within this qdisc.- tc filters attached to the class.
- the
defmapof a class, as set with thesplit & defmapparameters. thedefmapmay contain instructions for each possible Linux packet priority.
each class also has a level. leaf nodes, attached to the bottom of the class hierarchy, have a level of 0. ๐ฑ
๐ง CLASSIFICATION ALGORITHM ๐ง
classification is a loop, which terminates when a leaf class is found. at any point the loop may jump to the fallback algorithm. okay so here's the loop, step by step:
- if the packet is generated locally and has a valid
classidencoded within itsskb->priority, choose it and terminate. ๐ - consult the tc filters, if any, attached to this child. if these return a class which is not a leaf class, restart the loop from the class returned. if it is a leaf, choose it and terminate.
- if the tc filters did not return a class, but did return a
classid, try to find a class with that id within this qdisc. check if the found class is of a lower level than the current class. if so, and the returned class is not a leaf node, restart the loop at the found class. if it is a leaf node, terminate. if we found an upward reference to a higher level, enter the fallback algorithm. โฌ๏ธ - if the tc filters did not return a class, nor a valid reference to one, consider the minor number of the reference to be the priority. retrieve a class from the
defmapof this class for the priority. if this did not contain a class, consult thedefmapof this class for theBEST_EFFORTclass. if this is an upward reference, or noBEST_EFFORTclass was defined, enter the fallback algorithm. if a valid class was found, and it is not a leaf node, restart the loop at this class. if it is a leaf, choose it and terminate. if neither the priority distilled from theclassid, nor theBEST_EFFORTpriority yielded a class, enter the fallback algorithm.
and the fallback algorithm lives outside of the loop, and it goes like this:
- consult the
defmapof the class at which the jump to fallback occurred. if thedefmapcontains a class for the priority of the class (which is related to the TOS field), choose this class and terminate. - consult the map for a class for the
BEST_EFFORTpriority. if found, choose it, and terminate. - choose the class at which break out to the fallback algorithm occurred. terminate. ๐ซถ
the packet is enqueued to the class which was chosen when either algorithm terminated. it is therefore possible for a packet to be enqueued not at a leaf node, but in the middle of the hierarchy. plot twist! ๐ญ
๐ 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. ๐
CERTAINTY ENDS HERE, ANK PLEASE HELP
each class is not allowed to send at length though โ they can only dequeue a configurable amount of data during each round.
if a class is about to go overlimit, and it is not bounded, it will try to borrow avgidle from siblings that are not isolated. this process is repeated from the bottom upwards. if a class is unable to borrow enough avgidle to send a packet, it is throttled and not asked for a packet for enough time for the avgidle to increase above zero. sharing is caring but only if you're not isolated, bestie. ๐
I REALLY NEED HELP FIGURING THIS OUT. REST OF DOCUMENT IS PRETTY CERTAIN AGAIN.
โญ QDISC โญ
the root qdisc of a CBQ class tree has the following parameters:
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.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.avpkt bytesโ for calculations, the average packet size must be known. it is silently capped at a minimum of 2/3 of the interface MTU. mandatory. ๐ค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.cellโ the cell size determines the granularity of packet transmission time calculations. has a sensible default.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.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. defaults to 5. lower values imply greater sensitivity. must be between 0 and 31. ๐๏ธ
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 the qdisc is like the group chat admin, and the classes are the ones actually doing the work. periodt. ๐
โจ CLASSES โจ
ok bestie, this is the part where it gets real. Classes have a whole lil host of parameters you gotta configure so they actually do their job. Let's go one by one, no skipping, we don't do that here ๐
parent major:minorโ this is where the class sits in the hierarchy, its lil spot in the family tree ๐ณ. If it's attached directly to a qdisc and not to another class, you can just leaveminorout, easy. This one is mandatory, no negotiating.classid major:minorโ same energy as qdiscs, classes can have names too ๐. Themajornumber must match themajornumber of the qdisc it belongs to, that's the rule. It's optionalโฆ but bestie, if this class is gonna have children, you need it. Periodt.weight weightโ okay so when we're dequeuing to the interface, classes get tried for traffic in a round-robin kinda way. Classes with a higher configured qdisc will generally have more traffic to offer each round, so yeah, it makes sense to let them dequeue more traffic. Here's the cute part: all weights under a class get normalized, so only the ratios matter, the actual numbers are just vibes. Defaults to the configuredrate, unless the priority of this class is maximal โ in which case it gets set to1. ๐allot bytesโallotsays how many bytes a qdisc can dequeue during each round of the process. This parameter gets weighted using that renormalized class weight we just talked about, so it's all connected, iykyk.priority priorityโ in the round-robin process, the classes with the lowest priority field get tried for packets first. Also mandatory ๐ซถrate rateโ the maximum rate this class and all its children combined can send at. Mandatory, obviously, it's the whole point.bandwidth rateโ careful bestie, this is different from the bandwidth you specify when creating a CBQ disc โ ๏ธ. This one is only used to determinemaxidleandofftime, and those are only calculated when you specifymaxburstorminburst. So it's mandatory if you're specifyingmaxburstorminburst. Otherwise, leave it alone.maxburstโ this number of packets is used to calculatemaxidle, so that whenavgidleis atmaxidle, this number of average packets can burst beforeavgidledrops to0. Set it higher if you wanna be more tolerant of bursts ๐ธ. And heads up: you can't setmaxidledirectly, only through this parameter. That's just how it is.minburstโ remember how CBQ needs to throttle when things go overlimit? The ideal solution would be to throttle for exactly the calculated idle time and pass1packet. But ngl, 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 you wait is called the offtime. Higher values of minburst lead to more accurate shaping in the long term, but to bigger bursts at millisecond timescales. Tradeoffs, bestie, always tradeoffs.
minidleโ ifavgidleis below0, we're overlimits and we gotta wait untilavgidleis big enough to send one packet. But 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.
boundedโ this one signifies that this class will not borrow bandwidth from its siblings. Very "I don't need your help, I'm fine" energy ๐isolatedโ this means the class will not borrow bandwidth to its siblings. (That's exactly what the page says, so that's exactly what I'm telling you ๐ซถ)split major:minoranddefmap bitmap[/bitmap]โ okay 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, given 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:
'tc class add ... classid 10:1 cbq .. split 10:0 defmap c0'
this 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. See how it all fits together? Obsessed with a well-formed config honestly โจ
estimator interval timeconstantโ CBQ can measure how much bandwidth each class is using, andtcfilters can use that to classify packets with. To figure out the bandwidth it uses a very simple estimator that measures once everyintervalmicroseconds how much traffic has passed. And this again is a EWMA, for which thetimeconstantcan be specified, also in microseconds. The time constant corresponds to the sluggishness of the measurement, or, flip it around, to the sensitivity of the average to short bursts. Higher values mean less sensitivity. ๐ฆ
๐ SOURCES ๐
the receipts, bestie, we cite our sources here:
- 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 Guarantee 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 ๐ you made it all the way through, main character energy fr fr. this page came from iproute2 and it's dated 8 December 2001 โ yes it's been slaying since 2001, iconic behavior honestly ๐ go shape some traffic, you got this ๐ โจ
๐ฆ 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