tc-sfq
Fairly queue network traffic for shaping
SYNOPSIS
tc qdisc [ add | change | replace ] dev DEV root | parent CLASSID sfq [ limit PACKETS ] [ flows NUMBER ] [ depth PACKETS ] [ quantum BYTES ] [ perturb_period SECONDS ] [ divisor NUMBER ]
tc qdisc show dev DEV
PARAMETERS
limit
Maximum number of packets the qdisc can hold in total. Default is 128.
flows
Maximum number of flows to hash to. This parameter is deprecated; use 'divisor' instead. Default is 128.
depth
Maximum number of packets a single sub-queue (hash bucket) can hold. Default is 128.
quantum
Number of bytes a flow is allowed to send before SFQ moves to the next flow. Default is 1514 bytes (one Ethernet MTU). This value should be at least the interface's MTU.
perturb_period (or perturb)
Interval in seconds after which the hashing algorithm is re-seeded to redistribute flows and mitigate hash collisions. A value of 0 disables this feature. Default is 10 seconds.
divisor
The number of hash buckets available for flows. A larger number (preferably an integer power of two) reduces the chance of hash collisions. Default is 1024; maximum is 65536.
DESCRIPTION
tc-sfq implements the Stochastic Fairness Queueing (SFQ) queue discipline. It is designed to ensure that each active network flow receives a fair share of the available bandwidth, preventing any single flow from monopolizing the outgoing link. SFQ achieves this by classifying packets into a large number of independent sub-queues based on a hash of their header fields (e.g., source/destination IP addresses, port numbers, protocol). When the device is ready to send a packet, it round-robins through these sub-queues, sending one packet from each. This approach mimics true fair queueing without the high computational overhead, hence "stochastic." To mitigate the problem of hash collisions (where different flows map to the same sub-queue), SFQ periodically perturbs its hashing algorithm, causing flows to be re-assigned to different sub-queues. While SFQ excels at fairness, it does not provide any prioritization capabilities. It is a simple yet effective qdisc for general-purpose traffic shaping where overall fairness is desired over specific QoS guarantees.
CAVEATS
SFQ provides excellent fairness but does not support prioritization of specific types of traffic. All flows are treated equally. Hash collisions, although mitigated by the perturb_period mechanism, can still temporarily cause unfairness if a large number of flows collide into the same bucket. SFQ is also not suitable for single-flow scenarios where the primary goal is strict rate limiting or complex QoS, as it is designed for distributing bandwidth among multiple competing flows.
FLOW IDENTIFICATION
SFQ identifies "flows" by hashing various fields from the packet header, typically including source and destination IP addresses, TCP/UDP port numbers, and the protocol type. This means that, for example, a single TCP connection would be considered one flow.
SUB-QUEUES
SFQ maintains a set of internal sub-queues (also known as hash buckets). When a packet arrives, its flow is determined, and the packet is enqueued into the corresponding sub-queue. The scheduler then cycles through these sub-queues in a round-robin fashion, sending one packet from each active sub-queue in turn. This mechanism ensures that no single flow can monopolize the queue.
HISTORY
The Stochastic Fairness Queueing (SFQ) algorithm was proposed by Sally Floyd and Van Jacobson in 1993, building upon earlier fair queueing concepts. It was designed to provide a practical and efficient approximation of true fair queueing, which can be computationally intensive. SFQ was one of the early fair queueing disciplines integrated into the Linux kernel's traffic control framework, providing a robust solution for ensuring network fairness in environments where multiple flows compete for limited bandwidth without requiring complex configuration.
SEE ALSO
tc(8): Linux traffic control utility., tc-qdisc(8): General information about traffic control queueing disciplines., tc-fq_codel(8): Fair Queueing Controlled Delay. A more modern fair queueing algorithm., tc-htb(8): Hierarchical Token Bucket. For hierarchical bandwidth allocation and prioritization., tc-prio(8): Priority queueing.