Copying a File Without read() and write() Is About Twice as Fast: sendfile vs copy_file_range vs splice, Measured
At 1 GiB, sendfile, copy_file_range, and splice copy a file in 365–467 ms against 854 ms for a read/write loop on median — about twice as fast. At 64 MiB the edge is gone, and at 1 MiB it is noise.
Written November 9, 2026 · Tested with GCC 13.3.0 · 14 min read
- The four calls, briefly
- The table: wall time at three sizes
- The correction the fresh run forced
- The syscall table: the win is the copies, not the call count
What this guide is
Linux has four ways to copy a file in C: the plain read and write loop, and three calls that do the work inside the kernel — sendfile, copy_file_range, and splice. Every reference page says the kernel calls are more efficient than the loop. None of them says by how much, at what size, or whether the three kernel calls differ from each other. This guide measures all four on the same box, at three sizes, with the same source file and the same warm page cache.
The measurement is a C program, compiled with GCC 13.3.0. The source files are random bytes on tmpfs (/dev/shm, 12 GiB), created once and reused across all four methods.
The four calls, briefly
The four calls differ in what they move and where the data goes, and those differences explain the tables below.
read and write is the baseline loop: read pulls 64 KiB from the source file into a buffer in user space, write pushes it back out to the destination. Every byte crosses into user space and back. At 1 GiB that is 16,384 reads and 16,384 writes.
sendfile copies data between two file descriptors inside the kernel, so the bytes never enter user space. The manual page states it is more efficient than read plus write for exactly that reason. The source descriptor must support mmap-like operations, which a regular file does and a socket does not. The destination had to be a socket before Linux 2.6.33; since then it can be any file. One detail matters for correct code: a successful call may write fewer bytes than requested, so the caller must loop until the whole file is moved. The probe loops.
copy_file_range is the newest of the three: an in-kernel copy between two file descriptors with no transfer to user space and back. The flags argument must be 0. The two descriptors may refer to the same file, as long as the source and target ranges do not overlap. It needs _GNU_SOURCE and _FILE_OFFSET_BITS 64.
splice moves data between two file descriptors without copying between kernel and user address space, but with a constraint the other two do not have: one of the descriptors must be a pipe. A file-to-file copy through splice therefore takes two calls per chunk — one from the file into the pipe, one from the pipe into the destination file — and the pipe holds 64 KiB per chunk in this probe. SPLICE_F_MOVE asks the kernel to move pages instead of copying them, but the manual page states it is only a hint: pages may still be copied.
The table: wall time at three sizes
All times are milliseconds, medians of 3, with the full range of the 3 repetitions in brackets.
- 1 MiB — read/write 0.456 (0.428–1.018); sendfile 0.367 (0.353–0.477); copy_file_range 0.440 (0.363–0.746); splice 0.464 (0.386–0.826).
- 64 MiB — read/write 27.189 (26.484–56.685); sendfile 25.168 (24.341–47.056); copy_file_range 27.927 (27.334–45.850); splice 26.866 (24.927–28.545).
- 1 GiB — read/write 854.369 (397.894–854.669); sendfile 466.754 (399.792–554.948); copy_file_range 365.003 (364.104–365.790); splice 389.639 (386.269–710.630).
At 1 GiB the kernel-side methods beat the loop by 1.83-fold (sendfile), 2.34-fold (copy_file_range), and 2.19-fold (splice) on median. In throughput that is 1.17 GiB/s for the loop against 2.14, 2.74, and 2.57 GiB/s. The wall time is almost all system time at this size: the loop's slowest repetition spent 814 ms of its 855 ms in the kernel, and copy_file_range spent 350 ms of its 364 ms there. The work is kernel-bound in all four methods, including the loop.
- 1 MiB — read/write 0.796 (0.441–1.559); sendfile 0.846 (0.535–1.116); copy_file_range 0.571 (0.350–0.712); splice 0.444 (0.393–0.937).
- 64 MiB — read/write 30.102 (29.042–68.586); sendfile 25.946 (24.720–29.933); copy_file_range 27.189 (24.210–49.836); splice 27.974 (27.724–30.875).
- 1 GiB — read/write 943.056 (426.849–1232.925); sendfile 374.347 (372.504–422.554); copy_file_range 382.230 (371.272–386.789); splice 398.597 (395.498–594.032).
The two nights agree on the shape: kernel-side wins by roughly 2-fold at 1 GiB, the edge shrinks at 64 MiB, and 1 MiB is noise. They disagree on two points that matter, and the next section states them plainly.
The correction the fresh run forced
The previous night's run supported two claims that the fresh run does not. Both are corrected here, because a guide that keeps a claim its own re-run refuted is worse than no guide.
First, the previous night's table could be read as "every kernel-side copy beats every read/write copy": sendfile's worst repetition (422.554 ms) was still faster than the loop's best (426.849 ms), by 4 ms. The fresh run breaks that: splice's worst repetition took 710.630 ms while the loop's best took 397.894 ms. The honest claim is the medians with their ranges, not a sweep of every repetition. At 1 GiB the kernel methods are about twice as fast on median, and their ranges overlap the loop's range at the edges.
Second, the previous night's three kernel methods sat within about 7 percent of each other at 1 GiB (374, 382, and 399 ms), which invited the claim that picking among them is not a performance decision. The fresh run spreads them further: copy_file_range at 365 ms against sendfile at 467 ms, a 28 percent gap on median, and the ranking flips between nights — sendfile was fastest on the first night, copy_file_range on the second. copy_file_range was also the tightest on the fresh run: its three repetitions landed within 1.7 ms of each other (364.104–365.790), while sendfile ranged over 155 ms and splice over 324 ms. That tightness is a real observation from one run of 3 repetitions, not a verdict: it says copy_file_range was the most consistent that night, not that it is the fastest call in general. The standing conclusion holds in its weaker form — the choice that matters is kernel-side against the loop, and the choice among the three kernel calls is not settled by these numbers.
The loop itself is the unstable arm. Its 1 GiB repetitions span 398–855 ms on the fresh run and 427–1,233 ms on the previous night, a roughly 3-fold spread in both. The kernel methods are steadier, and copy_file_range steadiest of all on the fresh run, but a single median for the loop hides a spread that wide. Report the loop's range, never its median alone.
The syscall table: the win is the copies, not the call count
The probe counts its own data syscalls with an in-program counter (there is no strace; the counts below are the counter's numbers, not a tracer's). At 64 MiB:
| Method | Data syscalls per 64 MiB copy |
|---|---|
| read/write (64 KiB buffer) | 2,048 (1,024 read + 1,024 write) |
| sendfile | 1 |
| copy_file_range | 1 |
| splice (via pipe) | 2,048 (1,024 in + 1,024 out, 64 KiB pipe chunks) |
splice makes the same number of syscalls as the loop — 2,048 — and matches sendfile's speed. So the win is not fewer syscalls. The win is the avoided user-space copies: splice moves the bytes through a kernel pipe without ever materializing them in the program's buffer, and it is as fast as the one-call methods despite paying for 2,048 calls. sendfile and copy_file_range win on both axes (1 call, no copies). The mechanism claim is the count table, not a theory: same call count as the loop, same speed as the one-call methods.
The counts scale exactly as the chunk size predicts: at 1 MiB the loop and splice make 32 calls each and the other two make 1; at 1 GiB the loop and splice make 32,768 each and the other two make 1. The destination is verified correct in every case: the SHA-256 of the copied file matches the source for all four methods at 64 MiB, on both nights.
Where the edge goes: 64 MiB and 1 MiB
At 64 MiB there is no winner. The four medians on the fresh run are 27.189, 25.168, 27.927, and 26.866 ms — within 11 percent of each other, and copy_file_range is slower than the loop on median that night. The previous night says the same: 30.102, 25.946, 27.189, and 27.974 ms. The kernel-side edge at this size is inside run-to-run noise, and any guide that ranks the four methods at 64 MiB is ranking noise.
At 1 MiB there is nothing to rank at all. All four methods land between 0.35 and 1.02 ms on the fresh run, and the ordering flips between nights. A 1 MiB copy is dominated by process and call overhead at this granularity, and the guide claims nothing at this size.
The practical reading is a threshold, not a ranking. Below roughly 64 MiB, the choice among the four methods costs nothing measurable in wall time, so it should be made on portability and code shape: the loop works everywhere, copy_file_range needs Linux 4.5 or later, sendfile needs a mmap-able source, splice needs a pipe. Above roughly 1 GiB on warm cache, the kernel-side methods are about twice as fast as the loop, and the choice among them is still open.
What this guide does not show
The page cache was warm in every cell, and there was no cache drop between repetitions because the box has no root access to drop it. Cold-disk behavior is unmeasured: on a cold spinning disk the read side may dominate and the ranking may compress or invert. The guide's numbers are warm-cache numbers.
The filesystem is tmpfs only. There is no real disk, no network, and no fsync or writeback in the timed path, so dirty-page writeback is not in these numbers. A copy to a real disk pays writeback that tmpfs never charges.
The copy is one file, sequential, one thread. There is no concurrency arm and no many-small-files arm: with many small files the per-file open and close would dominate, and that is a different probe.
The user-versus-system split at 1 MiB is at the timer floor — some repetitions report the whole millisecond as user time and zero as system time, which is a granularity artifact, not a finding. The split is meaningful only at 1 GiB, where it shows the work is kernel-bound in all four methods.
The closest prior work measures different things. Ariadne's cat study pipes a 4 GiB tmpfs file into dd of=/dev/null, a sink, not a file destination, and reports 3.6 GB/s for the loop against 6.4 for sendfile and 11.6 for splice. The Go zero-copy study serves a 512 MiB file over plain TCP, socket serving again, not a file-to-file copy. CPython's shutil.copyfile gained os.sendfile support in 3.8 with a measured 26 percent speedup on a 512 MB copy, a library-level result with no per-method table and no copy_file_range or splice arm. A copy-programming guide asserts copy_file_range is the most efficient method with a "95 percent efficiency" figure and publishes no measured table for the four syscalls on one box. This guide's table is the file-to-file comparison those sources do not publish.
Checklist
- Before choosing a copy method for a large file, check the size: below roughly 64 MiB the four methods tie, so choose on portability and code shape, not speed.
- Before claiming a kernel-side method always beats the loop, check the ranges: on the fresh run
splice's worst repetition (710.630 ms) was slower than the loop's best (397.894 ms), so the claim is medians, not every repetition. - Before ranking
sendfile,copy_file_range, andspliceagainst each other, run the probe twice: the ranking flipped between nights, andcopy_file_range's tightest run is one run of 3 repetitions, not a verdict. - Before reporting the loop's speed, report its range: its 1 GiB repetitions span 398–855 ms on the fresh run and 427–1,233 ms on the previous night.
- Before crediting the speedup to fewer syscalls, count them:
splicemakes 2,048 calls at 64 MiB, the same as the loop, and matches the one-call methods — the win is the avoided user-space copies. - Before using
sendfilein production code, loop on short writes: the manual page states a successful call may write fewer bytes than requested. - Before using
splicefor a file-to-file copy, remember the pipe: one descriptor must be a pipe, so the copy takes two calls per chunk, andSPLICE_F_MOVEis a hint, not a guarantee. - Before applying these numbers to disk, remember the setup: warm page cache, tmpfs only, no
fsync, one file, one thread — cold-disk behavior is unmeasured here. - Before reproducing the probe, check the tooling: there is no
strace, so the syscall counts come from the probe's own counter, not a tracer.
Related guides on this site
- Copying a Sparse File, Measured: Which Tools Preserve the Holes
- Copying a 1 GiB File: dd at bs=512 Is 9x Slower — and cp Ties dd Once the Block Size Is Right
- Copying, Moving, and Splitting Files: Ten Measured Guides
- Copying a Directory Tree, Measured: cp -a vs rsync -a vs tar-pipe
Sources
- Linux man-pages project, sendfile(2) — read on the box 2026-11-09:
sendfilecopies between file descriptors within the kernel, more efficient thanreadpluswrite; the source must support mmap-like operations; the destination can be any file since Linux 2.6.33; a successful call may write fewer bytes than requested, so the caller must retry. - Linux man-pages project, copy_file_range(2) — read on the box 2026-11-09: an in-kernel copy between two file descriptors with no transfer to user space and back; the flags argument must be 0; the two descriptors may refer to the same file if the ranges do not overlap.
- Linux man-pages project, splice(2) — read on the box 2026-11-09:
splicemoves data between file descriptors without copying between kernel and user address space, and one of the descriptors must refer to a pipe;SPLICE_F_MOVEis only a hint and pages may still be copied. - Ariadne, How efficient can cat(1) be? — read in full 2026-11-09: a 4 GiB tmpfs file piped into
dd of=/dev/null, a sink, not a file destination; 3.6 GB/s for the read/write loop, 6.4 forsendfile, 11.6 forsplice;copy_file_rangeasserted to be possibly faster thansplice, with no measured number. - Segflow, Zero-copy in Go: sendfile, splice, and the cost of io.Copy — read 2026-11-09: a 512 MiB file served over plain TCP in Go, with
stracesyscall counts; socket serving, not a file-to-file copy. - Python tracker, Issue 33671: Efficient zero-copy for shutil.copy* functions — read 2026-11-09:
shutil.copyfilegainedos.sendfilesupport in Python 3.8, with a measured 26 percent speedup on a 512 MB copy on Linux (872 ms to 646 ms per loop); a library-level result with no per-method table and nocopy_file_rangeorsplicearm. - copyprogramming, The Most Efficient Way to Copy Files in Linux — read 2026-11-09: asserts
copy_file_rangeis the most efficient method with a "95 percent efficiency" figure; its comparison table covers bufferedfread/fwrite,cp, andcp --reflink, not the four syscalls on one box. - Veldica, rsync Delta vs Whole File: Wall Clock, Measured — the sibling guide: the same warm-cache, tmpfs harness asking a different copy question, delta against whole-file transfer, not which syscall copies a file.
- Veldica, Copying a 1 GiB File: dd at bs=512 Is 9x Slower — the follow-up guide: the CLI-level copy on the same box, dd at bs=512 is 8.8 to 9.7 times slower than bs=1M across four runs, and plain cp and cat tie tuned dd.
Keep Exploring
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.
Paste sshd -G output and get a hardening verdict on the values your server actually runs.
Paste a server block and get WebSocket, TLS, HSTS, and proxy-header verdicts.
Paste a systemd timer expression and get the specific reason it fails, the normalized form, and the past-date traps the built-in check hides.
The full sysadmin hub \u2014 systemd, cgroups, file tools, and measured Linux comparisons.