A Stackable Wear-Leveling Module for Linux-Based Flash File Systems Hai-Ning Wu 1 and Li-Pin Chang hainingwu@gmail.com and lpchang@cs.nctu.edu.tw Department of Computer Science National Chiao-Tung University, Hsin-Chu, Taiwan Abstract 1 Flash memory has now become a crucial component in building Linux-based embedded computers. As the overall flash-memory lifetime is concerned with block endurance, wear leveling is needed to evenly erase all blocks. This paper presents a modularized implementation of a wear-leveling algorithm. Our goal is to instantly enable any existing Linux-based flash file systems the ability of wear leveling without to modify the file systems. 1. Introduction With rich resources and trustworthy reliability, Linux has been a promising choice in building advanced embedded computers. A commonly faced design problem is how a storage system can be deployed in embedded computers, as power-hungry hard drives are vulnerable to shock. As a result, flash memory is widely used. Different from disks, flash memory is write-once and bulk-erase. New flash file systems are introduced to Linux, such as JFFS2 [1] and YAFFS [2]. Basically, a flash file system must deal with address translation and garbage collection. The former issue is to map the logical addresses of a piece of data onto physical locations on flash memory, and the latter one is to recycle space occupied by invalid data by means of block erasure. In Linux, the MTD (memory technology device) subsystem is introduced as a software framework for solid-state devices, especially for flash memory, as shown in Figure 1. As realistic workloads access flash memory with strong spatial localities, frequently updated data quickly leave invalid data in some particular blocks. Erasure is thus directed to the blocks in favor of garbage-collection efficiency. However, the preference may ultimately lead to uneven wearing of blocks, as shown in Figure 2(a). Because each individual flash-memory block endures only a limited cycle number of erasure operations (typically 100K) [3], the overall lifetime of the storage systems is largely concerned. Wear leveling refers to the intention to evenly distribute erasure cycles over blocks, as shown in Figure 2(b). 1 The corresponding author. The current open-source flash file systems do not seriously consider wear leveling. In particular, JFFS2 periodically erases an infrequently worn block Figure 1. The architecture of the Linux MTD subsystem and the role of the proposed wear-leveling module. 0 200 400 600 800 1000 1 2 3 4 5 6 7 8 9 10 11 12 13 Physical block number Erasure cycle counts 0 200 400 600 800 1000 1 2 3 4 5 6 7 8 9 10 11 12 13 Physical block number Erasure cycle counts Figure 2. Different effects on wear leveling: (a) No wear leveling, and (b) the desired effect. , and YAFFS considers no wear leveling at all. One brute-force approach is to directly modify the file systems. However, obviously, different file systems need to be modified separately, and the wear-leveling code must be synchronized with version changes to the file systems. In this paper, we present a stackable wear-leveling module. As shown in Figure 1, the module sits between real flash-memory devices and file systems. Wear-leveling activities are conducted internally in the wear-leveling module, and they are completely transparent to file systems. By this way any Linux-based flash file systems can be benefited without any modifications. 2. A Stackable Wear-Leveling Module There are two kinds of wear-leveling algorithms in literatures. Reclaiming-based algorithms are garbage-collection policies that take wear leveling into considerations. Placement-based algorithms do nothing but change data placement. It is to manipulate that which block is erased by garbage collection, and can be orthogonal to garbage collection. We have previously proposed an efficient and