How to Configure CAKE Queue Management in Linux Using tc to Eliminate Bufferbloat

In high-throughput Linux network gateways, edge routers, and workstation environments, network latency often spikes dramatically under heavy upstream or downstream data transfers. This phenomenon—known as bufferbloat—occurs when intermediate network buffers hold excessive packets before transmission, delaying real-time interactive traffic such as DNS queries, SSH sessions, VoIP calls, and video conferencing.

To eliminate bufferbloat, the Linux kernel provides the CAKE (Common Applications Kept Enhanced) queuing discipline (sch_cake). CAKE integrates advanced Active Queue Management (AQM), deficit-round-robin fair queuing, automatic DiffServ classification, and bandwidth shaping into an easily configurable framework using the tc (Traffic Control) utility.

Understanding CAKE Architecture and Advantages

Traditional queue disciplines like Token Bucket Filter (TBF) require complex chaining with CoDel or FQ-CoDel to achieve fair sharing and latency bounds. CAKE simplifies this by consolidating essential traffic control features:

  • Integrated Shaper: Accurately throttles interface throughput to just below the bottleneck link speed, preventing physical modems or ISP routers from buffering packets.
  • Flow and Host Isolation: Distributes bandwidth evenly across individual IP addresses (host fairness) or individual socket streams (flow fairness).
  • DiffServ Priority Handling: Understands standard 8-class and 4-class DiffServ precedence (DSCP) without requiring custom filter tables.
  • RTT Adaptation: Dynamically tunes drop thresholds for regional, metro, or intercontinental Round Trip Times (RTT).

Verifying Kernel Support for sch_cake

CAKE is included natively in mainline Linux kernels (Linux 4.19 and newer). Check if the sch_cake kernel module is available on your system:

modinfo sch_cake

If the module is present, load it into the active kernel:

sudo modprobe sch_cake

Confirm that the traffic control utility tc is installed and supports CAKE options:

tc qdisc help cake

Inspecting Existing Queuing Disciplines

Before attaching CAKE to a network interface, inspect the current queuing configuration on your primary uplink adapter (for example, eth0 or enp3s0):

tc -s qdisc show dev eth0

Standard Linux distributions often default to fq_codel or pfifo_fast. While functional, default schedulers do not throttle throughput to match upstream bottleneck capacities.

Configuring CAKE on an Egress Interface

To configure CAKE, replace the root queuing discipline on the target network interface. Specify your upstream bandwidth limit (for example, 50 megabits per second) to force queue management into your local Linux kernel:

sudo tc qdisc replace dev eth0 root cake bandwidth 50mbit

To enhance fairness across multiple local LAN devices sharing an egress connection, enable dual-srchost fairness. This ensures that no single device can monopolise the upload bandwidth:

sudo tc qdisc replace dev eth0 root cake bandwidth 50mbit dual-srchost

Optimising Framing Overhead and RTT Targets

When running Linux behind DSL, fibre, or cable broadband modems, packet encapsulation adds framing overhead. CAKE can account for this overhead to prevent hidden buffering at the modem layer:

Connection Type Recommended Overhead Parameter Example tc Command
Ethernet / Fibre ONT overhead 18 sudo tc qdisc replace dev eth0 root cake bandwidth 100mbit overhead 18
VDSL2 (PTM) overhead 26 ptm sudo tc qdisc replace dev eth0 root cake bandwidth 40mbit overhead 26 ptm
ADSL2+ (ATM) overhead 32 atm sudo tc qdisc replace dev eth0 root cake bandwidth 15mbit overhead 32 atm
DOCSIS Cable docsis sudo tc qdisc replace dev eth0 root cake bandwidth 35mbit docsis

For high-latency satellite connections or ultra-low-latency local links, tune the target RTT parameter:

# For intercontinental or satellite uplinks
sudo tc qdisc replace dev eth0 root cake bandwidth 20mbit rtt 300ms

# For low-latency metro fibre uplinks
sudo tc qdisc replace dev eth0 root cake bandwidth 500mbit rtt 20ms

Monitoring Live CAKE Performance and Buffer Statistics

Once CAKE is running under live network load, inspect detailed per-tin latency, dropped packet counts, and capacity metrics using the -s (statistics) flag:

tc -s qdisc show dev eth0

The output presents a comprehensive breakdown across DiffServ priority tins:

qdisc cake 8001: root refcnt 2 bandwidth 50Mbit diffserv4 dual-srchost
 Capacity estimate: 50Mbit
                 Bulk  Best Effort        Video        Voice
  thresh        3125K       50Mbit       25Mbit     12500Kbit
  target       7.50ms       5.00ms       5.00ms       5.00ms
  interval    102.5ms      100.0ms      100.0ms      100.0ms
  pk_delay        0us        420us        110us         45us
  av_delay        0us        215us         85us         20us
  sp_delay        0us         12us          5us          2us
  backlog          0b           0b           0b           0b
  drops             0            4            0            0

Reviewing pk_delay (peak delay) and av_delay (average delay) confirms whether real-time traffic is forwarded with minimal latency while background bulk transfers are throttled.

Removing CAKE Queuing Disciplines

If you need to remove CAKE and revert the network interface to the system default queuing discipline, delete the root qdisc:

sudo tc qdisc del dev eth0 root

By implementing CAKE queue management, network administrators can maintain consistent single-digit millisecond latency for interactive services even during heavy saturating downloads and uploads.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.