← 返回日报
精读 预计 1 分钟

Linux 7.2 Improves Anonymous/Unnamed Pipe Performance For Shell Pipelines & More

摘要

Linux 7.2 内核合并了一项针对匿名 / 无名管道(anon pipe)写入的性能优化。该优化源于 Meta 工程师 Breno Leitao 在缓存代码分析中发现的管道互斥锁争用问题,通过将页分配操作移出锁临界区来避免争用。具体做法是在获取 pipe->mutex 前预分配最多 8 个页面,剩余页面在解锁前回收至临时缓存,解锁后释放,从而将内存分配器完全移出临界区。在 64KB 写入、1MB 管道的读写测试中,吞吐量提升 6-28%,平均写入延迟降低 5-22%;在内存压力下,吞吐量提升 21-48%,延迟降低 17-33%。该优化对 shell 管道及应用程序标准流等场景有益。

荐读理由

你获知 Linux 7.2 通过预分配页面避免管道写锁争用,在内存压力下吞吐量提升可达 48%,这在你排查高负载下管道通信延迟时可作为内核层面的已知改进。

原文

Linux 7.2 Improves Anonymous/Unnamed Pipe Performance For Shell Pipelines & More

Written by Michael Larabel in Linux Kernel on 16 June 2026 at 01:05 PM EDT. Add A Comment

LINUX KERNEL

Yet another performance optimization merged for the in-development Linux 7.2 kernel is improving the speed of anon_pipe_write, the kernel function used for writing data into anonymous/unnamed pipes such as when using shell pipelines or standard streams from applications.

Breno Leitao of Meta was profiling some of their caching code and found pipe to mutex contention in a hot path, which is now resolved by the newly-merged code to pre-allocate outside the lock for avoiding contention.

In the VFS misc pull request that situation is described as:

"anon_pipe_write() called alloc_page() once per page while holding pipe->mutex. The allocation can sleep doing direct reclaim and runs memcg charging, which extends the critical section and stalls any concurrent reader on the same mutex. Now up to 8 pages are pre-allocated before the mutex is taken, leftovers are recycled into the per-pipe tmp_page[] cache before unlock, and any remainder is released after unlock, keeping the allocator out of the critical section on both sides. On a writers x readers sweep with 64KB writes against a 1 MB 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 added to selftests."

Very nice gains. More of the numbers in detail can be found via this patch cover letter by Breno Leitao.

Linux 7.2 unnamed pipes performance

That work is now merged for Linux 7.2.

Lobsters · 1 赞 · 0 评 讨论 → 阅读原文 →

这条对你有帮助吗?