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 ๐ŸŽฒ. (Check man tc-red for the deets about RED ๐Ÿ“–.) redflowlimit sets 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 to max /3 ๐ŸŒค๏ธ.
  • max โ€” At this average queue size, the marking probability is maximal ๐Ÿ”. Defaults to redflowlimit /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 with burst to 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 hits depth packets ๐Ÿค.
  • harddrop โ€” If the average flow queue size is above max bytes, 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 ๐Ÿซง

tc(8), tc-red(8)

๐Ÿ‘ฉโ€๐Ÿ’ป 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