Linux TCP throttling explained: Why nginx slowed with free RAM

Linux TCP throttling explained: Why nginx slowed with free RAM Linux TCP throttling explained: Why nginx slowed with free RAM

A server can have idle CPUs, substantial free memory, and a healthy network interface yet still deliver files through nginx at a fraction of the expected speed. CDN77 encountered exactly that contradiction: intermittent slow downloads that were eventually connected to Linux TCP throttling, not conventional host-wide memory exhaustion. Kernel tracing showed that TCP was reacting to memory pressure associated with service cgroups, restricting receive-window behavior even while global memory indicators looked normal.

The investigation is useful because it challenges a common troubleshooting assumption: if free reports plenty of available RAM and global TCP pressure counters remain at zero, memory cannot be limiting network performance. Linux kernel networking makes that conclusion unsafe. A socket can be considered under memory pressure because of its memory cgroup even when the machine itself is not under global pressure.

What CDN77 observed

CDN77’s reported problem involved inconsistent nginx download performance. Connections were established normally, the hosts had spare resources, and the slowdown did not resemble a simple bandwidth cap. Some downloads performed as expected, while others became much slower.

The decisive clue was the advertised TCP receive window. TCP throughput is constrained by how much unacknowledged data may be in flight. If the receiving side advertises a small window, the sender must stop and wait for acknowledgements more frequently. That effect becomes especially visible on paths with meaningful round-trip time, where even a fast link can sit underused.

This was not nginx deliberately rate-limiting clients. Nor was it ordinary packet shaping. The behavior emerged from TCP’s memory-management logic and the cgroup context attached to sockets used by the service.

How the TCP receive window affects download speed

A TCP receiver stores arriving data until the application consumes it. The advertised TCP receive window tells the peer how much more data the receiver can accept. Linux normally uses receive-buffer autotuning to expand buffers and windows as traffic conditions justify it, within limits such as net.ipv4.tcp_rmem and net.core.rmem_max.

On a high-bandwidth or higher-latency connection, a larger window may be necessary to keep the path full. As a simplified example, a small effective window can cap throughput because the sender may transmit only that amount during each round-trip interval. Window scaling raises the protocol’s potential ceiling, but it does not force the kernel to advertise a large usable window.

Linux also has to prevent sockets from consuming unbounded memory. Under pressure, the kernel becomes conservative about receive queues and autotuning. That is normally protective behavior. CDN77’s case became surprising because the pressure decision came from a cgroup-specific path rather than a host-wide shortage.

The critical kernel functions

tcp_under_memory_pressure()

At the center of the investigation was tcp_under_memory_pressure(). Conceptually, this helper answers whether TCP should behave as though memory is constrained. The result can be true through either of two paths:

  • A global TCP memory-pressure condition is active.
  • The socket’s memory cgroup is considered to be under socket-memory pressure.

That second path explains the misleading telemetry. Global counters reflect global TCP pressure; they do not necessarily reveal that a particular socket’s cgroup triggered the decision. Therefore, a zero global pressure count does not prove every socket received an unpressured result from tcp_under_memory_pressure().

tcp_adjust_rcv_ssthresh() and receive-window restraint

Linux tracks receive-side thresholds that influence how the advertised window and receive queue develop. The relevant implementation details vary across kernel versions, so administrators should inspect the source corresponding to the running kernel rather than relying on a random online snapshot.

In the path analyzed by CDN77, memory-pressure checks interacted with tcp_adjust_rcv_ssthresh() and related receive-buffer logic. Once the socket was treated as pressured, TCP became more conservative about receive-side memory. The resulting receive-window adjustments limited how much data the sender could keep in flight, producing nginx slow downloads without nginx itself imposing a rate limit.

It is more accurate to describe this as pressure-driven receive-window throttling than as a fixed bandwidth limiter. The kernel was protecting memory according to its internal state; reduced throughput was a consequence.

Why free RAM did not rule out pressure

Linux cgroups divide resource accounting and control into hierarchies. Under systemd, services normally run in dedicated units and therefore in service cgroups. A process does not need to be inside a container for cgroup state to matter.

A cgroup can encounter reclaim or memory-pressure conditions independently of the host’s overall free-memory total. Explicit settings such as MemoryHigh and MemoryMax, inherited limits, accounting state, and pressure propagated through the hierarchy can all matter. Socket memory is also accounted in ways that are not captured by looking only at an application’s resident set size.

This produces three different questions:

  • Does the machine have available memory?
  • Is global TCP memory pressure active?
  • Does the kernel consider this socket’s memory cgroup under pressure?

Only the third question directly explains the path reported by CDN77. The answers to the first two can be reassuring while the third is still yes.

The distinction also explains why tools such as free -h, vmstat, and global network counters were insufficient. They provide valuable host-level evidence, but they do not expose every per-cgroup decision made for an individual socket.

Why the global TCP pressure counters stayed at zero

Linux exposes TCP memory data through interfaces such as /proc/net/sockstat and protocol counters available through nstat. These are sensible places to begin. In this incident, however, the absence of global TCP pressure events became a false negative.

The reason follows directly from the logic above: the global pressure flag and the memory-cgroup socket-pressure check are separate inputs. If the cgroup check returns true, TCP can enter its conservative path without setting the global condition administrators expect to see.

This is an observability gap, not evidence that the counters are broken. A counter can truthfully say that global TCP pressure never occurred while failing to answer whether a service cgroup caused socket-level throttling.

How bpftrace exposed the decision

CDN77 used kernel tracing to move beyond symptoms and observe the relevant call path. bpftrace can attach probes to kernel functions, collect return values, identify processes and cgroups, and aggregate stack traces. That makes it particularly useful when ordinary metrics report healthy resources but kernel behavior says otherwise.

Before writing a probe, verify that the target exists and is traceable on the running kernel:

bpftrace -l '*tcp_under_memory_pressure*'
bpftrace -l '*tcp_adjust_rcv_ssthresh*'

Functions may be inlined, renamed, unavailable to kprobes, or represented differently depending on configuration and BTF support. If a helper cannot be attached directly, trace a visible caller and correlate it with receive-window changes. The official bpftrace documentation explains available probe types and kernel requirements.

Tracing production kernels requires care. Start with aggregation rather than printing every event, filter by nginx PID, cgroup, or port, and estimate probe frequency before deployment. Capturing every packet-path invocation can create avoidable overhead.

A practical server performance troubleshooting workflow

  1. Confirm that TCP flow control is the bottleneck. Run ss -tin during a slow transfer and inspect receive-space, window, congestion, retransmission, and round-trip information. Use a packet capture to verify whether the advertised receive window stays unexpectedly small.
  2. Separate network loss from receiver limitation. Check interface drops, retransmissions, MTU problems, queueing, routing, and congestion control. A small window and packet loss can coexist, so avoid treating either observation as conclusive by itself.
  3. Review host-wide socket state. Examine /proc/net/sockstat, /proc/net/netstat, and nstat -az. Record the results, but remember that zero global pressure does not exclude cgroup pressure.
  4. Locate nginx’s systemd cgroup. Use systemctl show nginx -p ControlGroup -p MemoryCurrent -p MemoryHigh -p MemoryMax. Then inspect the corresponding directory under /sys/fs/cgroup.
  5. Inspect cgroup memory evidence. Review memory.current, memory.high, memory.max, memory.events, memory.stat, and memory.pressure. Check parent cgroups too, because limits and pressure can be hierarchical. The kernel’s cgroup v2 documentation describes these files and their semantics.
  6. Compare healthy and slow connections. Correlate transfer rate, advertised window, cgroup state, socket ownership, destination RTT, and timestamps. Intermittent faults are much easier to understand through side-by-side evidence.
  7. Trace only after narrowing the hypothesis. Probe the pressure decision or a traceable caller with bpftrace. Record the process, cgroup ID, return value, and stack where possible.
  8. Test changes one at a time. Adjust confirmed cgroup limits or service placement in a controlled environment. Do not begin by increasing every TCP buffer sysctl; larger ceilings cannot override every pressure-driven decision.

The reported root-cgroup workaround

CDN77 reported that placing the affected service in the root cgroup avoided the problematic cgroup pressure path and restored performance in its environment. That result was also a strong diagnostic signal: network hardware and nginx configuration had not changed, but the socket’s cgroup context had.

This should not be treated as a universal production fix. Moving a service to the root cgroup can weaken resource isolation, complicate systemd management, and allow one workload to affect others. It may also mask the configuration or kernel behavior that should be corrected.

Use the root-cgroup result as a controlled experiment where operationally safe. A durable response may involve correcting inherited memory controls, updating the kernel, applying a vendor backport, or redesigning the unit hierarchy. Test any workaround against the exact distribution kernel in use.

What Linux 6.19 changed for observability

The original technical report identifies Linux 6.19 as the version introducing the sock_throttled memory-cgroup observability counter. Its purpose is to make socket throttling attributable at the cgroup level, reducing dependence on invasive tracing when global counters remain quiet.

This version detail matters: sock_throttled is an observability improvement, not proof that every underlying cause of pressure-driven throttling was universally eliminated. Administrators should check memory.stat for the field and consult their distribution’s kernel changelog, because enterprise kernels may backport features without adopting the upstream version number.

As of December 2026, systems running older or heavily customized kernels may still lack the counter. Its absence does not establish that throttling did not happen; it may simply mean the running kernel cannot report it directly.

Do not generalize one incident into a universal Linux defect

CDN77 documented a specific interaction among its workload, kernel behavior, systemd service cgroups, and TCP receive-side logic. That does not mean every nginx slowdown with free RAM has the same cause, or that all Linux systems misclassify socket pressure.

Common alternatives remain more likely in many environments: packet loss, overloaded storage, TLS CPU saturation, worker limits, connection caps, proxy buffering, upstream latency, virtual NIC contention, or intentional nginx rate controls. The value of the report is not a shortcut to a diagnosis. It is a warning that cgroup-aware socket pressure belongs on the checklist when receive windows collapse and conventional memory metrics look healthy.

Frequently asked questions

Can nginx cause Linux TCP throttling?

nginx can create the traffic pattern in which the behavior becomes visible, but the reported throttling decision occurred in Linux kernel networking. Check nginx rate directives and worker limits first, then investigate TCP and cgroup state if no application-level cap explains the result.

Why does adding RAM not necessarily fix the slowdown?

Adding RAM addresses host-wide scarcity. It may not change a memory limit, pressure state, or socket-accounting decision associated with the service’s cgroup. Inspect the cgroup hierarchy rather than relying only on total available memory.

Will increasing tcp_rmem fix a small receive window?

Not necessarily. Those settings define receive-buffer boundaries and autotuning ranges. If a pressure check prevents normal growth or makes TCP behave conservatively, raising the maximum alone may have little effect and can increase memory exposure.

Is sock_throttled available on every modern distribution?

No. Upstream Linux 6.19 introduced the counter according to CDN77’s report, but distribution availability depends on kernel version and backports. Check the actual cgroup files and vendor changelog instead of inferring support from the distribution release name.

What is the strongest evidence for this diagnosis?

The best evidence combines a persistently constrained advertised receive window, a cgroup-associated pressure or throttling signal, and kernel tracing that observes the relevant TCP pressure path. A controlled change to cgroup placement or limits can further test causality.

The operational lesson

Modern Linux performance is hierarchical. Host-wide free memory, global TCP counters, and process RSS no longer tell the entire story. When downloads slow unexpectedly, administrators need to connect packet-level behavior with socket state, systemd cgroups, memory accounting, and kernel decisions.

CDN77’s investigation showed why that broader view matters. The server was not out of RAM, nginx was not simply misconfigured, and global pressure telemetry was not lying. The missing information lived at the boundary between TCP and memory cgroups. Linux 6.19’s sock_throttled counter makes that boundary easier to observe, but disciplined correlation—and sometimes bpftrace—remains essential for reliable diagnosis.

Leave a Reply

Your email address will not be published. Required fields are marked *