A Short Study on Wear Leveling, part 1

Flash memories wear out, but there are ways to minimize their demise, from application changes to file system software.

By Thom Denholm, Technical Product Manager, Datalight

Over the past fifteen years, flash memory has been widely adopted in mainstream consumer grade products having short lifetimes, often measured in months.  While the limited lifetime of flash memory may or may not be problematic for your products, using the right flash management software can expand the breadth of available flash parts for your project.

This two-part paper focuses on determining when the limitations of flash memory lifetime become significant and what can be done about them. Here in part one, we look at some of the fundamental (first order) issues affecting flash memories.

Flash Lifetime Metrics

Flash memory lifetimes are described in two primary metrics which are generally touted on the first page of any flash memory manufacturers’ data sheets:

  • Data retention
  • Endurance cycles

Data retention is often listed at 20 years at a given operating temperature. Increased temperature ranges reduce the data retention period which further decrease as the flash memory is used at or near its specified operating temperatures. It is important to note that data retention is measured from the time data is successfully programmed.

The second metric, endurance cycles, is a measure of the number of write and erase cycles that the flash memory can endure before becoming unreliable. Flash memories are organized into a number of erase blocks or sectors and each must be erased prior to writing data. A typical erase block is 128 KB in size, however may range from 512 B to 2,048 KB or even more. Any given address within an erase block cannot be rewritten without an intervening erase. Erase cycles are cumulative and affect only those erase blocks being cycled. In other words, an error in any erase block is constrained to the data of that block.

Erase cycles range from 1,000 to 1,000,000. While these ranges have an order of magnitude difference, it is the application the flash is placed into that will primarily define the product lifetime.

What is Wear-Leveling?
Wear-leveling is a process to ensure that an entire flash memory device or an array of devices is used in a uniform fashion in order to extend the overall lifetime of the flash.

For a simplistic example of wear-leveling, let’s look at a data recorder device with the following characteristics:

  • Application: The device collects and stores the past 24 hours of field data by simply writing and rewriting the data to the same location on the flash.
  • File size of data to be recorded: 128 KB
  • Erase block size (of the flash): 128 KB
  • Flash memory endurance: 1,000 cycles

With one spare area, the device is assumed one cycle per day each year:

(1,000 cycles 365 days) * 1 spare area = 2.74 years

In this example, it would take about 2.74 years to cycle that one erase sector 1,000 times.

For the data recorder device to accommodate the write-erase rules of flash memory, it would have to complete an erase operation to start writing the next day’s set of data. To make the data recorder more robust to ensure that it doesn’t lose a whole day’s worth of data we can set aside a second erase block, and erase the first block only after the second set of data was recorded. The resulting side effect is the introduction of a simple wear-leveling scheme.

With two spare areas, the device is assumed one cycle every two days each year:

(1,000 cycles 365 days) * 2 spare areas = 5.48 years

With these parameters, the period of time prior to cycling the flash to its lifetime has just been increased to almost 5 1/2 years!

This simple example shows how distributing a fixed set of writes across more flash sectors can increase the period of time prior to cycling the flash to its specified limits. The following sections describe how to account for the important variables associated with wear-leveling techniques, and determine the expected lifetime of the flash in any application.

With and Without - A Huge Difference
Figures 1 and 2 below depict the concept of wear leveling. The flash disk in this example has a maximum endurance of 100,000 cycles. Figure 1 represents a disk that does not employ any wear leveling software, while Figure 2 shows a disk that is managed with wear leveling schemes. Note that the sectors that have exceeded the 100,000 cycles in Figure 1 are no longer able to store data, and have corrupted the data that they were storing. These sectors represent the high-use areas of the disk; on a FAT disk, for example, this may be where the FAT table is stored.

Lower use areas of the disk, which may include application and operating system code, will never reach the flash memory’s maximum endurance. Without wear leveling, these low-use sectors are essentially wasted flash lifetime. Meanwhile, the disk use in Figure 2 is spread evenly throughout the disk sectors, allowing the flash disk to be reliable for its maximum lifetime.


Disk File Mechanisms and Wear Leveling

FlashFX Pro, an intelligent flash driver and flash manager from Datalight, moves data around in the flash disk to accommodate the fact that flash memory cannot simply be rewritten. The specific algorithms are beyond the scope of this paper, but we can reasonably assume that FlashFX Pro will attempt to efficiently write throughout the flash before rewriting the same location. Many basic file systems have a primitive form of wear leveling.

The wear-leveling scheme implemented by FlashFX Pro consists of tracking the number of erases incurred on each flash erase block. In other words, the software monitors the high use areas (many erases) and low-use areas (few erases) of the flash; this is often referred to as dynamic wear-leveling. As erases accumulate, the difference between the highest and lowest counts is audited. If a specific set of constraints are met, a wear-leveling operation - which swaps the least erased block with the most recently used erase block is completed.

Two parameters control wear-leveling erases; the first is a maximum difference allowed before wear-leveling erases are incurred, and the second limits the frequency of wear-leveling erases. Again, considering the necessity to maintain optimal read/write performance in the flash, FlashFX Pro will never incur wear-leveling erases if they are not necessary. It will effectively move high-use areas of the flash to low-use areas over time and will keep the average erase cycle count within a predefined range. It is important to note that this system utilizes the entire flash disk by forcing static areas of the flash to move which would otherwise never be rewritten fully.

In order to ensure that the wear-leveling process will not degrade performance or compromise the integrity of fixed file system meta-data, the software begins erases well before the cumulative writes equals the size of the flash disk.

Simplistic Flash Cycles Calculation
In order to determine if a certain application will challenge the endurance cycles of the flash that are specified by the flash manufacturer, a number of variables must be considered. Assume the flash is used efficiently by the application and that all flash described by Stotal is available to be written prior to an erase cycle being incurred. Given this assumption, a single erase cycle will be incurred once the entire flash (Stotal) is written. The period of time elapsed over a given cycle count, and therefore the period of time before a flash chip wears out, is then calculated with the following formula:

P = C [Stotal ( F * Dwrite) ]
Stotal describes the total flash memory available (KB) to be used as a disk.
Dwrite describes the amount of data (KB) being regularly written into the disk.
F is the frequency of Dwrite to the disk per day.
C is a given number of cycles to calculate the period.

Example 1: Field Data Recorder (1 MB disk)
Table 1 shows an example of a field data recorder that collects and stores coordinates and other statistics at a rate of 1280 bytes per minute, and must maintain the last hour of data (75 KB), for a total of 1800 KB of writes per day. Although the entire flash size may be 1 MB or more, only 256 KB can be used to store data. The remaining space must store code and application data. The data requires one flash erase block (128 KB:remember we cannot erase just 75 KB); we will have the application swap between two flash erase blocks.

  • Stotal = 256 KB
  • Dwrite = 1800 KB
  • F = 1 day

If the field data recorder has a lifetime of 2 to 3 years and the flash management software implements efficient wear leveling, the data in Table 1 is assumed. If the flash memory’s endurance was limited to 1,000 cycles, we have a good cause to worry that the product’s lifetime is limited by the choice in flash memory. A flash endurance with 10,000 cycles might also be problematic, but with 100,000 cycles, the flash is expected to reasonably outlive our product. Fortunately, there are many flash memories on the market today with such an endurance capability.

Example 2: Field Data Recorder (1 MB disk)
Suppose the entire 1MB flash chip is managed by a flash file system such as FlashFX Pro. In the previous example, our application was placed into the other 768 KB of the flash chip, but now it can be placed into the FlashFX Pro disk along with the data that is being recorded. If FlashFX Pro did not employ any wear-leveling, the results of the endurance calculations would not differ. Since the flash management software periodically moves the two erase blocks that store data, the entire 1MB can be utilized. Table 2 shows the much improved situation.

  • Stotal = 1024 KB
  • Dwrite = 1800 KB
  • F = 1 day

In this example, the choice of flash memories now includes those rated for 10,000 cycles or greater.



Thom Denhom, Technical Product Manager, Datalight
Thom is an embedded software engineer with over 20 years experience, combining a strong focus on operating system and file system internals with a knowledge of modern flash devices. He has a degree in Mathematics and Computer Science from Gonzaga University.