TC(8)
๐ sfq: Stochastic Fairness Queueing ๐
manual for Linux, filed under tc(8) ๐
โจ NAME โจ
sfq is Stochastic Fairness Queueing ๐. It's a classless queueing discipline you can use with the tc(8) command. Iconic, right?
๐ง SYNOPSIS ๐ง
tc qdisc ... [ divisor hashtablesize ] [ limit packets ] [ perturb
seconds ] [ quantum bytes ] [ flows number ] [ depth number ] [ headdrop
] [ redflowlimit bytes ] [ min bytes ] [ max bytes ] [ avpkt bytes ] [
burst packets ] [ probability P ] [ ecn ] [ harddrop ]
๐ธ DESCRIPTION ๐ธ
okay so SFQ doesn't shape your traffic ๐. It only decides the order packets get sent in, based on flows. The whole goal is fairness: every flow gets its turn to send data, so no single flow can hog the link and drown out everybody else. Main character energy for every connection ๐.
This may actually help a bit against a Denial of Service attempt. Not a full fix, but it's giving protection ๐ก๏ธ.
SFQ is work-conserving, which means it always sends a packet if it has one ready to go. No waiting around, no cap ๐ฅ.
๐ฆ ALGORITHM ๐ฆ
When a packet gets enqueued, it's dropped into a hash bucket based on its hash value. That hash value comes from either an external flow classifier (you set those up with tc filter) or a default internal classifier, if you haven't configured an external one.
When SFQ uses the internal classifier, it looks at:
(i)Source address(ii)Destination address(iii)Source and Destination port
...as long as those are available. SFQ knows about IPv4 and IPv6, plus UDP, TCP and ESP. Packets with other protocols get hashed based on the 32bits representation of their destination and source. A flow mostly means one TCP/IP connection ๐งต.
Each bucket is supposed to hold one unique flow ๐. Multiple flows can land in the same bucket, though, so SFQ's internal hash can be perturbed at set intervals. That way the unfairness only lasts a little while. Perturbation can cause some accidental packet reordering, though ๐ญ. After linux-3.3 there's no reordering problem anymore, but packets can get dropped if rehashing runs into a limit (number of flows or packets per flow).
When dequeuing, every hash bucket that has data gets checked in a round robin fashion ๐.
Before linux-3.3, the compile time maximum length of SFQ is 128 packets. Those can be spread over at most 128 buckets, out of 1024 available. If it overflows, tail-drop happens on the fullest bucket, which keeps things fair โ๏ธ.
After linux-3.3, the maximum length of SFQ is 65535 packets, and the divisor limit is 65536. On overflow, tail-drop happens on the fullest bucket, unless headdrop was requested โจ.
๐ PARAMETERS ๐
divisorโ Lets you pick a different hash table size, available from kernel 2.6.39 onwards. The divisor must be a power of two and can't be bigger than 65536. Default: 1024 ๐.limitโ The upper limit of the SFQ. Use it to shrink the default length of 127 packets. After linux-3.3, you can raise it too ๐.depthโ Limit of packets per flow (after linux-3.3). It defaults to 127, and you can lower it ๐ง.perturbโ The interval in seconds for queue algorithm perturbation. It defaults to 0, which means no perturbation at all ๐ โโ๏ธ. Don't set it too low, because each perturbation can cause some packet reordering or losses ๐ฌ. Advised value: 60. This value has no effect when external flow classification is used. It's better to increase the divisor value to lower the risk of hash collisions ๐ก.quantumโ The amount of bytes a flow is allowed to dequeue during one round of the round robin process. It defaults to the MTU of the interface, which is also the advised value and the minimum value ๐ฆ.flowsโ After linux-3.3, you can change the default limit of flows. The default value is 127 ๐.headdropโ By default SFQ tail-drops packets from a flow. You can ask for a headdrop instead, which is known to give better feedback for TCP flows ๐ซถ.redflowlimitโ Configures the optional RED module on top of each SFQ flow. RED works by marking or dropping packets in a probabilistic way ๐ฒ. (Checkman tc-redfor the deets about RED ๐.)redflowlimitsets the hard limit on the real (not average) queue size per SFQ flow, in bytes ๐งฑ.minโ The average queue size at which marking becomes a possibility. Defaults tomax /3๐ค๏ธ.maxโ At this average queue size, the marking probability is maximal ๐. Defaults toredflowlimit /4.probabilityโ The maximum probability for marking, given as a floating point number from 0.0 to 1.0. Default value is 0.02 ๐ฏ.avpktโ Specified in bytes. Used together withburstto determine the time constant for average queue size calculations โฑ๏ธ. Default value is 1000.burstโ Decides how fast the average queue size gets influenced by the real queue size ๐โโ๏ธ. Default value is(2 * min + max) / (3 * avpkt).ecnโ RED can either mark or drop ๐ท๏ธ. Explicit Congestion Notification lets RED tell remote hosts that their rate is more than the bandwidth available. Non-ECN capable hosts can only be told this by dropping a packet ๐. If you specify this parameter, packets from hosts that honor ECN will only get marked and not dropped, unless the queue size hitsdepthpackets ๐ค.harddropโ If the average flow queue size is abovemaxbytes, this parameter forces a drop instead of ECN marking ๐.
๐ EXAMPLE & USAGE ๐
To attach to device ppp0:
# tc qdisc add dev ppp0 root sfq
Please note that SFQ, like all non-shaping (work-conserving) qdiscs, is only useful if it owns the queue โผ๏ธ. That's the case when the link speed equals the bandwidth that's actually available. This holds for regular phone modems, ISDN connections and direct non-switched ethernet links.
Most of the time, cable modems and DSL devices don't fall into this category ๐ฉ. Same goes for when you're connected to a switch and trying to send data to a congested segment that's also connected to the switch.
In that case, the effective queue doesn't live inside Linux, so it isn't available for scheduling ๐ซ .
To make sure it owns the queue, embed SFQ in a classful qdisc ๐งฉ.
You can use external classifiers with SFQ, for example to hash traffic based only on source/destination IP addresses:
# tc filter add ... flow hash keys src,dst perturb 30 divisor 1024
Note that the given divisor should match the one used by SFQ. If you changed the SFQ default of 1024, use the same value for the flow hash filter too โ ๏ธ.
Example of SFQ with optional RED mode:
# tc qdisc add dev eth0 parent 1:1 handle 10: sfq limit 3000 flows 512
divisor 16384
redflowlimit 100000 min 8000 max 60000 probability 0.20 ecn headdrop
๐ SOURCE ๐
- Paul E. McKenney "Stochastic Fairness Queuing", IEEE INFOCOMM'90 Proceedings, San Francisco, 1990.
- Paul E. McKenney "Stochastic Fairness Queuing", "Interworking: Research and Experience", v.2, 1991, p.113-131.
- See also: M. Shreedhar and George Varghese "Efficient Fair Queuing using Deficit Round Robin", Proc. SIGCOMM 95.
๐ซง SEE ALSO ๐ซง
๐ฉโ๐ป AUTHORS ๐ฉโ๐ป
Alexey N. Kuznetsov, <kuznet@ms2.inr.ac.ru>, Eric Dumazet <eric.dumazet@gmail.com>.
This manpage is maintained by bert hubert <ahu@ds9a.nl> ๐ท.
bestie, that's the whole sfq tea ๐๐ iproute2 ยท 24 January 2012 ยท TC(8) ๐ฆโจ
๐ฆ 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