Trueffs Principle
ReferenceTrueffs principle and its implementation on the CF card
"1. Wear-Leveling
Flash memory cannot be reused infinitely. Although each slice has a large number of erases, It is limited. Therefore, as the number of erases increases, it will eventually become read-only, so it should be extended as much as possible. An effective method is to balance the use of all storage units, rather than over-using a certain unit. This technology is called loss balancing. Trueffs uses a block ing Translation System Based on a dynamically maintained table storage to balance the loss. After the block data is modified, moved, or recycled, the maintenance table is automatically adjusted. However, if some data stored in Flash is static in nature, static file locking will occur. The region where the static data is stored will not be used cyclically, and other regions will be used more frequently, which will reduce the expected live value of flash. Trueffs successfully overcomes the static file lock problem by forcibly transferring the static area. Because the ing table is dynamic, trueffs can transfer these static data regions in an invisible way to the file system. Since the absolute forced loss balancing method has some negative impact on performance, trueffs adopts a non-absolute loss balancing algorithm. It ensures that the use of all spaces is almost equal without affecting
Yes.
2. Debris recovery
The modification of block data makes the data in some block areas of flash no longer valid, and these areas become unwritable before being erased. If there is no mechanism to recycle these regions, flash will soon become read-only. Unfortunately, because these blocks cannot be erased separately, it is complicated to recycle them. A single erasure is limited to a large range called an erasure unit, for example, 64 kB for AMD's am29lv065d chip. Trueffs uses a mechanism called fragment to reclaim blocks that no longer contain valid data. This mechanism replicates all valid data blocks from one pre-erased unit to another new erased unit called a transfer unit. Then, trueffs updates the ing table and erases the used pre-erased unit. In this way, the original block still contains the original data when it appears, although the data is now stored in other spaces of flash memory.
The fragment retrieval algorithm will find and reclaim the erasure unit that best matches the following criteria:
① Most waste blocks;
② The minimum number of erases;
③ The most static region.
Three data blocks for allocation and associated data aggregation
To improve data reading efficiency, trueffs uses a flexible space allocation policy: Associate data (such as multiple blocks composed of the content of the same file) aggregate to a continuous area in the same independently erased unit. Therefore, trueffs tries to maintain a storage pool consisting of multiple physical Continuous Free blocks in the same erasure unit. If this continuous storage pool cannot be implemented, try to ensure that all the blocks in the pool are in the same erased unit. If this is not the case, trueffs tries to divide the block pool
Allocated to an erased unit with the maximum available space. There are several advantages for this way to aggregate and associate data. First, if trueffs must access flash from a small storage window, then the associated data will reduce the number of calls to map physical blocks to the window, this accelerates file access. Second, this policy can reduce the generation of fragments. This is because deleting a file can release the complete block that is easier to recycle, which means that the fragment collection will become faster. In addition, it can store multiple blocks of static files in the same address. This makes it easier to transfer these blocks when the loss algorithm determines the moving of static areas.
4 power failure management
Writing data to flash may sometimes cause errors, such as when the file system responds to write requests, fragment collection, and even when the trueffs format or erase flash. In these cases, trueffs can be recovered from the error, but it will be lost if an error occurs when the new data is written to flash for the first time. However, trueffs carefully ensures that all the data that has been stored in Flash is recoverable, and even avoids the catastrophic consequences that users may have when suddenly pulling out the flash card due to impatience or curiosity.
Trueffs algorithms based on "erase after write" instead of "erase before write" the key to robustness is that it uses a "write first and then erase" policy. When updating the number of Flash sectors
Data can be erased only after the update operation is completed and the data in the new storage is verified successfully. The result is that the data sector cannot be partially written. If the operation is successful, the data of the new sector is valid; otherwise, the data of the old sector is valid. Obviously, this is conducive to the stability of data that has been written to flash"
Here, I think of the isd5116 used by the Programming program. At that time, I also considered the frequency of use. I did an absolute balance. However, I feel the same with this article.
CF card is a storage medium with large capacity and convenient carrying Based on Flash technology. It has been widely used in embedded systems and other fields. However, the limited number of writes greatly limits the service life of the CF card. Trueffs uses a series of algorithms to prolong the service life of the CF card and improve the efficiency of the CF card. This article introduces the principle of trueffs, implements trueffs on the CF card, and analyzes the performance of trueffs.
Keywords:Trueffs loss balanced flash memory CF card
One of the biggest disadvantages of flash memory is its limited service life. The number of Erasable chip manufacturers varies, generally between 10 thousand and ~ About 0.1 million times. To extend the life of flash memory and improve efficiency, msystems has launched a trueffs system. It provides unified block device interfaces for a wide range of flash memory, and features reentrant and thread security. It supports most popular CPU architectures, such as PowerPC, MIPS, arm, x86, and 68k.
As the distinctive flash memory is increasingly favored by Embedded System Engineers, the popular embedded real-time operating system VxWorks has used trueffs as a customizable module. The current version of this module is 2.0. It supports flash memory and flash cards of most models produced by companies such as Intel, AMD, toshba, and Fujitsu. Users only need to change a small amount of code or even directly call flash cards; however, this module lacks support for today's popular CF cards.
The CF card uses Flash technology. The CF card is composed of several flash memory and a manager. However, the CF card has the advantages of convenient carrying, easy upgrade, large storage capacity, good earthquake resistance, and good compatibility. At present, the CF card standard has reached version 1.4, with the capacity from the earliest 2 MB to the current 1 GB. However, the limited number of erase flashes is the inherent defect that flash memory inherits from the CF card. This article describes how to implement the trueffs System on CF. The hardware platform uses the PowerPC processor (MPC8250, Motorola) as the CPU, and the embedded operating system is VxWorks.
1 trueffs Structure
Trueffs itself is not a file system. It can be used only by loading the DOS file system on trueffs. Otherwise, it is meaningless. Trueffs shields the differences between lower-layer storage media and provides developers with a unified interface. Applications perform read and write operations on storage devices just like those on disk devices with DOS file systems.
As shown in figure 1, trueffs consists of one core layer and three functional layers: the compilation layer, MTD layer (memorypolicilogy driver), and socket layer.
The Translation Layer provides advanced interaction between trueffs and DOS file systems, manages the relationships between file systems and physical erasable blocks in flash, and provides various Intelligent Processing functions in trueffs, such as block ing and wear-leveling. There are currently three different Translation Layer modules available. Which of the following modules should be determined based on the use of nor, Nand, or ssfdc in Flash Media.
The MTD layer implements read, write, erase, ID identification, ing and other drivers for specific flash, and sets parameters related to the Flash password. The trueffs of VxWorks already includes MTD layer drivers that support most flash chips from Intel, AMD, toshba, and other vendors. The new device requires a new MTD layer driver.
The socket layer provides interface services between trueffs and hardware, and is responsible for power management, device plugging, hardware write protection, window management, and socket registration to the system.
The core layer combines the other three layers to handle global problems, such as information, timers, fragment collection, and other system resources.
We are most concerned with the MTD layer and socket layer. VxWorks only provides the compiled binary core layer and Translation Layer drivers. The principles of trueffs are introduced before implementing trueffs applications.
2. trueffs Principle
2.1
Loss balancing
Flash memory cannot be reused infinitely. Although each slice has a large number of erases, It is limited. Therefore, as the number of erases increases, it will eventually become read-only, so it should be extended as much as possible. An effective method is to balance the use of all storage units, rather than over-using a certain unit. This technology is called loss balancing. Trueffs uses a block ing Translation System Based on a dynamically maintained table storage to balance the loss. After the block data is modified, moved, or recycled, the maintenance table is automatically adjusted.
However, if some data stored in Flash is static in nature, static file locking will occur. The region where the static data is stored will not be used cyclically, and other regions will be used more frequently, which will reduce the expected live value of flash. Trueffs successfully overcomes the static file lock problem by forcibly transferring the static area. Because the ing table is dynamic, trueffs can transfer these static data regions in an invisible way to the file system. Since the absolute forced loss balancing method has some negative impact on performance, trueffs adopts a non-absolute loss balancing algorithm. It ensures that the use of all spaces is almost equal without affecting performance.
2.2
Fragment recovery
The modification of block data makes the data in some block areas of flash no longer valid, and these areas become unwritable before being erased. If there is no mechanism to recycle these regions, flash will soon become read-only. Unfortunately, because these blocks cannot be erased separately, it is complicated to recycle them. A single erasure is limited to a large range called an erasure unit, for example, 64 kB for AMD's am29lv065d chip.
Trueffs uses a mechanism called fragment to reclaim blocks that no longer contain valid data. This mechanism replicates all valid data blocks from one pre-erased unit to another new erased unit called a transfer unit. Then, trueffs updates the ing table and erases the used pre-erased unit. In this way, the original block still contains the original data when it appears, although the data is now stored in other spaces of flash memory.
The fragment retrieval algorithm will find and reclaim the erasure unit that best matches the following criteria:
① Most waste blocks;
② The minimum number of erases;
③ The most static region.
2.3
Block allocation and associated data aggregation
To improve data reading efficiency, trueffs uses a flexible space allocation policy: Associate data (such as multiple blocks composed of the content of the same file) aggregate to a continuous area in the same independently erased unit. Therefore, trueffs tries to maintain a storage pool consisting of multiple physical Continuous Free blocks in the same erasure unit. If this continuous storage pool cannot be implemented, try to ensure that all the blocks in the pool are in the same erased unit. If this is not the case, trueffs tries its best to allocate the block pool to an erased unit with the maximum available space.
There are several advantages for this way to aggregate and associate data. First, if trueffs must access flash from a small storage window, then the associated data will reduce the number of calls to map physical blocks to the window, this accelerates file access. Second, this policy can reduce the generation of fragments. This is because deleting a file can release the complete block that is easier to recycle, which means that the fragment collection will become faster. In addition, it can store multiple blocks of static files in the same address. This makes it easier to transfer these blocks when the loss algorithm determines the moving of static areas.
2.4
Error Recovery
Writing data to flash may sometimes cause errors, such as when the file system responds to write requests, fragment collection, and even when the trueffs format or erase flash. In these cases, trueffs can be recovered from the error, but it will be lost if an error occurs when the new data is written to flash for the first time. However, trueffs carefully ensures that all the data that has been stored in Flash is recoverable, and even avoids the catastrophic consequences that users may have when suddenly pulling out the flash card due to impatience or curiosity.
The key to trueffs's robustness is that it uses a "write first and then erase" policy. When updating data in one sector of flash, the previous data can be erased only after the update operation is completed and the new data is verified successfully. The result is that the data sector cannot be partially written. If the operation is successful, the data of the new sector is valid; otherwise, the data of the old sector is valid. Obviously, this is conducive to the stability of data that has been written to flash.
3 Programming
Trueffs programming mainly lies in the MTD layer and socket layer. First, you must define include_tffs (including the trueffs system) and include_tffs_show (including the display function of the trueffs system) in the configuration file (config. h) of the generated directory of the current VxWorks System ).
3.1
Translation Layer
The Translation Layer is selected based on the flash implementation technology. The design selects a cfcard of sst49cf064 type of SST, with a capacity of 64 MB. It is based on the Flash technology of NAND, so the file defines include_tl_nftl; if it is the nor technology, it defines include_tl_ftl.
3.2mtd Layer
The cfcardmtd. c file implements the MTD layer function. In this design, the MTD layer mainly implements four functions: read, write, erase, and Id recognition.
The ID recognition function selects the MTD driver that matches the current device based on the Read Device ID. The identification function specifies some parameters and basic operation functions for the current device, and assigns a data structure called flflash.
Flstatus cfmtdidentify (flflash * pvol );
The main parameter values in the data structure are as follows:
Pvol-> type = cf_id;/* device ID */
Pvol-> erasableblocksize = 512;/* The minimum erasable unit is 512b */
Pvol-> chipsize = 0x4000000;/* The device capacity is 64 MB */
Pvol-write = cfwriteroutine;/* write function *