← Mon, Nov 30 digest

Uncovering Hidden TCP Throttling in the Linux Kernel

read article ↗ hn thread ↗

CDN77 engineers discovered that the Linux cgroup memory controller silently throttles TCP throughput on Nginx servers due to a flawed 2MB reclaim pressure window, independent of available RAM.

read it A must-read post-mortem for systems engineers detailing how a hidden cgroup memory controller bug silently throttles Linux TCP connections.

summary

CDN77 engineers investigated intermittent, self-healing TCP download speed drops on Nginx edge servers that occurred only on cache misses. Using bpftrace, they traced the throughput collapse to a tiny receive congestion window caused by `tcp_under_memory_pressure()`. They discovered this was triggered by the cgroup memory controller's `vmpressure()` function, which aggressively throttles sockets based solely on a hardcoded 2MB reclaim efficiency window rather than actual system memory availability. The team bypassed the bug by moving Nginx to the root cgroup and contributed an upstream telemetry patch in Linux 6.19.

key points

  1. Systemd places services into cgroups by default, activating the cgroup memory controller even when no strict memory limits are configured.
  2. The `vmpressure()` function flags socket pressure based on a tiny, hardcoded 2MB reclaim window—failing if less than 40% of scanned pages are freed—completely ignoring total free system RAM.
  3. Moving affected Nginx processes to the root cgroup bypasses `vmpressure()`, and an upstream patch introduced a `sock_throttled` counter in Linux 6.19 to make this visible.

who should read it

Systems engineers, SREs, and Linux kernel developers managing high-performance networking or container resource limits.

discussion warm

consensus

Commenters expressed deep gratitude for high-quality debugging write-ups and voiced shock that a cgroup memory controller bug could cause severe, silent performance degradation on high-RAM servers.

pushback

Some noted that cgroup memory controllers are full of unintuitive traps, such as charging filesystem caches to memory usage and causing performance issues before any OOM kills occur.

best comment by rstuart4133 ↗

Bravo to CDN77 for tracking this down.

But limiting TCP socket memory use on a cgroup that could have TB of memory available to it and is not under memory pressure - WTF? The global kernel algorithm for socket memory still applies, so why have this extra socket limit on a cgroup when the user hasn't constrained the cgroup's memory?

We regularly see posts from kernel devs sweating blood to squeeze an extra couple of % of performance under some rare circumstances, yet here we have a process being throttled by more than 80% for no good reason. This has got to be one of the most egregious …

Highlights the absurdity that a socket memory limit can severely throttle processes on a machine with terabytes of free memory.

Generated by an LLM from the article and thread. Check the sources before relying on it.