Linux cgroup memory pressure silently throttles TCP sockets in nginx
CDN77 engineers traced intermittent download slowdowns to a hidden kernel mechanism where cgroup reclaim inefficiency triggers global socket throttling, even on servers with abundant free RAM.
Engineers at CDN77 spent weeks debugging intermittent, self-healing download slowdowns on their edge servers that affected only nginx processes during cache misses. The investigation revealed that the Linux kernel’s cgroup memory controller was silently throttling TCP socket buffers based on reclaim efficiency rather than actual memory exhaustion.
What happened
The issue began with customer complaints about slow download speeds from specific edge nodes. Unlike typical network failures, there were no error codes, and the problem appeared randomly, lasting for hours before resolving itself without intervention. In one notable instance, throughput collapsed just before 3 a.m., remained flat for five hours, and recovered around 8 a.m. Initial troubleshooting ruled out external factors like ISP peering issues, transit problems, or misconfigured kernel TCP parameters such as tcp_rmem and tcp_wmem.
Internal monitoring showed lower traffic on the network interface, but CPU, memory, and disk I/O metrics appeared normal. The problem persisted across multiple regions, eliminating location-specific network paths as the cause. Crucially, the slowdown only occurred when nginx had to fetch content from upstream layers due to cache misses. Direct downloads via curl on the same server worked fine, indicating the bottleneck was specific to how nginx handled these dynamic connections. Rebooting the server provided temporary relief, but the issue inevitably returned.
How it works
To isolate the culprit, the team used bpftrace to hook into the kernel’s tcp_rcv_established function, inspecting fields within the struct tcp_sock structure. They discovered that the rcv_ssthresh value, which controls the receive window clamp, had dropped to exactly four times the advertised maximum segment size. This specific value is set by the tcp_adjust_rcv_ssthresh() function, which is only called when tcp_under_memory_pressure() returns true.
Although standard SNMP counters reported zero global TCP memory pressure, the kernel’s TCP pressure check includes an additional condition: it verifies if the socket’s cgroup is under memory pressure. When the cgroup memory controller is active, which is default for systemd services, this check becomes relevant. The kernel tracks memory reclaim efficiency over a small, hardcoded window of two megabytes. If the kernel scans pages but fails to free at least 40% of them within this window, it flags the cgroup as under pressure.
This flag triggers vmpressure(), which sets a timer that throttles every socket in that cgroup for at least one second. Because this mechanism relies on reclaim efficiency over a tiny window rather than total available memory, a server with hundreds of gigabytes of free RAM can still trigger throttling if its page reclaim process is inefficient. Since nginx runs in its own non-root cgroup, it was susceptible to this behavior, while other processes or direct system calls were not.
Key details
- The throttling only affected nginx processes running in non-root cgroups, leaving other system functions unaffected.
- Standard memory pressure counters like
TcpExtTCPMemoryPressuresremained at zero, hiding the issue from traditional monitoring tools. - The trigger was a reclaim efficiency ratio over a hardcoded 2MB window, not the total amount of free memory on the server.
- Moving nginx to the root cgroup resolved the issue because
vmpressure()returns immediately for root cgroups. - A new counter,
sock_throttled, was added to thememory.eventsfile in Linux 6.19 to help detect this specific type of throttling.
Why it matters
For infrastructure engineers, this case highlights a significant blind spot in standard Linux performance monitoring. Traditional metrics often focus on global resource usage, such as total RAM or CPU load, missing nuanced behaviors introduced by cgroup controllers. Systems that appear healthy from a high-level perspective can suffer from severe performance degradation due to internal kernel mechanisms designed for isolation rather than throughput optimization.
This behavior is particularly relevant for applications like web servers, databases, or caches that run in isolated cgroups and handle large numbers of concurrent connections. Understanding that memory pressure can be defined by reclaim efficiency rather than absolute scarcity helps teams avoid misdiagnosing network issues as application bugs or hardware failures. It also underscores the importance of keeping kernels updated, as newer versions provide better visibility into these obscure subsystems.
What you can do
- Check if your critical services are running in non-root cgroups, which is the default for systemd services.
- Monitor the
memory.eventsfile in your cgroup filesystem for thesock_throttledcounter if you are running Linux 6.19 or later. - Be aware that high page scan rates with low reclamation can trigger throttling even when ample free memory exists.
- Consider moving performance-sensitive network services to the root cgroup if isolation limits are not strictly required, though this reduces resource containment.
- Review kernel versions and consider upgrading to access new diagnostic counters that expose hidden pressure states.
- Use eBPF tools like
bpftraceto inspect kernel TCP structures directly when standard metrics fail to explain throughput anomalies.



