Kowning YAFFS

来源:互联网 发布:主流编程语言对比 编辑:程序博客网 时间:2024/06/06 10:01

 

YAFFS (Yet Another Flash File System)

 

YAFFS1: A first version file system work on NAND chips that have 512 bytes pages + 16 byte spare areas.
The advantage is that dirty pages are marked by writting to a special spare area byte. Newer NAND flash chips have larger page, 2048 bytes + 64 bytes spare areas, each page within a block must be written in sequential order and each page must be written only once. YAFFS is a robust log-structured file syetem that holds data integrity as high priority and high performance. It is designed for Linux, WinCE, oSOS, eCos, ThreadX and various special-purpose OSes. It follows mark 5th byte of spare area of each block as bad block status flag. (0xFF 可用, 反之为坏)

 

To write file data, YAFFS initially writes a whole page (chunk in YAFFS) that describes the file timestamps, name, path, etc. The new file is assigned a unique Object ID, every data chunk within the file will contain this unique ID within the spare area. (for example, supposed 1 page = 512 bytes + 16 bytes, then the unique Object ID is record in that 16 bytes).

 

garbage collection -

YAFFS maintains a tree structure in memory of the physical location of chip. When a chunk is no longer valid (the file was delete or the file was overwritten), YAFFS marks a particular byte in the spare area of the chunk as 'dirty'.

When an entire block (32 pages) is marked as dirty, YAFFS can erase the block and reclaim the space. If the free space on the device is low, YAFFS may need to choose a block that has some number of dirty pages and some number of good pages, move the good pages to a new block, mark the old pages as dirty and erase the block.

 

YAFFS2:

To support 2K bytes + 64 bytes as a chunk and the YAFFS2 code base supports of YAFFS1 data formats through backward compatibility. The main difference is that YAFFS2 needs to jump through significant hoops to meet 'write once' requirement of modern NAND flash. It provide the following benefits,

 

1. zero page rewrites means faster operation (write:1.5x, delete: 4x, garbage collection: 2x) and add chip valid life.

2. lower RAM footpoint (approx 25% to 50% of YAFFS1)

3. can support Toshiba/Sandisk MLC parts.

 

YAFFS2 chunks have more tag information, including a block sequence id, from that we can determine the chunk sequence id since the chunks are allocated sequentially in a block. Thus we always know the patch order fir all chunks in the system.

 

Deletion is achieved by moving the object to the "unlink" directory. We also keep the track of the number of chunks in system for each object. While this number indicates that there are still chunks associated with this object we keep the deletion record. When the last trace of the object has been really erased from NAND, we can forget about the deletion record too.

 

Tag structure:

 

 

 

 

 

Flash File System Evaluation:

 

 

mount time: time mount -t <filesystem> /dev/mtdblock0 <target-dir>

 

write time: time tar xf <some-tar-compressed-file> with 81MB size and extract out 1865 files.

 

read time: time du -shc <target-dir>