Definition
Write amplification is the ratio of the number of bytes a storage system physically writes to its storage medium to the number of bytes of data the application asked it to write, both counted over the same period. It is also called the write amplification factor (WAF). Values above 1 come from metadata, check values and padding added to each record, from rewriting whole blocks to change part of one, and from copying still-needed data while reclaiming space.
The idea
An application changes a 4-byte setting and reasons that each change costs 4 bytes of flash. The store, however, writes a whole record: the 4 bytes plus 8 bytes of metadata, 12 bytes in all. Every so often it also reclaims a sector, copying the records that are still needed and erasing the sector. Averaged over a long run, each 4-byte change may cost 24 bytes or far more. Flash wear §8.17, energy and write time all follow the physical bytes, not the logical ones, so an estimate based on 4 bytes per change is several times too optimistic.
The picture is a fixed overhead plus a share of housekeeping. Every change pays the overhead of its own record each time, and on top of that a share of the occasional large job of reclaiming space. Write amplification puts both into one number, so that designs can be compared and lifetimes estimated from what the medium really receives.
How it works
Write amplification has several sources, and one store may have all of them.
Record overhead. Each record adds a header or metadata entry, a check value and padding up to the write unit, the smallest amount the medium programs at once.
Block granularity. A medium that must rewrite a whole unit to change part of it multiplies every small change. Changing 4 bytes in place on flash memory §6.6 means erasing and rewriting the whole erase block, often 4096 bytes.
Garbage collection §8.16. Reclaiming space in a log copies live records, those still holding current values, before an erase.
Redundancy. Write-ahead logging §8.12 writes each change twice, once to a log and once to its final place, and keeping two copies of a value writes it twice.
Bookkeeping. Commit records §8.21, sector headers and markers are written in addition to the data.
To measure it, fix three things before counting.
The physical count : usually the bytes programmed into the medium, padding included.
The logical count : usually the bytes of values the application asked to write.
The window, the period over which both are counted. It must contain many complete collection cycles; otherwise it either misses the collections, and the ratio comes out too low, or catches one, and the ratio comes out far too high.
Write amplification is then . Erases are not bytes written, so count them separately, for example as erases per thousand updates.
For a log, the long-run value follows from the live fraction of the regions that collection reclaims. Collecting a region of bytes copies bytes and leaves bytes for new records. So every bytes of new records cost bytes of programming in total, and every new record byte costs programmed bytes.
Worked example
A 4-byte value is stored as a 12-byte record, 4 bytes of value and 8 bytes of metadata, in sectors that hold 4080 bytes of records.
Record overhead alone: .
With collection at : each new record costs programmed bytes, so write amplification is . Check by counting one sector: collection copies bytes, the other 2040 bytes take new records, and the sector receives bytes for logical bytes, and . One erase serves those 170 updates.
With collection at : programmed bytes per update, write amplification .
In place, without a log: each change erases and reprograms a whole 4096-byte block, , plus one erase per update.
The window matters. At , the update that triggers collection programs bytes, a ratio of for that update alone. A window of the 169 ordinary updates that follow shows a ratio of 3. A window of all 170 updates of one cycle shows , the long-run value.
Divide totals; do not average per-update ratios. An update of 4 bytes that programs 12 bytes has a ratio of 3, and an update of 400 bytes that programs 408 bytes has a ratio of 1.02. The average of the two ratios is , but the medium received bytes for logical bytes, a ratio of . Only the ratio of the totals says how many bytes the medium really received; the entry on the ratio of aggregates versus aggregate of ratios §11.40 explains the difference.
Stated precisely
Let be the number of bytes programmed into the medium and the number of logical bytes the application asked to write, both counted over the same window. Write amplification is a pure number, because the byte units cancel. For a log in steady state §11.27, assume that each update of logical bytes writes one record of bytes, that the regions collected have average live fraction with , that a copy has the size of its original, and that the window covers many complete collection cycles. Then The first factor is the record overhead and the second the cost of collection, which grows without bound as approaches 1. Stacked layers multiply: if an upper layer, such as a file system, turns bytes into , and a lower layer, such as a drive, turns into , then .
Limits and common mistakes
A ratio means something only with its definitions. Two figures of write amplification are comparable only if they count the same bytes at the same boundary over comparable windows, and the ratio is undefined when .
Erases are not in . A design with a lower ratio can still erase more often, so report erases per update next to the ratio.
A store that skips writing a value equal to the current one, as Zephyr §6.33 NVS (Non-Volatile Storage) does, can show a ratio below 1 when counts requested bytes. That says the requests were redundant, not that writing became cheaper. For the same reason, a ratio of 1 does not show that only application data was written: if the same 4-byte value is requested three times and only the first request is written, as a 12-byte record, then and , a ratio of 1, although 8 of the 12 bytes written were metadata.
A low ratio is not crash safety. Overwriting a value in place, on a medium that can overwrite bytes, has a ratio near 1 and can leave a torn write §8.19, a mixture of old and new bytes, after a power failure. Nor does a low ratio mean short write times: a store can spread collection evenly or concentrate it in rare, slow writes with the same ratio.
Questions answered
How much flash traffic can one logical key update cause?
One logical key update, a change to the value stored under one key, always programs at least its whole record and can program thousands of bytes of flash plus an erase. For a 4-byte value stored as a 12-byte record in sectors of 4080 usable bytes:
every update programs at least its 12-byte record, 3 times its logical size;
averaged over time, copying by garbage collection multiplies that by , where is the live fraction of the sectors collected: 24 bytes per update at , 120 bytes at ;
the single update that triggers a collection also programs the copied live records, 2052 bytes in all at , close to a whole sector when the victim is almost entirely live, plus one erase of the 4096-byte sector; if one write must collect several sectors, each adds as much again.
Without a log, changing the value in place erases and reprograms a whole 4096-byte erase block for 4 bytes of data. To quantify the traffic, count programmed bytes and erases separately over a window that covers complete collection cycles, and divide the totals by the logical bytes.
Related entries: Garbage collection (§8.16), Flash wear and endurance (§8.17), Ratio of aggregates versus aggregate of ratios (§11.40). Further reading: [12].