Section 8.17

Flash wear and endurance

Definition

Flash wear is the gradual damage that erasing and programming cause to the cells of flash memory §6.6, the storage that keeps data without power and must erase a whole block before rewriting any of it. Endurance is the number of program/erase cycles, each one erase of a block followed by programming it, that the manufacturer guarantees every block survives while still storing data reliably. The nRF52840 §6.4 microcontroller §6.1, for example, guarantees at least 10,000 cycles per 4096-byte page. The guarantee holds only within the stated temperature range and supply voltages.

The idea

A device saves its state once a minute, and each save appends a small record to a log in flash memory. Endurance is counted in cycles, and every cycle contains one erase of a whole block. A log erases a block only after the block has filled, so the block’s count rises once per fill, however many records the fill took. Bigger records and more frequent saves fill blocks faster, and more blocks taking turns share the erases.

The damage is physical. A cell holds a bit as charge in an insulated region, and each program or erase pushes charge through a thin insulating film and degrades it slightly. Worn cells program and erase more slowly and hold their charge for less time, until data no longer reads back reliably. The rated endurance is a guaranteed floor for planning, not the point of failure, and it promises nothing beyond itself.

How it works

An estimate of life follows the erases.

  1. Effective record size bb: the bytes one update really occupies, meaning the value plus its header or metadata, its check value and its padding up to the write unit.

  2. Records per sector n=⌊C/b⌋n = \lfloor C / b \rfloor, where CC is the space in one sector available for records and ⌊x⌋\lfloor x \rfloor means xx rounded down to a whole number; a record that does not fit whole goes to the next sector.

  3. Updates per round. A log that uses its SS sectors in turn absorbs SnS n updates in one trip round the ring and erases each sector once.

  4. Total updates. Each sector may be erased EE times, the endurance, so the area absorbs SnES n E updates.

  5. Life. Divide by the update rate uu, in updates per day.

Three corrections usually lower the result.

Endurance is one of two limits. The other is retention, the time that programmed data stays readable without power, which heat and wear shorten. Spreading erases evenly over blocks is called wear leveling. A log that rotates through its sectors levels wear among them, and the controller inside a memory card or solid-state drive levels wear over the whole device. The flash memory built into a microcontroller has no such controller, so the storage software must do it.

Worked example

Take the nRF52840: sectors of 4096 bytes and endurance E=10,000E = 10{,}000 cycles. Let each sector keep 16 bytes for bookkeeping, leaving C=4096−16=4080C = 4096 - 16 = 4080 bytes for records. A record holds a 4-byte value and 8 bytes of metadata, so b=12b = 12 bytes and n=⌊4080/12⌋=340n = \lfloor 4080 / 12 \rfloor = 340 records per sector. The log has S=2S = 2 sectors, and the device saves once a minute, u=60×24=1440u = 60 \times 24 = 1440 updates per day. Ignoring copies, life is SnEu=2×340×10,0001440=6,800,0001440≈4722 days,\frac{S \, n \, E}{u} = \frac{2 \times 340 \times 10{,}000}{1440} = \frac{6{,}800{,}000}{1440} \approx 4722 \text{ days}, about 12.9 years. Each sector is erased once every 2×340=6802 \times 340 = 680 updates, that is 1440/680≈2.11440 / 680 \approx 2.1 times a day.

Change one factor at a time.

The documentation of Zephyr §6.33 NVS (Non-Volatile Storage), the flash storage library of the Zephyr RTOS (real-time operating system), gives the same estimate in minutes, without the rounding down of step 2.

Stated precisely

Let SS be the number of sectors that take turns, CC the bytes per sector available for records, b>0b > 0 the effective bytes per update, ff the average fraction of each sector taken by copies, with 0≤f<10 \le f < 1, EE the guaranteed erase cycles per sector and u>0u > 0 the updates per day. The number of days until the first sector reaches EE erases is T=S⌊C/b⌋(1−f)Eu.T = \frac{S \, \lfloor C / b \rfloor \, (1 - f) \, E}{u}. The formula assumes that:

  1. every update appends exactly one record of bb bytes, and nothing else writes to the area;

  2. the sectors are erased in strict rotation, so that all reach the same count together;

  3. the update rate stays at uu;

  4. the device stays within the temperature range and supply voltages for which EE is guaranteed.

TT is the period of guaranteed operation, not a predicted date of failure. Beyond TT the specification promises nothing.

Limits and common mistakes

The endurance figure is a minimum guaranteed within stated temperature and voltage limits, not a measured average and not a promise of calendar life. A different chip, or the same chip run hotter, needs its own figure.

Writing more bytes does not by itself wear flash faster; erasing does. Two designs that write the same bytes can differ greatly in wear if one of them erases more often, for example by rewriting data in place instead of appending.

The estimate covers only the log’s own area and the traffic it models. Another writer in the same sectors, a value at a fixed place, or a reset loop that saves a record at every start-up can use up endurance far faster than the normal update rate suggests. A store that skips a write whose value equals the current one, as Zephyr NVS does, removes those updates from uu.

Wear-out is a separate failure from a torn write §8.19, poor retention or a software bug; an endurance estimate covers none of them.

Questions answered

How do record size, update frequency, and sector rotation affect estimated life?

Estimated life is the number of updates a storage area can absorb before its sectors reach their guaranteed erase count, divided by the update rate: life in days =S⌊C/b⌋E/u= S \lfloor C / b \rfloor E / u, for SS sectors taking turns, CC usable bytes per sector, bb bytes per record, EE guaranteed erases per sector and uu updates per day, where ⌊x⌋\lfloor x \rfloor means xx rounded down. All three factors act through the erase rate, because flash memory wears by erase cycles.

Record size: a larger record, counting metadata, check values and padding, fills a sector sooner, so the sector is erased more often. With 4080 usable bytes per sector, 48-byte records instead of 12-byte ones give 85 records per sector instead of 340, and a quarter of the life. Update frequency divides life directly. Sector rotation multiplies it, because more sectors share the same erases: 8 sectors instead of 2 give four times the life, but only if all sectors really take turns and nothing is rewritten at a fixed place. Copies made by garbage collection lower the result by the fraction of each sector they fill, and the figure holds only within the chip’s stated temperature and voltage limits.

Related entries: Write amplification (§8.18), Circular log (§8.14), Flash memory (§6.6), Garbage collection (§8.16). Further reading: [12, 56].