Section 8.18

Write amplification

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.

To measure it, fix three things before counting.

  1. The physical count PP: usually the bytes programmed into the medium, padding included.

  2. The logical count LL: usually the bytes of values the application asked to write.

  3. 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 P/LP / L. 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 uu of the regions that collection reclaims. Collecting a region of CC bytes copies uCuC bytes and leaves (1−u)C(1 - u)C bytes for new records. So every (1−u)C(1 - u)C bytes of new records cost CC bytes of programming in total, and every new record byte costs 1/(1−u)1 / (1 - u) 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.

The window matters. At u=0.5u = 0.5, the update that triggers collection programs 2040+12=20522040 + 12 = 2052 bytes, a ratio of 2052/4=5132052 / 4 = 513 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 (169×12+2052)/680=(2028+2052)/680=4080/680=6(169 \times 12 + 2052) / 680 = (2028 + 2052) / 680 = 4080 / 680 = 6, 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 (3+1.02)/2=2.01(3 + 1.02) / 2 = 2.01, but the medium received 12+408=42012 + 408 = 420 bytes for 4+400=4044 + 400 = 404 logical bytes, a ratio of 420/404≈1.04420 / 404 \approx 1.04. 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 PP be the number of bytes programmed into the medium and L>0L > 0 the number of logical bytes the application asked to write, both counted over the same window. Write amplification is A=PL,A = \frac{P}{L}, a pure number, because the byte units cancel. For a log in steady state §11.27, assume that each update of ℓ\ell logical bytes writes one record of bb bytes, that the regions collected have average live fraction uu with 0≤u<10 \le u < 1, that a copy has the size of its original, and that the window covers many complete collection cycles. Then A≈bℓ⋅11−u.A \approx \frac{b}{\ell} \cdot \frac{1}{1 - u}. The first factor is the record overhead and the second the cost of collection, which grows without bound as uu approaches 1. Stacked layers multiply: if an upper layer, such as a file system, turns LL bytes into P1P_1, and a lower layer, such as a drive, turns P1P_1 into P2P_2, then P2/L=(P2/P1)(P1/L)P_2 / L = (P_2 / P_1)(P_1 / L).

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 L=0L = 0.

Erases are not in PP. 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 LL 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 P=12P = 12 and L=3×4=12L = 3 \times 4 = 12, 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:

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].