<h1>Flash file systems&nbsp;</h1>

<h2>Background &amp; basics</h2>

<h3>What is a flash file system?</h3>

<p>A Flash File System stores data on flash chips, rather than a hard drive. Flash memory is used because it’s faster, much more tolerant of physical stress and takes less power. A flash filesystem is used to manage the data and get the best out of flash memory. For example, it will often include wear levelling in order to maximize the working lifetime of the file system because Flash chips have a limited number of Erase and Write cycles in their life.</p>

<p>A flash file system is most useful as a part of an embedded system, tied to hardware. As a developer, you &gt;can&lt; read from and write directly to your Flash memory on an embedded system, but unless your use is extremely limited, you'll probably find that you come up against problems that Flash file systems have already solved.</p>

<h3>What are NAND Flash &amp; NOR Flash?</h3>

<p>These are the two fundamental Flash architectures and have very different characteristics in performance, reliability, erase cycles, life span, and price. They also differ fundamentally from hard disk drives, and so need specialised treatment.</p>

<table>
	<tbody>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>NAND flash</p>
			</td>
			<td>
			<p>NOR flash</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Storage density</p>
			</td>
			<td>
			<p>Higher</p>
			</td>
			<td>
			<p>Lower</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Read performamce</p>
			</td>
			<td>
			<p>Fast</p>
			</td>
			<td>
			<p>Fast (may be slowed by serial access)</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Write performance</p>
			</td>
			<td>
			<p>Faster</p>
			</td>
			<td>
			<p>Slower (may be slowed further by serial access)</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Erase performance</p>
			</td>
			<td>
			<p>Faster (low ms typically)</p>
			</td>
			<td>
			<p>Slower (possibly seconds)</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Storage reliability</p>
			</td>
			<td>
			<p>Lower (without management)</p>
			</td>
			<td>
			<p>Better</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Life span</p>
			</td>
			<td>
			<p>Higher</p>
			</td>
			<td>
			<p>Lower</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Price</p>
			</td>
			<td>
			<p>Lower</p>
			</td>
			<td>
			<p>Higher</p>
			</td>
		</tr>
	</tbody>
</table>

<p>Yaffs is both an embedded NAND flash file system and an embedded NOR Flash file system. It can handle SLC, TLC and MLC NAND. It also works on MLC and SLC NOR. And it can work with parallel or serial access including Serial Peripheral Bus (SPI).</p>

<h3>What special functions does a file system for flash include?</h3>

<p>As well as the normal file system functions, a flash file system embedded in hardware should help the device to switch on and off quickly; deal well with losing power with no warning, without corrupting the data; and, manage the foibles of flash memory, protecting the stored data with extreme reliability.</p>

<p>To these ends, an embedded flash file system may : use log structuring, rather than traditional file structuring plus a flash translation layer; manage power loss and recovery; include flash memory wear levelling; deal with the unreliability of flash from read and write disturbs, by using error correction (ECC), bad block remapping, over provision and flash block refreshing; ensure it’s ready to write fast by using garbage collection and flash block erase to prepare; and manage writing while avoiding write amplification.</p>

<h4>What is a log-structured file system?</h4>

<p>Log structuring means that data is written to the file system as it is received as a set of changes to the file system. This has the advantage that there is less overhead, and so it's faster than a non-log-structured system which is important when a device may be turned off at any moment. It also means that a file may be fragmented. For hard drives, fragmentation can mean much slower access, but Flash memory is thousands of times faster than hard drives as well as writing more rapidly. So a log structure is a simple flash file system when compared to a block structured flash file system.</p>

<p>Yaffs is log structured because this flash files system architecture is faster and more robust than the alternatives.</p>

<h4>What is a Flash Translation Layer (FTL) ?</h4>

<p>When Flash memory is used in an SSD, for instance, it’s sometimes useful to mimics the interface to hard drives. A Flash Translation Layer presents flash memory or a flash file system as if it's an ordinary hard drive.</p>

<p>An FTL is an incomplete storage solution it still requires a file system. This makes two layers where data can be damaged and lost: in the FTL and in the flash memory file system.</p>

<p>Yaffs is not a FTL, but one can be put in front of it.</p>

<p>True file systems for flash memory, such as Yaffs, do not use FTLs. They deal directly with the idiosyncrasies of flash, providing a better solution.</p>

<h4>What is power loss recovery?</h4>

<p>When power to any storage device is suddenly lost, the device can end up in an unknown state and may have damaged areas. Most file systems have to work hard to ensure that they are in a consistent state after power loss. Embedded file systems for flash may make allowances for unscheduled power loss with a recovery process.</p>

<p>Yaffs is built with fault tolerance as a guiding principle and so is designed so power loss is considered a normal event.</p>

<h4>What is wear levelling?</h4>

<p>Flash chips wear out. Each time a part of the Flash memory is erased and written, it is slightly damaged. Embedded flash file systems note the danger, and sometimes try to spread the damage rather than having it concentrated in one region, so prolonging the life of the memory and the life of the device.</p>

<p>Yaffs is designed so that special wear levelling is unnecessary. Instead, it’s automatically wear levelling because of the log structure,.</p>

<h4>What is Flash read disturb? What is Flash write disturb?</h4>

<p>MLC NAND chips may experience degradation or loss of data owing to reads or data changes in neighbouring blocks of the chip.</p>

<p>Our paper on Flash memory covers this in detail. XXXXX</p>

<p>Yaffs uses block refreshing to deal with such problems.</p>

<h4>What is Flash error correction/Flash ECC?</h4>

<p>Like any memory medium there are ways in which Flash memory can be corrupted – for instance F-N tunneling problems and leaky oxide layers. See detailed discussion at <a href="http://www.yaffs.net/documents/yaffs-nand-flash-failure-mitigation">http://www.yaffs.net/documents/yaffs-nand-flash-failure-mitigation</a>.</p>

<p>But every bit counts, and especially if it's a bit that's part of critical data or essential to the correct working of a system. Flash error correction keeps track of a section of memory to tell if there's corruption, and provides ways to correct these small errors.</p>

<p>Yaffs can use hardware or software based ECC.</p>

<h3>What is bad-block remapping?</h3>

<p>File systems are built upon storing data on physical media. But all media suffers deterioration. Some hardware or flash media file systems keep lists of damaged regions and behind the scenes, substitute known good ones in their place.</p>

<p>Because of the way that Yaffs works, there's no need for bad block remapping because it isn’t a block structured file system.</p>

<h4>What is over-provisioning ?</h4>

<p>Knowing that the media will degrade and suffer errors, and needing space to alter data because of the nature of flash memory, sometimes a flash memory based file system puts aside a portion of the media for this use. This is overprovisioning. Often this space used when remapping bad blocks.</p>

<p>Because Yaffs is log structured, it has the advantage that it does not need over-provisioning, making more memory available to store data.</p>

<h3>What is flash block refreshing?</h3>

<p>To counteract the problems of unreliable flash memory – for instance errors due to read and write disturbs – a flash filesystem can refresh the memory, by making a new copy of a block.</p>

<p>Yaffs includes flash block refreshing.</p>

<h4>What is Flash garbage collection?</h4>

<p>When a file is deleted, file systems often simply mark the file as deleted, rather than removing it. Later they reclaim the space for reuse. This is garbage collection.</p>

<p>Yaffs has garbage collection to maximise the amount of data the file system can store and to increase read speeds.</p>

<h4>What is flash block erase?</h4>

<p>Data must be written into blank areas of the flash chip, but erasing takes time. Rather than erase and write at the same time, in order to speed writes, NAND and NOR flash file systems can prepare blocks for later use. This is not usually necessary for other storage media.</p>

<p>As part of garbage collection, Yaffs uses a block erase strategy.</p>

<h4>What is flash Write amplification ?</h4>

<p>In many block-based flash file systems, when data changes the new data must be written to the disk, and then the old data must be marked as invalid. A small change early in the process can have consequences that propagate involving writing to the memory twice or more as the old data is cleaned up by garbage collection and files are organised to take the minimum amount of space. This is write amplification - a single small write causing a cascade of writes (and erases).</p>

<p>Yaffs avoids much of this problem by being log structured, meaning that Flash memory is slower to reach it's maximum number of cycles, while writing is faster.</p>

<h2>How does Yaffs work</h2>

<p>You can find full details in our xxxxxxxx but briefly, here's how it works.</p>

<p>It's a log-structured filing system. This also ensures that Yaffs is wear-levelling is built into the design because no one part of the Flash memory is used any more than another.</p>

<p>A Yaffs object is anything that Yaffs stores - for instance a file or a directory.</p>

<p>Yaffs The memory in NAND flash is arranged in pages. A page is the unit of allocation and programming. In Yaffs, the unit of allocation is the chunk. Typically a chunk will be the same as a NAND page, but there is flexibility to use chunks which map to multiple pages (eg. A system may have two NAND chips in parallel requiring 2x2048 = 4096 byte chunks) . This distinction gives a lot of flexibility in how the system can be configured.</p>

<p>A fixed but configurable number of chunks form a block which is the unit of erasure.</p>

<p>NAND flash may be shipped with bad blocks and further blocks may go bad during the operation of the device so Yaffs detects and marks bad blocks.</p>

<p>NAND flash also typically requires the use of some sort of error detection and correction code (ECC). Yaffs can either use existing ECC logic or provide its own.</p>

<p>Yaffs maintains data in RAM about the file system, but this is not needed for Yaffs to work - so the device can safely lose power at any point without data corruption.</p>

<p>Here's how the Yaffs file system works to ensure data safety and a very fast startup... At regular points and on controlled shutdown, checkpoint blocks are written to the Flash memory, containing all the data to quickly rebuild the file system. Under usual circumstances this checkpoint is used when a device is started, to very quickly rebuild the RAM data about the file system. If the checkpoint is determined to be corrupted, or if the user requested then the file system is rebuilt by scanning.</p>

<p>To do this, Yaffs makes a prescan, to find the sequence numbers for blocks. Then it scans through blocks backwards to build up the list of chunks that make up objects. It speeds up this process by using Block Summaries, which are collections of all the tags in a data in a block. (But it's still always possible to go back to the chunks themselves, to find the tags, if a summary is missing or damaged.)</p>

<p>And tags are how Yaffs tells that a chunk belongs to a particular object.</p>

<p>Tags are also how Yaffs knows which chunks make up the current version of an object... Because the file system is log structured, if an object has been updated, only the latest chunks are used, giving the correct version of the object. A full description of the process is available in the technical documentation, and of course you can browse the code to see exactly how it all works; there's a lot more to tags, the metadata that they can hold, how they are stored, and how tags are used to link together objects into a file system with a POSIX interface.</p>

<p>And of course that's not the end of the story. There's caching to deal with repeated small changes to data. There's garbage collection to let space be re-used, and Yaffs deals with collecting garbage differently depending on whether there's lots of free space or only a little. And part of making Yaffs a high performance flash file system is to make sure that re-useable blocks are erased well before they are needed, so that writing involves only a single operation. There's lazy loading to help ensure a low memory footprint. And all of this is built in a portable way, so that Yaffs can be configured to match almost any hardware, and can be ported to any operating system, or work on bare metal without an operating system. There's a test harness which is used to subject Yaffs to power failure, and ensure it works even with external data corruption. That's what makes it robust enough to send into space and to handle hundreds of terabytes of mission critical data.</p>

<p>Read more about the thinking behind Yaffs in XXXX</p>

<h4>Why is Yaffs special</h4>

<p>Yaffs has been in use since 2002, and so it is hardened. It has been used in everything from sewing machines to satellites. It is popular with Aerospace companies, and firms managing large infrastructure and in Point-of-Sale equipment (where customer feedback is very rapid!) It has been used in extreme conditions where it must not lose data, and where there is no chance for maintenance. It's been used for very large file systems up to 190TB. It's been used for safety critical applications, and millions of consumer devices.</p>

<p>We carry out testing in a rig which can simulate random power failures and proved its reliability after [d] millions of power failures. [Link here to doc.] It's designed with an understanding of the constraints of Flash memory and for speed.</p>

<p>It works on multiple operating systems – Linux, VxWorks, Windows CE, eCos. - and also directly on bare metal, with no operating system. And it's easy to integrate into your RTOS or application using the Yaffs Direct Interface. It works with multiple types of Flash memory - NAND, NOR, SLC, MLC. It's endian neutral. It's been used with 32-bit and 64-bit CPUs including MIPS, 68000, ARM, ColdFire, PowerPC and x86 variants. Yaffs has even been used with various DSP architectures! And it'll work with 16-bit with some tuning. So it can be configured to work with your design and the Flash geometry that you need.</p>

<p>And it's a free embedded flash file system - it’s open source! Grab the GPL version now! Check out our the active community. And that's not the whole story - there are lots more reasons that make Yaffs special.</p>
