How fast are Linux pipes?
Summary
In “How fast are Linux pipes anyway?”, Francesco Mazzoli examines how pipes work in the Linux kernel by optimising a test program step by step. Starting from around 3.5 GiB/s, throughput rises to about 65 GiB/s through vmsplice, splice, huge pages and busy looping. Each step is justified with the perf profiler and a look at the kernel source code.
What it is about
A pipe connects two programs: what one writes, the other reads. The article was prompted by an extremely optimised FizzBuzz program that writes text into a pipe at around 36 GiB/s. A naive program using write and read, on the other hand, only managed 3.5 GiB/s, even though it computes nothing at all.
The reason: with write and read, the kernel copies each block twice, once from the writing program’s memory into the pipe’s ring buffer and once out again. perf showed that much of the time is spent precisely on copying and allocating memory pages.
The optimisation steps
vmsplice and splice pass only references to memory pages to the pipe instead of the data, saving copies. After that, managing the pages becomes the bottleneck; huge pages of 2 MiB instead of 4 KiB reduce this effort drastically. Finally, busy looping replaces putting processes to sleep and waking them, which saves latency but permanently occupies a CPU core. Both processes were also pinned to fixed cores with taskset.
The end result is around 65 GiB/s, about twenty times the starting value. Measurements were taken on an Intel Core i7-8550U running Linux 5.17.
What you can learn from it
The article is less a guide to pipes than a lesson in performance analysis: measure first, then understand the bottleneck, then change things in a targeted way. Along the way it explains zero-copy, ring buffers, page tables and synchronisation costs. Splice is considered a tricky concept; in March 2022 a severe vulnerability in the interplay of pipes and splice became known as Dirty Pipe.
Ideas
- perf shows where a program actually spends time in the kernel.
- splice and vmsplice pass page references instead of copying data.
- Huge pages reduce the management effort for many memory pages.
- Busy looping trades CPU time for lower latency.
Insights
- Zero-copy usually means fewer copies, not none at all.
- A faster microbenchmark can choose the wrong resource trade-off for real applications.
Facts
- Throughput rose from around 3.5 GiB/s to about 65 GiB/s.
- Measurements were taken on an Intel Core i7-8550U running Linux 5.17.
- In June 2022 the article reached 698 points and 200 comments on Hacker News.
References
Remarks
- The article made it onto Hacker News again in 2023 and 2025, each time marked “(2022)”.
Recommendations
- Profile with perf first before swapping buffers or system calls.
- Assess throughput, CPU usage and latency together, not just the peak value.
Found a mistake or have something to add? Get in touch.
Links to the original source and the Web Archive open in a new tab.