Research notes / File I/O
Zero-copy transfers do not freeze source bytes
Published / Updated / Measured Linux API behavior
A successful sendfile() can leave the receiver holding references to mutable file pages. In our file-to-pipe test, overwriting the source after the call returned changed the bytes later read from the pipe. Adding fsync() did not freeze them.
This is a documented source-lifetime obligation, not evidence of a Linux bug: zero-copy socket or pipe transfers require the caller to keep transferred regions unchanged until consumption. [1]
On this page13 sections
The same byte count, different byte versions
Each private test file begins with one page of A. We hash it, enqueue the page, then perform the named operation before consuming the pipe, except in the consume-first control. B is the replacement payload; C is written through an old descriptor after pathname replacement. There are no sleeps or concurrent-writer races.
| Sequence | Read | Path | Old inode |
|---|---|---|---|
| read + write, then overwrite | A | B | B |
| sendfile, then overwrite | B | B | B |
| splice, then overwrite | B | B | B |
| sendfile, overwrite, fsync | B | B | B |
| sendfile, replace pathname | A | B | A |
| Replace pathname, then write old inode | C | B | C |
| sendfile, close input fd, overwrite | B | B | B |
| sendfile, consume, then overwrite | A | B | B |
The buffered control had already copied the bytes. The consume-first control had already read them. Both retained A. The other mutation cases demonstrate why enqueue completion alone cannot establish an immutable source version. These are 40 controlled checks, not independent samples estimating a failure rate.
A page reference is not a byte snapshot
In upstream Linux v6.8, splice_folio_into_pipe() puts a page reference in a pipe buffer and increases its reference count. filemap_splice_read() obtains pages from the file's page cache for that path. The reference preserves lifetime; it does not create a private copy of each byte. [3]
This source explains the observed behavior, but we did not trace or rebuild the distribution kernel. Nor does every splice path share pages: the kernel documents copy_splice_read(), which reads into newly allocated pages. A successful API call alone cannot prove that all copying was avoided. [6]
SPLICE_F_MOVE is not a way to demand exclusive ownership or frozen content; the manual documents it as a no-op. The experiment uses zero flags. [2] We also verify the returned count: short successful transfers must not be mistaken for a complete page.
Replacing a pathname helps only if the old object stays unchanged
Renaming a separately written replacement over the source changes what a new pathname lookup opens, while existing descriptors still refer to their previous object. [4] Our replacement-only case therefore delivered A while the pathname read B.
The next case is the important qualification. A writable descriptor still referred to the old inode. Writing C through it changed the queued data to C, even though the pathname continued to expose B. Atomic publication is useful for immutable file versions; rename by itself does not enforce immutability. See pathname publication and directory durability.
The separate close-input case also delivered B. Closing the descriptor used for transfer is not a receiver-consumption barrier. This connects to the broader distinction between descriptor, mapping and object lifetimes.
A checksum can be correct for the wrong intended version
In the overwrite case, a digest computed before enqueue describes A, but the receiver gets B. Hashing the pathname afterwards would describe B too. Agreement between those latter hashes would not prove that the earlier version was transferred. This follows directly from the retained payload hashes; it is not a hash-collision claim.
For backup or content-serving pipelines, bind verification to an identified, stable source version. A snapshot, immutable object version or coordinated writer protocol may provide that contract. Copying into an independent buffer protects bytes already copied, but reading a large changing file in multiple chunks still does not create an atomic snapshot. Compare backup consistency and recovery and checksums and object identity.
Two consumers can disagree after tee(2)
A separate experiment duplicates the queued page into another pipe with the Linux tee(2) system call. It then reads and hashes the first branch, overwrites the source, and reads and hashes the second. The syscall duplicates references without consuming the input; it does not promise independent byte snapshots. [8]
| Pipe filled by | First read | Next read | Hashes agree |
|---|---|---|---|
| sendfile | A | B | No |
| buffered | A | A | Yes |
The file-backed path gave the first consumer A and the second B. The buffered control gave both A. A hash calculated on one branch therefore need not describe bytes later consumed on the other when the source-stability rule is broken. A hashing branch does not itself enforce that rule.
Download the supplement harness, observations and tests. The harness imports the main harness from the same directory and calls libc through Python ctypes; run python3 -B tee-source-lifetime.py --repetitions 5 --output tee-observations.json. It measures neither GNU tee nor any backup product.
Without GIFT does not mean without shared bytes
A separate native experiment starts with an anonymous memory page, not a file. After vmsplice() enqueues it with flags set to zero, overwriting the source changes the later pipe read. Omitting SPLICE_F_GIFT did not make an independent copy. The reverse operation, from pipe to user memory, preserved the version copied at that moment.
| Sequence after enqueue | Received bytes |
|---|---|
| write control, overwrite source | 4,096 A |
| vmsplice, overwrite source | 4,096 B |
| Rebind iovec address and length | 4,096 A |
| Read half, overwrite, read rest | 2,048 A + 2,048 B |
| Copy to user, overwrite source | 4,096 A |
| Overwrite, copy to user, overwrite again | 4,096 B |
| Unmap source, then read | 4,096 A |
| Forward to another pipe, overwrite | 4,096 B |
The partial-read case is the critical versioning witness: reading half, changing the source and reading the rest assembled 2,048 A bytes plus 2,048 B bytes. No concurrent-writer race was needed. Rebinding the caller's iovec to a different address and half-length did not redirect or resize the queued page. Unmapping the original address left the queued bytes readable; that demonstrates retained lifetime, not proof of copying.
The manual explicitly distinguishes the two directions. Its GIFT discussion concerns donation and later page movement, not a promise to copy on initial enqueue when the flag is absent. [14] In the reviewed upstream v6.8 implementation, iter_to_pipe() collects pages regardless of GIFT, whereas pipe_to_user() calls a copy helper. The GIFT check instead appears in the page-stealing path. [13] The reviewed v6.17 revision keeps that distinction; source comparison is not measurement on a second kernel. [15]
Forwarding to another pipe still left the receiver dependent on source bytes. Our engineering conclusion is to track every downstream reference before reusing the producer buffer. A copy taken later freezes the version available then, not necessarily the originally enqueued version. IO-Lite's separation of immutable buffers from mutable range descriptions makes this ownership distinction explicit, but Linux iovec rebinding does not make the underlying bytes immutable. [9, sections 2.1 and 2.2]
The replay packet contains the C probe, both raw captures, source receipts and tests. Three repetitions under each of two compiler settings agreed on one host. No GIFT case, hardware failure, throughput measurement or IO-Lite reproduction is claimed; deliberate mutation outcomes are observations, not portable guarantees. These executions are separate from the earlier file-backed, tee and offset-copyback checks.
IO-Lite made stable bytes part of the design
Pai, Druschel and Zwaenepoel's OSDI 1999 paper offers a useful contrast. IO-Lite shares immutable data buffers, while mutable buffer aggregates describe how their slices fit together. Editing an aggregate allocates new storage for changed bytes. Its file cache replaces buffers on a write, retaining earlier buffers while readers still reference them. [9]
Section 2.1 also separates shared bytes from the description of their range: buffer aggregates carry pointer-length slices and cross subsystem boundaries by value, while their buffers are shared by reference. Our separate sealed-memfd handoff experiment shows why this distinction matters: immutable bytes did not prevent a shared file offset from selecting only a suffix. This is a comparison of contracts, not an IO-Lite reproduction or a claim that its aggregates are Linux file descriptors. [9, section 2.1]
The design also pairs a buffer address with a generation number so cached Internet checksums can identify unchanged contents across reuse. The transferable lesson is to make byte identity and mutation rights explicit when removing copies. This is our design comparison, not a claim that Linux sendfile implements IO-Lite.
Removing copies also has a limit. IO-Lite section 2.8 explains that widely scattered edits can make a fragmented buffer aggregate more expensive to traverse than a contiguous copy. Its mmap path may copy a page on first write when an immutable buffer still references that page, preserving the earlier read snapshot. This is a design-specific trade-off: copying can enforce a version boundary, rather than merely represent wasted work. It does not establish Linux sendfile snapshot semantics. [9, section 2.8]
The prototype used modified FreeBSD 2.2.6 and an application library. Its historical web-server measurements do not predict current Linux performance; the experiment here measures a different API contract.
Stable bytes still need the right input and output positions
Byte identity and range placement are separate obligations. Duplicated descriptors share an open file description, including its cursor; dup() does not allocate an independent position. [10]
| Call | Input position | Output position |
|---|---|---|
sendfile | Explicit pointer or input cursor | Seekable output uses its cursor [1] |
copy_ | Explicit pointer or input cursor | Independent explicit pointer or output cursor [11] |
splice | Pipe: NULL required; seekable file: pointer or cursor | Pipe: NULL required; seekable file: pointer or cursor [2] |
On successful transfer with an explicit offset, the call advances the pointed-to value rather than the corresponding file position. With sendfile(), that choice exists only for the input: a seekable destination's cursor still advances. The offset rules do not relax the source-lifetime requirement. [1]
After a positive short copy_file_range return, retain the updated offsets and subtract the copied count from the remaining work. Zero for a positive-count request indicates EOF: stop instead of retrying without progress. Resetting explicit offsets selects the original range again. Caller-owned offsets avoid shared-cursor dependence, but coordinating overlapping writes and source mutation remains a separate responsibility. [11]
Append mode is not an interchangeable fallback: an O_APPEND destination is rejected by sendfile and splice with EINVAL, and by copy_file_range with EBADF. [1] [2] [11]
An error return can arrive after the bytes
A separate native experiment keeps the source unchanged and makes an explicit offset readable but not writable. The kernel can read the starting position and move data, then fail while writing the new position back to caller memory. In the sendfile case, six bytes reached the destination despite a return of -1/EFAULT. After restoring write permission, a blind retry duplicated them.
| Offset condition | After first call | After blind retry |
|---|---|---|
| sendfile: input read-only | -1 / EFAULTCDEFGH | CDEFGHCDEFGHEarlier input duplicated |
| copy_file_range: input read-only | -1 / EFAULTCDEFGH | CDEFGHCDEFGHEarlier input duplicated |
| copy_file_range: output read-only | -1 / EFAULTCDEFGH | IJKLMNLater input replaces earlier output |
| splice from pipe: output read-only | -1 / EFAULTCDEFGH | IJKLMNLater pipe bytes replace earlier output |
| copy_file_range: both read-only | -1 / EFAULTCDEFGH | CDEFGHSame range rewritten; not a recovery guarantee |
| sendfile: input inaccessible | -1 / EFAULTNo payload | CDEFGHFirst payload appears only after repair |
The stale side matters. If the input offset remains behind while output advances, retry duplicates earlier input. If input advances but output stays behind, retry writes later bytes over the previous range. The pipe-to-file case consumed six bytes before reporting the error; resetting a local output offset cannot put those bytes back into the pipe.
The inspected upstream Linux v6.8 wrappers perform byte transfer and offset copyback separately. In copy_file_range, failure to publish one position does not stop the other position from advancing. [12] The splice wrapper similarly attempts copyback after a nonnegative transfer result. [13]
Do not reverse the inference: EFAULT alone does not establish that bytes moved. Inaccessible-offset controls failed before copying; read-only sendfile offsets also produced that error for zero-count and EOF requests. The table's both-read-only case happens to rewrite the same stable range, but does not establish a safe generic retry rule.
Keep offset storage valid and writable throughout the call. A buffer-lifetime or permission defect needs investigation, not the continuation rule for a successful short return. Our engineering inference is to reconcile the intended source version, range and actual destination state, or discard a private incomplete output and restart. An already-consumed stream needs its own receiver-visible acceptance protocol.
The separate reproducibility packet contains the C probe, raw observations, generated CSV, source receipts and tests. There are 50 snapshots per capture; two compiler modes and a fresh replay agree exactly on one Linux 6.8.0-147-generic host. Deliberately invalid caller buffers are not device failures, a new vulnerability or a crash-persistence test. This extends the position contract without changing the earlier lifetime measurements.
Three completions that should not be conflated
Enqueue completion: this experiment records bytes accepted into a pipe. Source-lifetime completion: the receiver has consumed the referenced data. Persistence completion: synchronization has met the relevant storage contract. fsync() addresses synchronization, not snapshot isolation; our second-fsync case still delivered the changed bytes. [5]
Do not import completion rules from a different API. MSG_ZEROCOPY has socket error-queue notifications for buffer reuse, but they are not transmit-completion notifications and copying may still occur. Those notifications are not supplied by sendfile(). No MSG_ZEROCOPY or TCP experiment was run here. [7]
Copy avoidance is not read sharing
zicIO coordinates a database library and modified kernel through shared control state. Its SKzicIO variant shares a moving page pool; missed chunks are fetched later. In-use pages are protected from recycling. The prototype targets static data, not concurrent-update consistency. Its evaluation used Linux 5.15/ext4; columnar tests disabled compression and parallel processing. These conditions limit performance comparisons. [16, sections 3-6]
This distinction matters when diagnosing an optimization: removing a memory copy, hiding a wait and avoiding a second device read are three different outcomes. Count each separately. A smaller CPU cost per request can coexist with more storage traffic; a shared buffer needs both valid bytes and a reclamation protocol.
Count the command map, not just the data buffer
The author's pinned code archive encodes each command in eight bytes, with lengths from 4 KiB to 256 KiB in its test configuration. The README explains that mapping information is collected at channel opening and becomes stale if file mappings change. It also explicitly identifies the archive as partial, not a runnable full system. [17]
| Request limit | Descriptor payload | Coverage with 4 MiB of descriptors |
|---|---|---|
| 4 KiB | 160 MiB | 2 GiB |
| 64 KiB | 10 MiB | 32 GiB |
| 256 KiB | 2.5 MiB | 128 GiB |
The arithmetic is 8 * sum(ceil(rangeBytes / requestBytes)). Separate ranges round independently. For the illustrated 80 GiB scan, 4 KiB requests need 160 MiB of packed descriptors; 256 KiB requests need 2.5 MiB. That is a 64-fold metadata difference, not a speedup. The 4 MiB column is a separate descriptor-only budget: it does not say the complete scan engine fits in 4 MiB.
Our engineering inference is to budget mapping metadata alongside data buffers and to verify how mapping validity is maintained. The descriptor array does not make changing files immutable. The calculated JSON, model and tests reproduce only this accounting. No zicIO kernel was installed or benchmarked here, and the earlier Linux lifetime observations remain a separate experiment.
Reproduce the sequence, not a timing accident
The dataset contains the CSV, full JSON, harness, tests and source hashes. Download the Python harness and run it on Linux with Python 3.10 or later and GNU stat:
python3 zero-copy-lifetime.py --repetitions 5 --output observations.jsonOnly newly created files in private temporary directories are used. Choose the test filesystem with --temp-dir. The harness checks capacity, exact transfer counts, complete received payloads and cleanup. Unexpected API errors abort instead of being counted as successful observations.
The recorded environment is Python 3.12.3, Linux 6.8.0-146-generic, x86_64; stat -f reports ext2/ext3. That magic label does not identify an ext-family version or mount configuration. Input bytes are synthetic, but the calls and observations are real. This is not a throughput benchmark, crash test, TCP transfer test or survey of filesystems. Mutation cases deliberately violate the source-stability requirement; their particular resulting bytes are observations, not a portable promise.
Corpus definitions: zero-copy I/O, sendfile, splice and tee(2).
Primary sources
- Linux man-pages 6.19: sendfile(2), return value and source lifetime
- Linux man-pages 6.19: splice(2), pipe buffers and flags
- Linux v6.8 mm/filemap.c: splice_folio_into_pipe and filemap_splice_read
- Linux man-pages 6.19: rename(2), replacement and open descriptors
- Linux man-pages 6.19: fsync(2), synchronization and directory entries
- Linux 6.12 documentation: splice and pipes, copy_splice_read
- Linux kernel documentation: MSG_ZEROCOPY, notifications and deferred copies
- Linux man-pages 6.19: tee(2), duplication without consuming and shared references
- Pai, Druschel and Zwaenepoel: IO-Lite, OSDI 1999, sections 2.1, 2.2, 2.5, 2.8, 2.9 and 3
- Linux man-pages: dup(2), shared open file descriptions and file offsets
- Linux man-pages: copy_file_range(2), independent offsets, short copies and append restriction
- Linux v6.8: sendfile64 and copy_file_range transfer followed by offset copyback
- Linux v6.8: offset copyback, vmsplice directions and page donation
- Linux man-pages 6.19: vmsplice(2), directions, GIFT and NOTES
- Linux v6.17: vmsplice source-path comparison
- Lim, Yoon, Kim, Fekete and Jung. Rapid Data Ingestion through DB-OS Co-design. PACMMOD 3(1), article 68, 2025, sections 4 and 6. DOI: 10.1145/3709718.
- Minseok Yoon: partial zicIO source archive, README and mapping assumptions; commit 523e88df673e2d6368732b9dc5cbc7f0242b85b2.