A single mutex contention in anon_pipe_write() was costing shell pipelines up to 28% throughput and 22% latency - and under memory pressure the penalty hit 48%. Breno Leitao of Meta found the culprit while profiling caching code: alloc_page() called once per page while holding pipe->mutex. That allocation can sleep doing direct reclaim and memcg charging, extending the critical section and stalling any concurrent reader on the same mutex.
The Problem: alloc_page() Inside the Mutex Every write to an anonymous pipe (think | in your shell) called alloc_page() while spinning on the mutex. If the allocator had to do reclaim, the mutex held time ballooned, serializing all readers and writers. For shell pipelines and standard stream plumbing, that meant measurable slowdowns in everyday workflows.
The Fix: Pre-allocate and Recycle Pages Leitao's patch, now merged into Linux 7.2, pre-allocates up to 8 pages before taking the lock. Leftovers are recycled into the per-pipe tmp_page[] cache before unlock, and any remainder is released after unlock. The allocator stays out of the critical section on both sides.
The Numbers: 6-48% Gains Across the Board On a writers x readers sweep with 64KB writes against a 1MB pipe, throughput improves 6-28% and average write latency drops 5-22%. Under memory pressure - when the cost of holding the mutex across reclaim is highest - throughput improves 21-48% and latency drops 17-33%. The microbenchmark is already added to kernel selftests. This patch is the kind of low-level fix that doesn't make flashy headlines but shaves milliseconds off every grep | sort | uniq pipeline on the planet. Every shell user on Linux 7.2 gets these gains for free, no config tweaks required.
Source: Linux 7.2 Improves Anonymous/Unnamed Pipe Performance For Shell Pipelines & More
Domain: phoronix.com
Comments load interactively on the live page.