Algorithms and Data Structures for Flash Memories
Total Page:16
File Type:pdf, Size:1020Kb
Algorithms and Data Structures for Flash Memories ERAN GAL AND SIVAN TOLEDO Tel-Aviv University Flash memory is a type of electrically-erasable programmable read-only memory (EEPROM). Because flash memories are nonvolatile and relatively dense, they are now used to store files and other persistent objects in handheld computers, mobile phones, digital cameras, portable music players, and many other computer systems in which magnetic disks are inappropriate. Flash, like earlier EEPROM devices, suffers from two limitations. First, bits can only be cleared by erasing a large block of memory. Second, each block can only sustain a limited number of erasures, after which it can no longer reliably store data. Due to these limitations, sophisticated data structures and algorithms are required to effectively use flash memories. These algorithms and data structures support efficient not-in-place updates of data, reduce the number of erasures, and level the wear of the blocks in the device. This survey presents these algorithms and data structures, many of which have only been described in patents until now. Categories and Subject Descriptors: D.4.2 [Operating Systems]: Storage Management—Allocation/deallocation strategies; garbage collection; secondary storage; D.4.3 [Operating Systems]: File Systems Management—Acess methods; file organization; E.1 [Data Structures]—Arrays; lists, stacks, and queues; trees; E.2 [Data Storage Representations]—Linked representations; E.5 [Files]—Organizagtion/ structure General Terms: Algorithms, Performance, Reliability Additional Key Words and Phrases: Flash memory, EEPROM memory, wear leveling 1. INTRODUCTION of other programmable memories such as volatile RAM and magnetic disks. Perhaps Flash memory is a type of electrically- more importantly, memory cells in a flash erasable programmable read-only mem- device (as well as in other types of EEP- ory (EEPROM). Flash memory is nonvolatile ROM memory) can be written to only a lim- (retains its content without power) so it ited number of times, between 10,000 and is used to store files and other persistent 1,000,000, after which they wear out and objects in workstations and servers (for become unreliable. the BIOS), handheld computers and mobile In fact, flash memories come in two fla- phones, digital cameras, and portable mu- vors, NOR and NAND, that are also quite dif- sic players. ferent from each other. In both types, write The read/write/erase behaviors of flash operations can only clear bits (change memory is radically different than that their value from 1 to 0). The only way to Authors’ address: School of Computer Science, Tel-Aviv University, Tel-Aviv 69978, Israel; email: [email protected]. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or direct commercial advantage and that copies show this notice on the first page or initial screen of a display along with the full citation. Copy- rights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, to redistribute to lists, or to use any component of this work in other works requires prior specific permission and/or a fee. Permissions may be requested from Publications Dept., ACM, Inc., 1515 Broadway, New York, NY 10036 USA, fax: +1 (212) 869-0481, or [email protected]. c 2005 ACM 0360-0300/05/0600-0138 $5.00 ACM Computing Surveys, Vol. 37, No. 2, June 2005, pp. 138–163. Algorithms and Data Structures for Flash Memories 139 set bits (change their value from 0 to 1) is other patents assigned to two compa- to erase an entire region memory. These nies that specialize in flash-management regions have fixed size in a given device, products, M-Systems and SanDisk (for- typically ranging from several kilobytes merly SunDisk). Finally,we also examined to hundreds of kilobytes and are called patents that were cited or mentioned in erase units.NOR flash, the older type, is a other relevant materials both patents and random-access device that is directly ad- Web sites. dressable by the processor. Each bit in a We believe that this methodology led us NOR flash can be individually cleared once to most of the relevant materials. But this per-erase-cycle of the erase unit contain- does not imply, of course, that the article ing it. NOR devices suffers from high erase covers all the techniques that have been times. NAND flash, the newer type, enjoys invented. The techniques that are used in much faster erase times, but it is not di- some flash-management products have re- rectly addressable (it is accessed by issu- mained trade secrets; some are alluded to ing commands to a controller), access is in corporate literature but are not fully by page (a fraction of an erase unit, typi- described. Obviously, this article does not cally 512 bytes) not by bit or byte, and each cover such techniques. page can be modified only a small num- The rest of this survey consists of three ber of times in each erase cycle. That is, sections, each of which describes the map- after a few writes to a page, subsequent ping of one category of abstract data struc- writes cannot reliably clear additional bits tures onto flash memories. The next sec- in the page; the entire erase unit must be tion discusses flash data structures that erased before further modifications of the store an array of fixed- or variable-length page are possible [Woodhouse 2001]. blocks. Such data structures typically em- Because of these peculiarities, storage- ulate magnetic disks where each block management techniques that were de- in the array represents one disk sec- signed for other types of memory devices, tor. Even these simple data structures such as magnetic disks, are not always pose many flash-specific challenges such appropriate for flash. To address these as wear leveling and efficient reclama- issues, flash-specific storage techniques tion. These challenges and techniques to have been developed with the widespread address them are discussed in detail in introduction of flash memories in the early Section 2, and in less detail in later sec- 1990s. Some of these techniques were in- tions. The section that follows, Section 3, vented specifically for flash memories, but describes flash-specific file systems. A file many have been adapted from techniques system is a data structure that represents that were originally invented for other a collection of mutable random-access files storage devices. This article surveys the in a hierarchical name space. Section 4 data structures and algorithms that have describes three additional classes of flash been developed for management of flash data structures: application-specific data storage. structures (mainly search trees), data The article covers techniques that have structures for storing machine code, and a been described in the open literature, mechanism to use flash as a main memory including patents. We only cover US replacement. Section 5 summarizes the patents mostly because we assume that survey. US patents are a superset of those of other countries. To cope with the large number 2. BLOCK-MAPPING TECHNIQUES of flash-related patents, we used the fol- lowing strategy to find relevant patents. One approach to using flash memory is to We examined all the patents whose ti- treat it as a block device that allows fixed- tles contain the words flash, file (or fil- size data blocks to be read and written ing), and system,aswell as all the patents much like disk sectors. This allows stan- whose titles contain the words wear and dard file systems designed for magnetic leveling.Inaddition, we also examined disks, such as FAT,toutilize flash devices. ACM Computing Surveys, Vol. 37, No. 2, June 2005. 140 E. Gal and S. Toledo In this setup, the file system code calls ten, the new data does not overwrite the a device driver, requesting block read or sector where the block is currently stored. write operations. The device driver stores Instead, the new data is written to another and retrieves blocks from the flash device. sector and the virtual-block-to-sector map (Some removable flash devices, like Com- is updated. pactFlash, even incorporate a complete Typically, sectors have a fixed size and ATA disk interface so they can actually be occupy a fraction of an erase unit. In NAND used through the standard disk driver.) devices, sectors usually occupy one flash However, mapping the blocks onto flash page. But in NOR devices, it is also possible addresses in a simple linear fashion to use variable-length sectors. presents two problems. First, some data This mapping serves several purposes: blocks may be written to much more than others. This presents no problem for —First, writing frequently modified blocks magnetic disks so conventional file sys- to a different sector in every modifica- tems do not attempt to avoid such situa- tion evens out the wear of different erase tions. But when the file system in mapped units. onto a flash device, frequently used erase —Second, the mapping allows writing a units wear out quickly, slowing down ac- single block to flash without erasing and cess times and eventually burning out. rewriting an entire erase unit [Assar This problem can be addressed by using et al. 1995a, 1995b, 1996]. a more sophisticated block-to-flash map- —Third, the mapping allows block writes ping scheme and by moving blocks around. to be implemented atomically so that, if Techniques that implement such strate- power is lost during a write operation, gies are called wear-leveling techniques. the block reverts to its prewrite state The second problem that the identity when flash is used again.