How a Hidden cgroup Memory Feature Throttled TCP Downloads on CDN77 Servers

CDN77 engineers traced a mysterious download slowdown on edge servers to a memory controller behavior in the Linux kernel that throttles sockets at the cgroup level.

How a Hidden cgroup Memory Feature Throttled TCP Downloads on CDN77 Servers
Source: CDN77

A customer reported slow downloads from one of CDN77's edge servers, with no error codes and no way to reproduce the problem. The slowdowns hit only some connections, lasted for hours, and then cleared up on their own. Network paths, TCP and nginx settings, software versions, CPU, memory, and kernel logs all looked normal, and a curl test on the same server ran at full speed. Only nginx was slow, and only on requests that missed the cache.

Tracing the kernel's TCP receive window with bpftrace revealed a receive threshold stuck at a very small value. That value was only changed when the kernel believed the socket was under memory pressure, even though the global TCP memory pressure counters reported none. The engineers found that the TCP memory pressure check also looks at the socket's cgroup. Because systemd places nginx in its own cgroup with the memory controller loaded, a reclaim shortfall in that cgroup throttled every connection nginx owned for at least one second. The pressure decision used a fixed two-megabyte scanning window and ignored how much free memory the machine had.

As a temporary fix, the team moved nginx processes into the root cgroup, where this throttling does not apply. They also contributed a patch upstream. Since Linux 6.19, a sock_throttled counter in memory.events makes this behavior visible. CDN77 said a more complete fix would follow.

Source: CDN77


Posted

in

by