a comprehensive comparison of Cramfs, JFFS2 and YAFFS2 http://blog.csdn.net/daofengdeba/article/details/7721340
because of the special requirements of the embedded system itself, some traditional file systems (such as FAT, EXT2, etc.) are not very suitable. The special embedded file system should have some characteristics, such as the particularity of the storage media, the security of the cross-platform, and the immediacy of the whole system. This paper introduces 3 kinds of open-source Embedded file system Cramfs, JFFS2, YAFFS2, analyzes and compares the main performance of these 3 file systems in detail, and points out their applicable fields according to the analysis results.
Cramfs, JFFS2, YAFFS2 are 3 kinds of superior performance, dedicated to embedded system file system. Based on the analysis and comparison of the design principle and main performance of these 3 file systems, this paper summarizes the basis and applicable fields of their selection.analysis and comparison of the main performance of three embedded file systemsData security, operating speed, occupation of resources, scope of use are the main performance indicators of embedded file system. The following from these aspects, the three kinds of embedded file system analysis and comparison.Data SecurityThe current embedded system mainly uses solid-state flash wafer as storage device. Because of the characteristics of the flash device and the complex diversity of the working environment of the embedded system, how to ensure the security of the data is the first problem to be considered in the embedded file system. Data security mainly includes data redundancy and power-down protection and other parts.
Data Redundancy
Cramfs File system is a read-only file system, the file system content can not be changed, the design of the idea to follow the "only store the least information"; even if there is no time stamp and other information, in addition to the data packet CRC check information, there is little data redundancy.
JFFS2 File system is a typical log structure of the file system, it stores information is log-type information. JFFS2 on Flash?? There are only two types of data entities: J.ffs2_raw_inode and Jffs2_raw dirent. The former contains administrative information about the file , which is used to describe the location of the file in the file system . The real information is kept behind the Jffs2_raw_inode node, and most of the information that is managed is built after the system is mounted. Two data entities have a common file header structure JFFS2 _ Unknown_node. In this structure, there is a jint32 _t type of HDR_CRC variable, which represents the CRC checksum value of the other domains in the file header. This indicates that the JFFS2 file system uses a CRC cyclic redundancy check code. [File management information + file location in file system + Real data]
The YAFFS2 file system is a class-log file system dedicated to NAND flash devices . The basic unit of its storage data is chunk, the equivalent of a Flash page. The data in the chunk includes two parts: a data area, a page that occupies a flash, and a file information and redundant data area that occupies the OOB area of the Flash page. Its redundant data is mainly ECC calibration data, for small pages (512 bits per page) of Flash, each page has 6-bit ECC data; for large pages (2048-bit per page) of Flash, each page has a 24-bit set of ECC data. [Dedicated to NAND, real data placed on flash pages, file information and redundancy data placed in the OOB area of the Flash page]
Power-down Protection:
The Cramfs file system extracts the file system contents into memory, because it cannot be written, the contents of the file system cannot be changed, so there is no problem of power-down protection. [ no power-down protection ]JFFS2 is a log structure file system, so JFFS2 maintains data integrity regardless of the mode at which time the power supply stops powering.
When the system is restarted after an abnormal power outage, the JFFS2 automatically restores the system to the last stable state before the power outage. It is important to note that any changes that occur after the file system is in the last stable state cannot be restored. [Restore to the previous stable state after power-off reboot]
YAFFS2 is a class log file system that automatically provides reliable data logging after an accidental power-down restart to prevent file system crashes. It uses stand-alone log files to track changes in file system content. For example, when an application needs to write a page of Flash, it first modifies a piece of image that is stored in the file log, and the data is actually written to that page only if the image in the log is copied to the file system.
In the event of an unexpected power-down restart, YAFFS2 did not use the old file completely in place of the new write file, as in JFFS2, but instead chose to replace the old file with a new file, or write some of the new file with the old file. This approach enhances the security performance of files that are not fully written when power-down, especially when accidental power-down occurs in the data area, and the files that are accidentally dropped are preserved almost completely. [After power-off restart, use new to replace the old]
Operating Speed
The operating speed can be examined from the following aspects: File system mount speed, read file speed, write file speed and so on. The preset storage media here is NAND Flash. In general, a compressed, read-only file system needs to extract the file system into the SDRAM when it is started, which in some way slows down the file system mount speed. However, the Cramfs file system in the design of the system to take full account of the time, and did not once all the contents of the file system into memory, but only when the system needs to access a location of data, quickly calculate the location of the data in the CRAMFS, unzip it into memory, And then perform the access operation. Because its read file speed is only to find the file address and access to memory operations,
So whether it's mount speed or read file speed, the Cramfs file system is faster than the JFFS2 and YAFFS2 file systems.
The mount of the JFFS2 file system can be divided into the following steps:
1. Check the legality of each node CRC verification code, in memory for each node to allocate the necessary relevant structure;
2. Scan the physical node list of each I node to establish a link;
3. Release the temporary information used during the scan. It can be seen that the process is still very complex and, more importantly,
It takes a lot of time to scan the entire flash storage area when the JFFS2 file system is mounted, so the JFFS2 file system is very slow to boot. Compared to JFFS2, YAFFS2 reduces some features, and only scans the idle area of flash memory when mounted .According to the Yaffs_tags information read from the OOB (backup data area) is the file header page or the data page, and then according to the corresponding information in the memory for each file set up a pair?? The Yaffs_object object to be applied to.
since the YAFFS2 can only scan the OOB area of each page when the system is loaded, the whole file system will be built up without the need to scan the entire flash device like JFFS2, thus greatly speeding up the file system startup speed. However, YAFFS2 still requires a scan of all pages of the entire flash device, which causes the system scan time to go straight up when the storage space of the flash device becomes larger.
when the file system is running, JFFS2 needs to maintain several linked lists to manage the erase block. Depending on the content on the erase block, a erase block may be on a different list. Specifically, when a erase block is a legitimate (valid) node, it will be on the clean_list, and when a erase block contains at least one obsolete (obsolete) node, it will be on dirty_list; When a erase block is erased, and is written to the Cleanmarker node, it will be on the free_list.
based on these linked lists, JFFS2 file system can achieve garbage collection, loss balancing and other performance. When a file system is mounted, YAFFS2 creates a hierarchical index in memory that can be viewed as a tree of files. The bottom of the tree points to the page where the file is actually stored, and the top level is the index directory of the layer. The file tree is implemented through a node of a federated structure. The Union structure is a fixed size (32-bit tuple), and when it is at the bottom, it is searched by 16 2-bit tuple portals to find the page ID, and 8 4-bit pointers point to other lower-level nodes when in other layers. Each file corresponds to a file tree for easy retrieval.
In the embedded system with NAND flash as storage medium, YAFFS2 's file read and write performance is better than JFFS2. [YAFFS2 than JFFS2 startup speed, read-write performance is also more excellent]
Occupy ResourcesIn embedded systems, memory and external memory resources are scarce and need to be used sparingly. Therefore, the amount of memory and external memory resources used is also an important index to measure the embedded file system.
If you use RAMDisk to run the file system, then after the system runs, the first thing to do is flash on?? Image file into memory before you can start running the program. In this way, the same code not only occupies space in the external memory, but also takes up more space in memory because of decompression.
CramfsAlthough it is a compressed file system, it has been described earlier,
It doesn't need to extract all the content into memory at once. Because of its compression of the contents of the file, both external memory and memory, Cramfs consumes less resources than JFFS2 and YAFFS2.
JFFS2The file system data and the original data in the form of nodes stored in Flash??, its redundant data is only the CRC check code of the node head, and
compression of the node data at the time of storage。 Compared with the
YAFFS2It not only stores the ECC check code of the page data, but also stores the page node information without the Flash device OOB area storage data. The image is made up of several pages without compressing the data, so
the YAFFS2 file system image greatly exceeds the JFFS2 file system image. Experiments show that the size of the normal YAFFS2 image is about twice times the size of the same JFFS2 image. When the file system is running in memory, JFFS2 defines several linked lists in memory, and YAFFS2 creates a file tree for each file in memory.
Although it takes a lot of memory to build a file tree for each file, it is less than the memory that is consumed by the list of JFFS2 needed to maintain it. In actual operation, YAFFS2 occupies less memory than the JFFS2 file system. [JFFS2 compresses the node's data when it is stored, the system image is larger than YAFFS2, but the linked list maintained by the runtime JFFS2 more memory than the yaffs tree ]Scope of Use
to use the Cramfs or JFFS2 file system, it is not necessary to support the MTD driver layer. MTD (Memory technology device) is a common interface layer for storage devices in Linux. Although it can also be built on RAM, it is designed for flash-based devices. MTD contains a specific flash chip driver, Flash chip driver to provide read, write, erase and other basic flash operation methods. MTD provides a device for the user layer to provide MTD char and MTD block types after encapsulation of these operations. The MTD char type device includes/DEV/MTD0, which can be accessed by the original characters of the Flash, the MTD block type device includes the/dev/mtdblock0, etc., the flash analogy into a block device, This allows you to create file systems such as Cramfs or JFFS2 on these block devices.
in the interface to the user layer, the Cramfs or JFFS2 file system also requires the support of the operating system VFS (virtual file system). Same
YAFFS2 file system support using MTD drive?? and VFS layer, which is commonly used in embedded Linux or Clinux operating systems using YAFFS2 file systems. In addition, the YAFFS2 also features NAND flash chip drivers and provides an embedded system with direct access to the file system API, which allows users to directly manipulate the files without using MTD and VFS in Linux. [Cramfs and Jffs use MTD and VFS support, and YAFFS2 is not available, but is usually used in Linux]
Figure 1File system architecture for embedded systems. YAFFS2 Direct in AFFS2 provides a straightforward file system interface, so YAFFS2 can be used in embedded systems that do not have a VFS layer. The YAFFS2 file system is more widely used than the CRAMFS and JFFS2 file systems, but it is important to note that YAFFS2 can only be used on NAND flash storage devices.ConclusionThese 3 kinds of embedded file systems are widely used in embedded systems, but they have their own characteristics.
Table 2The main performance of 3 kinds of file systems is compared, and the most applicable fields are summed up.
The areas that are most applicable to eachThe specific analysis is as follows:
1.
CramfsIs the earliest embedded file system, it only stores the least information, the content of the file is compressed, running speed comparison
Fast. However, because it cannot be written, it does not support files that are more than MB in size, so
widely used in small storage space, file system content
embedded systems that are less and do not require user writes.
2.
JFFS2is an earlier flash dedicated file system. There are many examples of JFFS2 used in Clinux and embedded Linux. Thing
In fact, it has become a standard file system in the new version of Linux.
While
it provides support for nor flash and NAND flash, providing power-down protection and loss balancing for the common features of two flash devices
function, which can be read and written by users, is suitable for both flash devices and embedded systems.
3.
YAFFS2 is a file system designed for NAND flash, which takes into account the characteristics of NAND flash devices, supports ECC calibration,
power-down protection and loss balancing function, running and mounting speed is faster than JFFS2. It supports a wide range of operating systems, including common embedded
Linux, WinCE, Clinux.
because it provides a direct interface, a slight modification can also be used in an embedded system without a job
the system. Currently, it is widely used in embedded systems that use NAND flash as a storage device. According to the specific application, we can choose a file system solution which is more suitable for the system based on the investigation of various file system features. Like what
in many applications with NAND flash as storage medium, "cramfs yaffs2" file system is used. With Cramfs as the root file system, it can improve the startup speed and protect the root files from being destroyed, and using YAFFS2 as the user file system can improve the security and speed of file system, and it is an excellent embedded file system solution.
A comprehensive comparison of Cramfs, JFFS2 and YAFFS2