TargetFTL-NDM™ Flash Translation Layer and Bad Block Manager for NAND Flash Memory

Overview

TargetFTL-NDM makes NAND flash memory behave like a hard drive, with sectors that can be read, written, and re-written freely. In contrast, NAND writes can only change ‘1’s to ‘0’s. Bits are only changed back to ‘1’ by erasing an entire block (typ 128KB or larger). Because data cannot be rewritten in place, modifications are written to a free page, leaving the old page ‘dirty’. This requires the FTL to maintain a dynamic mapping between virtual sectors and flash pages. It also necessitates garbage collection and wear leveling.

Because NAND flash has bad blocks, both initial bad blocks and blocks that fail during operation, TargetFTL-NDM includes a bad block manager swaps out bad blocks, making the flash appear to have a fixed number of always good virtual blocks.

Features

  • Works with TargetXFS™ and TargetFAT™ to implement fast reliable file systems on NAND flash. Use of NAND flash media for the backing store is invisible to application layer. Can be used standalone to provide a block mode driver for third party file systems.

  • Dynamic mapping between file system sectors and flash memory pages. Since flash sectors cannot be overwritten in place, when a file is modified or overwritten, the FTL allocates new flash pages and updates its mapping tables used to translate the file system’s sector numbers to the new flash page numbers.

  • Wear leveling. Because erase cycles cause wear on the flash device (whose lifetime is specified as the number of erase cycles they can endure), FTLs must spread wear evenly on all flash blocks assigned to a volume to prevent premature media failure. Blunk’s FTLs perform both dynamic (low wear blocks are prioritized for writes) and static (cold data is copied to higher wear blocks) wear leveling. Within a limit, no block will have a higher erase count than other blocks.

  • Third-generation virtual to physical page mapping and wear leveling algorithms. Blunk’s FTLs are advanced designs that track whether data is ‘hot’ or ‘cold’ (frequently or rarely updated, respectively) and performs ‘cold data coalescing’ and ‘cold data pasting’ to optimize performance and reduce wear.

  • Because they cannot be rewritten, there is an ongoing need to reclaim ‘dirty’ flash pages by erasing blocks. Before a block is erased, its in-use pages must be copied to another block, reducing the number of free pages gained. Consequently, garbage collection is more efficient if it is easier to find blocks with no or few in-use pages.

    Reserving memory to improve garbage collection efficiency is called overprovisioning. Some SSDs reserve 12% or more of their available flash. TargetFTL-NDM reserves 6% by default but the overprovisioning amount is configurable to allow management of this utilization-performance tradeoff.

  • Because reading drains a small amount of charge from flash cells, the page read count is recorded per block and at specified limits, the block’s data is copied to new locations, refreshing the flash cell voltage margins. The read-wear limits are configurable.

  • As another protection against accumulated read wear, a block’s data is copied to a new location if the flash driver reports that a page read had corrected bit errors that exceeded a threshold. Prevents data loss from later bit errors that exceed the ECC strength.

  • Provides guaranteed power-fail recovery when used with TargetFAT and TargetXFS, ensuring volume integrity across unexpected shutdowns. Only data written after the last synchronizing operation (fflush(), fsync(), etc.) can be lost. Closed files, directory structures, and files open for reading are never at risk.

  • For optimal performance and highest flash utilization, the page number size in FTL map pages is compile-time configurable as 2, 3, or 4 bytes. With a 2KB page, 2 byte page numbers support volumes up to 128MB in size and 3 byte page numbers support volumes up to 32GB in size.

  • Map table caching provides a configurable memory footprint and tuned performance for volumes ranging from KBs to TBs in size.

  • Bad block management. NAND devices have blocks that are initially bad and blocks that fail erase or page program commands. Uses TargetNDM to perform bad block management by reserving a pool of blocks and transparently swapping out failed blocks after copying their in-use data to a reserved block.

  • NAND devices also have bit errors, as specified in their data sheet. These must be corrected either in the driver layer, the NAND flash device, or the NAND flash controller by ECC. TargetNDM includes software routines for 1 and 4 bit error correction but for performance hardware ECC is usually used when more than 1 bit error correction is required.

  • Supports all parallel and serial Single Level Cell (SLC) and Multi-Level Cell (MLC) NAND flash devices. Performs in-order page writes, avoids partial programming (programming a page more than once between block erasures), and uses only 16 spare bytes per page.

  • Garbage collection, to free dirty pages, is performed just-in-time by default. It may be scheduled for system idle times by calling vclean() from a low priority task. Applications can manually schedule garbage collection by calling vclean() before a planned write for optimum streaming throughput.

  • When used with TargetXFS or TargetFAT, the FTL performs TRIM at file system sequence points. TRIM accounts for deleted files by removing unused entries from FTL mapping tables, making garbage collection more efficient.

  • Worst-case power loss occurs if the free page count is critically low when an in-progress garbage collection is interrupted. The FTL detects this condition during startup and performs a resume option to recover the free pages lost by the interrupted garbage collection, guaranteeing it can restart successfully.

  • Unless unmount() was used at the last shutdown, blocks are erased before their first use since the last start-up. Protects against writing data on a page that was subject to an interrupted page write or block erase commands, for reliability.

  • The best way to measure FTL memory footprint (and performance) is using your own hardware and development environment. Blunk supports source code evaluations for that purpose. For estimation, footprint measurements using an ARM Cortex-A9 on a 256MB volume with 2048B pages and 128KB blocks are shown below.

    Cached Map Pages Code RAM
    1 45KB 20KB
    10 45KB 38KB
    50 45KB 119KB
  • Supports reentrant use in multitasking environments via one global semaphore and one semaphore per volume.

  • A single flash device can support multiple FTL volumes or a single volume can be implemented using multiple flash devices. FTL volumes can be permanently installed or added and deleted as needed.

  • To protect against interrupted page write and block erase commands, all blocks are erased before their first use since the last start-up, unless unmount was used. Unmount saves a list of the erased blocks.

  • Binary volume image tool for creating image files for pre-production programming of flash devices using automated programmers from Data I/O, BP Microsystems, etc.

  • Optimized for fast initialization and mount times.

  • Optional copy_page() driver routine supports faster garbage collection for NAND flash devices that can perform on-chip transfers, to avoid copying data on and off the chip.

  • For efficient DMA use, all buffers passed to the driver are aligned on CPU cache line boundaries.

  • Extensive scripted testing of error handling, multitasking reentrancy, memory allocation failure, powerfail recovery, and regression tests ensure reliability. Tested on big and little-endian CPUs. Automated continuous 247 powerfail recovery testing on physical hardware.

  • Used in consumer electronics and industrial products worldwide.

  • Developed using TargetOS™-Lite, Blunk’s free RTOS. Easily ported to other RTOSes or used in polled mode, without a kernel.

  • Source code is 100% Standard C and has been tested using PC-lint and multiple Standard C compilers, including GCC.

  • Royalty-free license. Includes complete source code, sample applications, sample drivers, user’s manual, and one year of technical support. Electronic delivery via customer-specific web portal.

  • Bundled in liteFS-NAND