Sparse file
A file with unallocated ranges that read as zeros, allowing its logical size to exceed its allocated storage.
On Linux, seeking past EOF alone does not extend a file; writing there leaves a zero-reading gap. SEEK_DATA and SEEK_HOLE are not exact physical allocation maps because filesystems may conservatively report every offset as data.
Linux st_blocks counts 512-byte units; st_blksize is a preferred I/O size, not that count's unit. A three-file Hesela observation on ext4 found identical zero readback before and after allocation changes; this is a scoped example, not a universal physical-space measurement.
A SEEK_HOLE result can include allocated unwritten ranges. In Hesela's ext4 observation, a source preread changed GNU cp's destination allocation for a half-preallocated zero file without changing any bytes; fully preallocated files were a negative control. A sparse copy is not a guarantee of preserving preallocation.
Sparse output also needs a content precondition when updating an existing destination. GNU dd with conv=sparse,notrunc can seek past nonzero bytes instead of replacing them with input zeros; this is documented behavior, not hole punching. In a controlled GNU dd 9.4 example, 8192 of 16384 intended replacement bytes remained stale even after a successful final fsync. Larger blocks hid the mismatch for a mixed input but not for an all-zero control. Check exact contents and required surrounding data separately from allocation or synchronization. Operational inference: exclude concurrent writers so skipped ranges remain zero throughout the update.
For GNU dd with bs= and no data-transforming conversion, a short input read can reach the sparse-output check before the requested block is full. iflag=fullblock accumulates reads but does not establish zero destination contents. This source-based pipe-input caveat was not exercised by the regular-file experiment.
Relations
- related
- File size, End of file, File storage, Hole punching, File preallocation, Thin provisioning, File extent, Unwritten extent, Filesystem block, Swapfile, Regular file, SEEK_DATA / SEEK_HOLE
Advantages
- Unwritten gaps can be represented without allocating data blocks for the entire logical range. [1, 2]
Limitations
- Zeros returned by a read do not prove that the corresponding range is a hole. [1]
- Filesystem allocation is not a direct measurement of underlying thin-pool capacity. [2, 3]
- Seek classification depends on filesystem behavior and can reflect page-cache state; it is not an exact allocation map. [6, 7, 9]
- The recorded dd controls concern completed operations on generated regular files; they do not establish behavior after a crash or for raw devices. [11]
Citations
- Linux man-pages: lseek(2), holes and SEEK_DATA/SEEK_HOLE
- Linux man-pages: inode(7), file size and allocated blocks
- LVM2: lvmthin(7), physical allocation, discards and pool exhaustion
- Linux v6.8 iomap seek handling of unwritten extents
- Linux v6.8 page-cache seek classification
- Hesela: recorded sparse-copy observations and versioned method
- Hesela: GNU dd destination preconditions, twelve generated-file configurations and exact byte checks
Further reading
- Sparse files, preallocation and thin-pool capacity
- Hesela: three-run ext4 allocation observation, source hashes and environment
- GNU coreutils v9.4 copy.c: sparse heuristic and copy paths
- GNU Coreutils v9.4 manual: dd sparse and notrunc destination semantics
- Linux man-pages: read(2), successful short reads and pipes
Sources & caveats
- The concurrency precondition is an operational inference; no concurrency experiment was performed.
- Sparse-copy supplement: one host, Linux 6.8.0-146-generic, ext4/tmpfs and GNU cp 9.4-3ubuntu6.3. This is a file-level observation, not a crash, capacity-exhaustion or device-traffic test.
- GNU dd supplement: 12 selected regular-file configurations, repeated on one Ubuntu host with GNU dd 9.4-3ubuntu6.3. Not a failure-rate sample, crash test, device overwrite, sanitization test or independent-host replication.