OverlayFS: a small write can trigger a large copy-up
Trace upper/lower lookup, data and metadata copy-up, whiteouts, and storage amplification under explicit OverlayFS feature settings.
On this page
The question for today
What you’ll understand
- Explain which object a merged name resolves to.
- Calculate simplified full-file copy-up amplification.
- Distinguish kernel whiteouts and metacopy from image-layer archive conventions.
A writable container layer often presents an OverlayFS merged tree over read-only image content. Reading a lower-layer file can be cheap, while opening it for modification may require creating an upper representation and copying data. A one-byte application change is therefore not necessarily one byte of storage work. This lesson uses Linux 6.12 OverlayFS with an explicit writable upper and compatible work directory. Features such as metacopy, redirect handling, indexing, and the underlying filesystem can change details, so measurements must record the mounted configuration.
Merged lookup is not concatenation of file contents
When a name exists in upper and lower trees, the upper non-directory object generally hides the lower one; directories can present a merged set of names. The result is a namespace view, not a bytewise merge of two versions of the same regular file. The work directory supports OverlayFS operations and must satisfy the kernel's upper/work requirements, including being on the same filesystem. Sharing lower layers is common, but overlapping or concurrently reused upper/work directories have specific restrictions and are not a safe shortcut for sharing writable state.
Removing a lower-visible name cannot modify a read-only lower tree, so the upper layer records a whiteout that hides it in the merged view. An opaque upper directory can hide the corresponding lower directory's contents. Kernel representations include documented device or xattr forms depending on the feature configuration. These are distinct from OCI image archive whiteout naming conventions, which an image unpacker interprets. Deleting a lower-visible name does not imply its image bytes were erased from the lower layer or that its space was reclaimed there.
Copy-up has data, metadata, and identity consequences
For an operation requiring write access to a lower-only file, OverlayFS may create the needed upper object, parent directories, metadata, and data before using that upper representation. Opening for read-write can cause copy-up even if no data is ultimately changed, under the documented behavior. Full-file data copying, reflink support, sparse allocation, caching, and filesystem-specific mechanisms affect actual physical work. An estimate based on the logical file size is an explicit model, not a universal measurement of device writes.
With metacopy enabled, a metadata-only operation can copy metadata without immediately copying file data. A later write still needs the appropriate data copy-up. Therefore changing ownership on a large lower file and editing its contents are not always equivalent costs. Record feature support and avoid trusting untrusted layer metadata or redirect combinations outside the documented security constraints. File identity fields can also behave differently across layers and configurations; do not assume a stable device-and-inode story from a single pre-copy observation.
Put mutable application data on an intentional storage path
A database, checkpoint writer, or model cache that repeatedly modifies large image-resident files can incur surprising startup and space costs. Consider whether mutable data belongs on a separately managed volume or should be initialized directly in the writable destination. That decision also changes backup and lifecycle semantics, so verify persistence expectations rather than merely moving files until a benchmark improves. Compare first-write behavior with later writes and account for upper-layer growth, page cache, metadata, and failure recovery separately.
The function lab illustrates one related payload-scaling effect, not OverlayFS itself. Reset, explicitly set a=1 and x=1, predict y=1, then Play or Step; for a separate comparison Reset and explicitly set a=1 and x=2, predicting y=4. Interpret x as normalized side length of a dense square file payload. Four times the lower-file payload can make a full logical copy-up four times larger under that model. The graph has no upper/lower trees, whiteouts, metacopy, reflinks, or device-I/O simulation.
Work it through
Separate a byte edit from its modeled copy
Assume a lower-only regular file has 64 MiB of logical data and the selected configuration performs a full logical data copy-up before changing one 4 KiB block. Ignore metadata, sparse holes, reflinks, compression, and page-cache effects.
Convert units: 64 MiB is 64×1,048,576=67,108,864 bytes. The application changes 4 KiB, or 4,096 bytes.
Under the stated full-copy model, the data-copy amount is 67,108,864 bytes. Dividing by 4,096 gives a logical copy amplification of 16,384 relative to the changed block.
A later edit to the already upper-resident file does not need the same lower-to-upper data copy solely for that reason. Actual storage traffic and latency still need measurement because this ratio excludes metadata, caching, and the backing filesystem's allocation behavior.
The modeled first edit copies a 64 MiB payload for a 4 KiB application change. It is a logical-work estimate, not a claim that every deployment writes exactly that amount to physical media.
The living notebook
Explore the model
Interactive lab · function
Payload size before the first write
Compare fresh Reset → explicitly set both a and x → predict → Play or Step runs at (1,1) and (1,2). The exact graph y=ax² illustrates square-payload scaling only. It does not model copy-up triggers, whiteouts, metacopy, sparse files, reflinks, or physical I/O.
- y at chosen x
- 0.608
- Tangent slope · 2ax
- 1.35
- Signed area · ax³/3
- 0.182
This lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forEstimate the payload that a copy may cover, then measure the actual mounted filesystem path rather than equating changed bytes with copied bytes.
Pause & reason
Check your understanding
Your turn
Try it yourself
Under the same deliberately simplified full-copy assumptions, a 128 MiB lower file is copied before a 1 MiB change. Calculate logical amplification. If the merged pathname is then deleted, does that necessarily free the lower file's 128 MiB?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use a ratio in matching units, then distinguish a whiteout in upper from deletion of lower storage.
Compare with the solution
The logical ratio is 128 MiB divided by 1 MiB, or 128. Actual physical traffic can differ under the excluded features. Deleting the merged lower-visible name can create an upper whiteout that hides it; it does not by itself erase the read-only lower bytes or reclaim their storage. The image and other containers may still use that lower layer. Inspect layer and volume lifecycle policies separately from the merged directory listing.
Keep the idea
Take it with you
- A merged pathname selects or hides layer objects rather than merging regular-file bytes.
- Copy-up cost depends on operation, feature flags, and backing filesystem behavior.
- Whiteout visibility and physical space reclamation are different events.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.