Linux Kernel's Hidden TCP Throttling Bug Traced to Cgroup Memory Pressure
Uncovering Hidden TCP Throttling in the Linux Kernel

A CDN customer reported random download slowdowns that self-healed and only hit nginx on cache misses. After ruling out network, config, and disk issues, engineers used bpftrace to find rcv_ssthresh stuck at four times the advertised MSS. The culprit: tcp_under_memory_pressure() also checks the socket's cgroup, and a reclaim shortfall over a tiny 2MB window sets a per-cgroup flag that throttles every socket for a second—even with hundreds of gigabytes free. They contributed a counter in Linux 6.19.
What's NOT in the formula is how much free memory the machine has. It's purely a measure of reclaim efficiency over a tiny two-megabyte window.
- freedomben
More of a meta comment, but I'm always grateful for these sort of network-related debugging blog posts. As a software eng who has a good grasp of networking at a conceptual layer, but has struggled to translate concept into concrete implementation in linux, I get a lot of value from these. Thank you to the author(s) for putting in the effort to write this up.
- basilikum
> Memory reclaim reports how many pages it scanned and how many it managed to free per cgroup. Once roughly two megabytes' worth of pages have been scanned, the kernel turns that into a ratio. If it freed less than about 40% of what it walked, that counts as memory pressure, and every socket in the cgroup gets throttled for that one second. What's NOT in the formula is how much free memory the machine has.
Maybe I'm missing something, but can someone explain why memory pressure is detected like this in the first place? The article goes on to say that there was a TODO comment in the source to scale the scanning window proportional to the memory size, but why is memory pressure even measured like this without considering the free memory at all? Am I missing something or does that indeed make no sense?
- InsidiousWombat
cgroup memory controller in general is full of traps. For example, it does also count filesystem caches into memory usage, which means just using it as limit against application leaks can get into bad behavior, especially if app relies on that cached file access, any leak will just cause that performance to get worse and worse far before it leaks to the level causing app to be killed.
IIRC tmpfs is also charged to the cgroup that uses it.
It makes sense from memory system perspective (else there would be a ways for cgroup to leak memory usage) but it also leads to many unintuitive debug sessions, and under-utilization of free RAM for caching
- rid
I think the workaround for this at the moment is the boot parameter:
cgroup.memory=nosocket
If you're not bothered about socket memory counting towards the cgroup's limit (it's usually negligible).
- montjoy
Lots of little gems in this article. e.g.
> We launch nginx as a systemd service, and systemd places each service into its own cgroup and sets default controllers
Thank you for sharing.