The TCP memory pressure counter said 0 while my window was 4 packets
Cgroup memory pressure on Linux can clamp a TCP receive window to 4 packets. I reproduced it: 205 MB/s fell to 0.3 MB/s, and sock_throttled showed why.
By Meet ModiThe counter Linux gives you for TCP memory pressure, TcpExtTCPMemoryPressures, read 0 the whole time my test connection was held to 5,792 bytes per round trip. That is four packets. CDN77 hit the same thing on nginx edge servers, where downloads crawled for five hours and then fixed themselves, while curl on the same box was fast.
The short answer to what cgroup memory pressure does to networking: on cgroup v2, when memory reclaim inside a cgroup gets inefficient, the kernel marks that cgroup as under socket pressure for one second, and every TCP socket in it (or in any cgroup below it) stops growing its windows. No memory limit is needed for this, and no global counter shows it. Since Linux 6.19 there is one place it does show: sock_throttled in memory.events. I reproduced it on a GitHub Actions runner and measured what it costs.
What CDN77 found in nginx
Daniel Sedlak's write-up is worth reading in full, mostly for the list of things it was not. Slow downloads, only from nginx, only on cache misses, across several regions, cleared by a reboot for a while. One case dropped just before 3 a.m., stayed flat for five hours, and recovered around 8 a.m. with nobody touching it. They ruled out the network path, the usual sysctls ("the well-known tcp_rmem, tcp_wmem, or tcp_mem"), the nginx config, CPU, disk and kernel logs. Syscall tracing showed nginx reading promptly, so the app was not sitting on its socket.
The break came from a bpftrace probe on tcp_rcv_established, reading fields out of the kernel's tcp_sock. During the slow periods, rcv_ssthresh, the cap on how far the receive window is allowed to grow, sat at exactly four times advmss. The only path that drags it down there is the "under memory pressure" branch of the window growth code. And the system-wide pressure counters said zero.
The missing piece was the cgroup. Their nginx runs as a systemd service, and in their words the memory controller "has an undocumented feature, which activates when the controller is only loaded". They were not using memory limits at all. The box had "hundreds of gigabytes of free RAM". The fix they shipped was to move the nginx processes into the root cgroup.
- Oct 7, 2025Sedlak posts [PATCH v5] memcg: expose socket memory pressure in a cgroup, proposing a memory.net.throttled_usec file.
- Oct 16, 2025Shakeel Butt posts the version that lands instead, a sock_throttled counter in memory.events. Sedlak is a reviewer on it.
- Feb 8, 2026Linux 6.19 is tagged with the counter in it. It was not in 6.18.
- Nov 25, 2026CDN77 publishes the debugging story. A proper fix is promised for later and is not out yet.
How cgroup memory pressure throttles TCP
I read the path on the current kernel source. In include/net/tcp.h, tcp_under_memory_pressure() checks the socket's memory cgroup first and the global tcp_mem state second. The cgroup check, in include/net/sock.h, walks from the socket's cgroup up through every parent and returns true if any of them has its socket pressure deadline in the future.
That deadline is set in mm/vmpressure.c. The relevant constants:
const unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16; /* 512 pages, 2 MB at 4 KB */
static const unsigned int vmpressure_level_med = 60; /* % of scanned NOT reclaimed */
/* For now, no users for root-level efficiency */
if (!memcg || mem_cgroup_is_root(memcg))
return;
...
if (level > VMPRESSURE_LOW && order <= PAGE_ALLOC_COSTLY_ORDER) {
/* keep the pressure state asserted for a second */
mem_cgroup_set_socket_pressure(memcg); /* jiffies + HZ */
}Put plainly: every time reclaim scans 512 pages in a cgroup, it compares how many it managed to free. Below 40% freed, the cgroup is under pressure for the next second, and every socket in it gets throttled. The formula only looks at reclaim efficiency. It has no idea whether the machine has hundreds of gigabytes free. A cache-heavy service, where reclaim keeps scanning pages that are still hot, can trip it all day.
What "throttled" means, from the commit message of the counter: "clamping the transmit window, failing to expand receive or send buffers, aggressively prune out-of-order receive queue, FIN deferred to a retransmitted packet and more." On the receive side, the visible one is rcv_ssthresh being pulled down to 4 x advmss, which caps the window you advertise to the sender.
Why nstat shows no TCP memory pressure
TcpExtTCPMemoryPressures counts entries into the global pressure state, the one driven by net.ipv4.tcp_mem. The cgroup path never touches it. So the first thing anyone checks for "is the kernel squeezing TCP memory" says no, honestly, about a different question. Before 6.19 there was no counter for the cgroup kind at all. That is the reason CDN77 needed bpftrace to see it.
I reproduced the throttling with a 200 MB cgroup
The runner was a GitHub Actions VM on kernel 7.0.0-1020-azure, with 2 vCPUs, 7.9 GB of RAM and cgroup v2. Its system.slice has the memory controller turned on for children, so every service gets a memory.events file, sock_throttled included, without anyone asking for it.
$ cat /sys/fs/cgroup/system.slice/cgroup.subtree_control
cpuset cpu io memory pids
$ cat /sys/fs/cgroup/system.slice/hosted-compute-agent.service/memory.events
low 0
high 0
max 0
oom 0
oom_kill 0
oom_group_kill 0
sock_throttled 0The setup: a small Python receiver in a transient systemd unit, and a sender in a network namespace on the other end of a veth pair, with netem adding 10 ms each way for a 20 ms round trip. On loopback the throttle fired (65,816 times in 10 seconds) but barely mattered, because four packets per few microseconds is still fast. Distance is what turns a small window into a slow download.
I did not have CDN77's situation, a huge box under global reclaim, so I forced reclaim inside the unit instead: MemoryHigh=200M, a process holding 190 MB and touching every page, and a loop reading a 1.5 GB file through the page cache. The first try still allowed swap, and nothing happened: 199.4 MB/s, sock_throttled 0, because reclaim had clean cache and swap to take from. With MemorySwapMax=0 it fell over:
# no limit, no hog
$ HOG=0 ./run2.sh rtt-base3 5203
@18s sock_throttled 0 memory.current=7299072
avg 203.7 MB/s
# MemoryHigh=200M, MemorySwapMax=0, 190 MB hog + page cache reads, same unit
$ HOG=1 HOGMB=190 ./run2.sh rtt-press2 5205 MemoryHigh=200M MemorySwapMax=0
@18s sock_throttled 908 memory.current=212021248
1.0s 0.4 MB/s
2.0s 0.3 MB/s
...
19.1s 0.3 MB/s
avg 0.3 MB/sThen the same two runs with a bpftrace probe on tcp_rcv_established, printing the receiving socket's fields every two seconds, the way CDN77 did it:
# baseline: avg 203.8 MB/s, sock_throttled 0
rcv_ssthresh=21506676 advmss=1448 rcv_wnd=21507072
# pressured: avg 0.3 MB/s, sock_throttled 917
rcv_ssthresh=5792 advmss=1448 rcv_wnd=61445,792 is 4 x 1,448. And 5,792 bytes per 20 ms round trip is 289,600 bytes a second, which is the 0.3 MB/s the receiver printed. The whole slowdown is that one clamp. Every sample I took, one every two seconds, showed the same value, because the hog kept re-triggering the one second flag before it ran out.
Last run, roughly CDN77's workaround: the same hog in its own limited unit, the receiver in a sibling unit with no limit.
sib-recv: @18s sock_throttled 0 avg 199.4 MB/s
hog-only: sock_throttled 0 high 5292
$ nstat -z | grep -i pressure
TcpExtTCPMemoryPressures 0 0.0
TcpExtTCPMemoryPressuresChrono 0 0.0Full speed. The pressure belongs to the cgroup doing the reclaiming, and the neighbour next door does not feel it. And through all of this, the global counters never moved.
How to check if cgroup memory pressure is throttling TCP
If a service is slow to send or receive and the network looks clean, these are the checks, cheapest first.
# 6.19 and later: any non-zero number here is TCP being throttled
grep -H sock_throttled /sys/fs/cgroup/system.slice/*.service/memory.events
# any kernel: look for rcv_ssthresh stuck at 4 x advmss on the slow sockets
ss -tin state established '( sport = :443 )' | grep -o 'advmss:[0-9]*\|rcv_ssthresh:[0-9]*'
# is the cgroup's reclaim struggling at all
cat /sys/fs/cgroup/system.slice/nginx.service/memory.pressureDuring my pressured run, ss printed "advmss:1448 ... rcv_ssthresh:5792 ... rcv_wnd:6144" and memory.pressure showed "some avg10=30.47". ss needs no bpftrace and no new kernel, so it is the one to remember for older fleets.
memory.events is hierarchical, so the parent slice's file adds up its children. On this runner, system.slice had collected 67,861 events by the end, almost all from my test units. Containers live in cgroups as well, so on a 6.19 or newer node the same file should exist under each container's cgroup. I did not test that on Kubernetes.
If the counter moves, the options are the boring ones: give the cgroup room so reclaim is not scanning hot pages, keep cache churn away from the process that owns the sockets, or do what CDN77 did and take the process out of a child cgroup. This is the same shape of bug as the sidecar GitHub's autoscaler did not know existed: the thing watching resources was looking at a different box than the one that was hurting. And as with the slow RAG pipeline I traced, the obvious suspect, here the network, was innocent.
The catch: a counter, not a fix
- sock_throttled counts how many times a socket asked and was told yes. It is not seconds and not sockets. My runs added about 900 in 18 seconds for one connection, and 65,816 in 10 seconds on loopback. Read it as "zero or not zero", and watch its rate.
- It needs 6.19. Plenty of production fleets are older, and there it is ss or bpftrace.
- The root cgroup workaround trades away accounting and limits for that process. Fine for a dedicated edge box, risky anywhere a runaway process should be contained.
- My reproduction needed a memory limit and no swap. I did not reproduce the CDN77 case, where there was no limit at all and plenty of free RAM. The kernel code says the same path applies, but my numbers are from the forced version.
- Shared parents are messy. With the hog and the receiver as siblings under one 250 MB slice, one run was clean (200.3 MB/s, 0 events) and the next got 490 events and a receiver that stalled for 20 seconds. memory.high also slows processes directly, so I cannot say how much of that stall was the socket clamp.
- There is no real fix upstream yet. CDN77 says they will share one. Until then the pressure signal is still reclaim efficiency over a fixed 2 MB window, the same on a 2 GB VM as on a 512 GB edge server.
What is cgroup memory pressure?
Cgroup memory pressure is the kernel's signal that reclaiming memory inside a cgroup is going badly. On cgroup v2 it is computed per cgroup from reclaim efficiency: if reclaim frees less than about 40% of what it scans over a 512 page window, the cgroup is marked under pressure for one second. TCP sockets in that cgroup and its children are throttled for that second.
Can a cgroup with no memory limit throttle TCP?
Yes, according to CDN77 and the kernel source. The check runs whenever the memory controller is enabled for the cgroup, which systemd does by default for services, with or without a limit. Global reclaim on a busy machine can still mark a service's cgroup as under pressure. I only reproduced it with a limit set, so that part rests on CDN77's account and the code.
How do I check memory pressure on Linux for a cgroup?
Read memory.pressure in the cgroup's directory under /sys/fs/cgroup for stall time, and memory.events for counters. On Linux 6.19 or newer, memory.events includes sock_throttled, which counts TCP throttling caused by cgroup memory pressure. On older kernels, use ss -ti and look for rcv_ssthresh stuck at four times advmss on slow connections.
What does sock_throttled in memory.events mean?
sock_throttled counts how many times a socket in that cgroup checked for memory pressure and was told to back off. It arrived in Linux 6.19. It is hierarchical in memory.events, so a parent slice adds up its children. It counts checks, not time, so a single connection can add hundreds per second. Treat any steady growth as a sign that TCP is being clamped.
Why does nstat show TCPMemoryPressures as 0 when TCP is slow?
TcpExtTCPMemoryPressures only counts the global TCP memory pressure state driven by net.ipv4.tcp_mem. Pressure coming from a socket's memory cgroup uses a separate check and never increments it. That is why CDN77 saw zero there while their nginx sockets were clamped, and why I saw zero during a run held to 0.3 MB/s.
Why is rcv_ssthresh 4 times the MSS?
When the kernel decides a socket is under memory pressure while growing the receive window, it lowers rcv_ssthresh to four times the advertised MSS, which caps the window the receiver offers. With a 1448 byte MSS that is 5,792 bytes. Over a 20 ms round trip that allows about 0.29 MB/s, which matches what I measured.
How do I stop cgroup memory pressure from slowing nginx?
Find out first: check sock_throttled or ss -ti. If it is the cause, give the cgroup enough memory that reclaim is not scanning hot pages, keep heavy page cache work out of the nginx cgroup, or move nginx to the root cgroup as CDN77 did. The last one drops memory accounting and limits for nginx, so weigh that before copying it.
- Uncovering Hidden TCP Throttling in the Linux Kernel, CDN77
- memcg: net: track network throttling due to memcg memory pressure (commit d929525), Linux kernel
- [PATCH v5] memcg: expose socket memory pressure in a cgroup, netdev mailing list
- Control Group v2: memory.events, Linux kernel documentation
- mm/vmpressure.c, Linux kernel
- include/net/sock.h, Linux kernel
- include/net/tcp.h, Linux kernel
More Posts
Next.js 16.5 compiles 4.2x faster. This blog got 1.35x
Next.js 16.5 on a 92-page static site with 2 cores: cold Turbopack compile went from 7.0 s to 5.2 s with 21% less memory. Not 4x. Warm builds didn't move.
I made a post-quantum SSH key. GitHub never answered it
A post-quantum SSH key is one ssh-keygen command in OpenSSH 10.6. GitHub, GitLab, Bitbucket, Codeberg and sourcehut can't use it, and GitHub just hangs.
I painted over a 4-digit code and read it back from the pixels outside the box
Can you unredact an image? From lossy WebP, yes: I got a hidden 4-digit code back from pixels 96 px outside the box. JPEG with a 16 px margin leaked nothing.