[go: up one dir, main page]

CN102222046B - Abrasion equilibrium method and device - Google Patents

Abrasion equilibrium method and device Download PDF

Info

Publication number
CN102222046B
CN102222046B CN 201110154330 CN201110154330A CN102222046B CN 102222046 B CN102222046 B CN 102222046B CN 201110154330 CN201110154330 CN 201110154330 CN 201110154330 A CN201110154330 A CN 201110154330A CN 102222046 B CN102222046 B CN 102222046B
Authority
CN
China
Prior art keywords
block
pool
physical
gbl
ebl
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN 201110154330
Other languages
Chinese (zh)
Other versions
CN102222046A (en
Inventor
潘立阳
唐晨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tsinghua University
Original Assignee
Tsinghua University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tsinghua University filed Critical Tsinghua University
Priority to CN 201110154330 priority Critical patent/CN102222046B/en
Publication of CN102222046A publication Critical patent/CN102222046A/en
Priority to US13/519,230 priority patent/US9405670B2/en
Priority to PCT/CN2012/072372 priority patent/WO2012167642A1/en
Application granted granted Critical
Publication of CN102222046B publication Critical patent/CN102222046B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Techniques For Improving Reliability Of Storages (AREA)
  • Memory System (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种磨损均衡方法,该方法根据每一个物理块的擦除次数,确定每一个物理块的池掩码;其中,对于不同擦除次数,物理块的池掩码确定为冷池掩码CPM、普通池掩码NPM或热池掩码HPM;当有物理块的池掩码从NPM变为HPM时,将任一个池掩码为CPM的物理块中的数据复制到所述池掩码为HPM的物理块上,并将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。本发明还公开了一种磨损均衡装置,该方法和装置能够降低磨损均衡带来的额外磨损。

The invention discloses a wear leveling method, which determines the pool mask of each physical block according to the erasing times of each physical block; wherein, for different times of erasing, the pool mask of the physical block is determined as a cold pool Mask CPM, normal pool mask NPM, or hot pool mask HPM; when the pool mask with physical blocks changes from NPM to HPM, copy the data in any physical block whose pool mask is CPM to said pool The physical block whose mask is HPM, and the physical block whose pool mask is CPM is used as a garbage block for garbage collection. The invention also discloses a wear leveling device, the method and the device can reduce the extra wear caused by the wear leveling.

Description

一种磨损均衡方法及装置Wear leveling method and device

技术领域 technical field

本发明涉及存储技术领域,特别涉及一种磨损均衡方法及装置。The invention relates to the field of storage technology, in particular to a wear leveling method and device.

背景技术 Background technique

目前,非易失性存储器在计算机、通讯和消费电子产品中非易失性存储器得到了广泛的应用;例如,U盘、MP3、数码相机、移动通信终端、固态硬盘等产品中都使用非易失性存储器作为存储介质。随着这些产品对存储容量的要求不断提高,非易失性存储器的工艺尺寸不断缩小,导致非易失性存储器的可靠性面临着越来越严峻的挑战,尤其是非易失性存储器擦除操作的最小单位物理块的擦除次数有限,这对非易失性存储器的使用寿命会造成严重影响。对于物理块擦除次数有限的问题,现有技术的做法是对物理块进行磨损均衡,通过对物理块的擦除进行控制,尽量平均存储器中所有物理块的擦除次数,避免某些物理块擦除次数过高,比其它物理块提前到达擦除次数上限而失效,造成存储器在尚有很多物理块未达寿命的情况下整体失效。At present, non-volatile memory is widely used in computers, communications and consumer electronics products; for example, U disk, MP3, digital camera, mobile communication terminal, solid-state hard disk and other products Volatile memory as a storage medium. As the storage capacity requirements of these products continue to increase, the process size of non-volatile memory continues to shrink, causing the reliability of non-volatile memory to face more and more severe challenges, especially the erase operation of non-volatile memory The number of erasures of the smallest unit physical block is limited, which will have a serious impact on the service life of the non-volatile memory. For the problem that the number of erasures of physical blocks is limited, the existing technology is to perform wear leveling on physical blocks. By controlling the erasure of physical blocks, try to average the number of erasures of all physical blocks in the memory to avoid certain physical blocks. The number of erasures is too high, and the upper limit of erasure times is reached earlier than other physical blocks, causing the memory to fail as a whole when there are still many physical blocks that have not reached their service life.

磨损均衡包括针对数据写入过程中通过控制写入的物理块,动态均衡所有物理块擦除次数的动态磨损均衡,以及通过调整物理块上存储的数据(经常被擦写的热数据或不经常被擦写的冷数据),静态地均衡所有物理块擦除次数的静态磨损均衡两大类。针对这两大类磨损均衡,现有技术已经提出了很多算法,但是这些算法一直没有很好地解决磨损均衡效果和降低因为磨损均衡算法本身带来的额外磨损之间的矛盾,而且现有的磨损均衡算法实现是基于保存每一个物理块的磨损信息,随着存储器容量增加,存储器中需要进行磨损均衡的物理块的数量大增,在执行磨损均衡算法时,搜索物理块磨损信息的速度也变得越来越慢。Wear leveling includes controlling the physical blocks written during the data writing process, dynamically balancing the dynamic wear leveling of all physical block erasing times, and adjusting the data stored on the physical blocks (hot data that is often erased or infrequently written) There are two types of static wear leveling that statically balances the erasure times of all physical blocks. For these two types of wear leveling, many algorithms have been proposed in the prior art, but these algorithms have not been able to solve the contradiction between the effect of wear leveling and the reduction of additional wear caused by the wear leveling algorithm itself, and the existing The implementation of the wear leveling algorithm is based on saving the wear information of each physical block. As the memory capacity increases, the number of physical blocks that need to be wear leveled in the memory increases greatly. When the wear leveling algorithm is executed, the speed of searching for the wear information of the physical blocks also increases. become slower and slower.

下面以一种目前使用广泛的代表性磨损均衡算法“双池算法”为例,对现有技术加以详细说明。The following is a detailed description of the prior art by taking a representative wear leveling algorithm "dual pool algorithm" which is widely used at present as an example.

如图1所示,该算法是一种结合了动态磨损均衡和静态磨损均衡的综合算法,该算法对物理块设置冷池和热池属性,并定义EC为物理块的总擦除次数;EEC为物理块的冷热池属性变化后重新开始累计的擦除次数(以下称为有效擦除次数);PT为物理块的冷热池属性标记,该标记中,CP表示冷池,HP表示热池,每一个物理块需要记录的磨损信息包括EC、EEC和PT。As shown in Figure 1, this algorithm is a comprehensive algorithm that combines dynamic wear leveling and static wear leveling. The algorithm sets cold pool and hot pool attributes for physical blocks, and defines EC as the total number of erasures of physical blocks; EEC It is the number of erasing times accumulated after the hot and cold pool attributes of the physical block are changed (hereinafter referred to as the effective erasing times); PT is the hot and cold pool attribute mark of the physical block. Pool, the wear information that needs to be recorded for each physical block includes EC, EEC, and PT.

在算法中,定义

Figure BDA0000067173260000021
分别表示冷池中擦除次数队列,热池中擦除次数的队列,冷池中有效擦除次数的队列,热池中有效擦除次数的队列。定义H+(Q)和H-(Q)分别为返回队列Q的最大值和最小值(具体物理块)的函数;EC(B)为返回物理块B的总擦除次数的函数;EEC(B)为返回物理块B的有效擦除次数的函数。In the algorithm, define
Figure BDA0000067173260000021
Respectively represent the queue of erasure times in the cold pool, the queue of the erasure times in the hot pool, the queue of the effective erasure times in the cold pool, and the queue of the effective erasure times in the hot pool. Define H + (Q) and H- (Q) to be the function of returning the maximum value and the minimum value (concrete physical block) of queue Q respectively; EC(B) is the function that returns the total erasing times of physical block B; EEC( B) is a function that returns the effective erasure count of physical block B.

具体算法执行过程如图1所示,包括如下步骤:The specific algorithm execution process is shown in Figure 1, including the following steps:

步骤101,获取磨损信息;在执行双池算法前,需要先获取所有物理块的磨损信息,之后才能对物理块进行管理,这一获取磨损信息的步骤一般在存储器上电初始化的过程中完成,分两种情况,如果存储器非第一次使用,则磨损信息会在存储器上一次正常卸载时被记录在存储器中(如存储器中专门划分出来,用户不可见的用于保存管理信息的备份区),在存储器上电初始化时,只需要读取存储器备份区的数据即可得到磨损信息;如果存储器是第一次使用,则备份区是没有数据的,此时需要构建磨损信息,即将EC、EEC置0,并对物理块标记冷热池属性,将物理块划分到冷池或热池;将物理块划分到冷池和热池的具体方法可以是任意的,例如随机划分。Step 101, obtain wear information; before executing the dual-pool algorithm, it is necessary to obtain wear information of all physical blocks before managing the physical blocks. This step of obtaining wear information is generally completed during the power-on initialization process of the memory. In two cases, if the memory is not used for the first time, the wear information will be recorded in the memory when the memory is unloaded normally last time (such as a backup area specially divided in the memory and invisible to the user for storing management information) , when the memory is powered on and initialized, you only need to read the data in the backup area of the memory to get the wear information; if the memory is used for the first time, there is no data in the backup area. Set to 0, and mark the hot and cold pool attributes on the physical block, and divide the physical block into the cold pool or the hot pool; the specific method of dividing the physical block into the cold pool and the hot pool can be arbitrary, such as random division.

步骤102,判断是否有写请求,如果是,进入步骤103,否则进入步骤117;Step 102, judge whether there is a write request, if yes, enter step 103, otherwise enter step 117;

步骤103,判断分配给写请求的写入块是否已经写满,若是,则进入步骤104,否则进入步骤105;Step 103, judging whether the write block assigned to the write request has been filled, if so, proceed to step 104, otherwise proceed to step 105;

步骤104,从预先设置的空白块队列中,按照新来新分配(FIFO)的方式(按照进入空白块队列的顺序,首先进入队列的空白块将首先分配出去),为写请求分配空白块,进入步骤105;Step 104, from the preset blank block queue, allocate a blank block for the write request according to the new allocation (FIFO) method (according to the order of entering the blank block queue, the blank block that first enters the queue will be allocated first), Go to step 105;

步骤105,响应写请求,将数据写入分配的写入块;Step 105, responding to the write request, writing the data into the allocated write block;

步骤106,判断

Figure BDA0000067173260000032
之差是否超过设定的阈值TH,若是,则进入步骤107,否则进入步骤111;Step 106, judge and
Figure BDA0000067173260000032
Whether the difference exceeds the set threshold TH, if so, then enter step 107, otherwise enter step 111;

步骤107,强制回收物理块,即将该物理块上保存的有效数据复制到其它物理块,并擦除

Figure BDA0000067173260000034
上保存的数据。Step 107, mandatory recycling Physical block, that is, to copy the valid data stored on this physical block to other physical blocks and erase
Figure BDA0000067173260000034
data saved on.

步骤108,将

Figure BDA0000067173260000035
物理块上的数据复制到
Figure BDA0000067173260000036
物理块;Step 108, will
Figure BDA0000067173260000035
The data on the physical block is copied to
Figure BDA0000067173260000036
physical block;

步骤109,擦除

Figure BDA0000067173260000037
物理块上的数据,使之变为空白块;Step 109, Erase
Figure BDA0000067173260000037
Data on the physical block, making it a blank block;

步骤110,交换

Figure BDA0000067173260000039
物理块的冷热池属性;因冷热池属性变化,
Figure BDA00000671732600000311
物理块各自的EEC将清零,重新开始累计。Step 110, exchange and
Figure BDA0000067173260000039
The hot and cold pool properties of the physical block; due to the change of the hot and cold pool properties, and
Figure BDA00000671732600000311
The EEC of each physical block will be cleared to zero, and the accumulation will start again.

步骤111,判断

Figure BDA00000671732600000312
Figure BDA00000671732600000313
之差是否超过2倍阈值TH;若是,进入步骤112,否则进入步骤113;Step 111, judge
Figure BDA00000671732600000312
and
Figure BDA00000671732600000313
Whether the difference exceeds 2 times the threshold TH; if so, enter step 112, otherwise enter step 113;

步骤112,将

Figure BDA00000671732600000314
物理块的PT从热池调整为冷池;Step 112, will
Figure BDA00000671732600000314
The PT of the physical block is adjusted from the hot pool to the cold pool;

步骤113,判断

Figure BDA00000671732600000315
Figure BDA00000671732600000316
之差是否超过阈值TH;若是,则进入步骤114,否则进入步骤115;Step 113, judge
Figure BDA00000671732600000315
and
Figure BDA00000671732600000316
Whether the difference exceeds the threshold TH; if so, then enter step 114, otherwise enter step 115;

步骤114,将

Figure BDA00000671732600000317
物理块的PT从冷池调整为热池;Step 114, will
Figure BDA00000671732600000317
The PT of the physical block is adjusted from the cold pool to the hot pool;

步骤115,判断存储器的可用空间是否小于预设的阈值,若是,则进入步骤116,否则返回步骤102;Step 115, judging whether the available space of the memory is less than a preset threshold, if so, then enter step 116, otherwise return to step 102;

步骤116,垃圾回收,返回步骤102;Step 116, garbage collection, return to step 102;

步骤117,判断存储器是否卸载,若是,进入步骤118,否则返回步骤102;Step 117, determine whether the memory is unloaded, if so, enter step 118, otherwise return to step 102;

步骤118,保存磨损信息,结束流程。Step 118, save the wear information, and end the process.

上述步骤中,步骤102~103、105是正常的数据写入过程,步骤104则是该算法的动态均衡部分,即通过空白块队列,采用FIFO方式控制空白块的分配,达到动态磨损均衡的效果。Among the above steps, steps 102-103 and 105 are the normal data writing process, and step 104 is the dynamic balance part of the algorithm, that is, through the blank block queue, the allocation of blank blocks is controlled by FIFO to achieve the effect of dynamic wear balance .

步骤106~114是该算法的静态均衡部分,通过移动

Figure BDA0000067173260000042
上保存的冷热数据,以及交换
Figure BDA0000067173260000043
Figure BDA0000067173260000044
的冷热池属性,使得擦除次数多的物理块因保存冷数据并进入冷池而减缓磨损,擦除次数少的物理块因保存热数据并进入热池而加快磨损,从而达到磨损均衡的目的。Steps 106-114 are the static equalization part of the algorithm, by moving and
Figure BDA0000067173260000042
The hot and cold data saved on it, and the exchange
Figure BDA0000067173260000043
and
Figure BDA0000067173260000044
The properties of hot and cold pools make the physical blocks that have been erased more often slow down wear because they store cold data and enter the cold pool, and the physical blocks that have been erased less frequently because they store hot data and enter the hot pool to accelerate wear, thereby achieving wear balance. Purpose.

步骤115之后是存储器的垃圾回收和卸载过程;其中垃圾回收包含数据转移和擦除过程。所谓数据转移是指擦除之前必须将标记为有效的数据拷贝到其他区块上;所谓的擦除过程是指将已经写有数据、但是所有数据已被标记为无效的物理块,即垃圾块进行擦除得到空白块的过程,现有的垃圾回收过程中,一般是随机选择垃圾块,双池算法的动态均衡部分并未对垃圾回收的过程进行改进。另外,卸载过程中存储器会将双池算法所需的磨损信息(如EC、EEC、PT和空白块队列)存储下来,以备下次启动存储器时使用。Step 115 is followed by garbage collection and unloading of the memory; wherein garbage collection includes data transfer and erasure. The so-called data transfer means that the data marked as valid must be copied to other blocks before erasing; the so-called erasing process refers to the physical block that has written data but all data has been marked as invalid, that is, the garbage block In the process of erasing to obtain blank blocks, in the existing garbage collection process, garbage blocks are generally randomly selected, and the dynamic balance part of the dual-pool algorithm does not improve the garbage collection process. In addition, during the unloading process, the memory will store the wear information (such as EC, EEC, PT and blank block queue) required by the dual-pool algorithm for use when the memory is started next time.

很明显,为了静态地均衡所有物理块擦除次数,双池算法需要挪动

Figure BDA0000067173260000045
Figure BDA0000067173260000046
两个物理块的有效数据,并且擦除
Figure BDA0000067173260000047
Figure BDA0000067173260000048
两个块。这会产生较大的系统开销,并额外增加物理块的擦除次数,即额外的磨损,这对于磨损均衡的目的(增加存储器寿命)来说,是一个反效果。Obviously, in order to statically balance all physical block erase times, the dual-pool algorithm needs to move
Figure BDA0000067173260000045
and
Figure BDA0000067173260000046
two physical blocks of valid data, and erase
Figure BDA0000067173260000047
and
Figure BDA0000067173260000048
two blocks. This will generate a large system overhead and additionally increase the erasure times of the physical block, that is, additional wear, which is a counter-effect for the purpose of wear leveling (increasing the lifetime of the memory).

另外,由于双池算法需要计算

Figure BDA0000067173260000049
Figure BDA00000671732600000410
这需要遍历整个存储器的所有物理块,然后才能进一步地往下运行。然而随着存储容量的不断提高,物理块的数量也在不断地增加,搜索物理块的速度也会变得越来越慢。In addition, since the two-pool algorithm needs to calculate
Figure BDA0000067173260000049
and
Figure BDA00000671732600000410
This needs to traverse all physical blocks of the entire memory before it can be further run down. However, with the continuous improvement of storage capacity, the number of physical blocks is also increasing, and the speed of searching for physical blocks will also become slower and slower.

发明内容 Contents of the invention

本发明实施例提供一种磨损均衡方法,能够降低磨损均衡带来的额外磨损。Embodiments of the present invention provide a wear leveling method, which can reduce extra wear caused by wear leveling.

本发明实施例提供一种磨损均衡装置,能够降低磨损均衡带来的额外磨损。An embodiment of the present invention provides a wear leveling device, which can reduce extra wear caused by wear leveling.

为达到上述目的,本发明的技术方案具体是这样实现的:In order to achieve the above object, the technical solution of the present invention is specifically realized in the following way:

一种磨损均衡方法,该方法包括:A wear leveling method, the method comprising:

根据每一个物理块的擦除次数,确定每一个物理块的池掩码;Determine the pool mask of each physical block according to the erasure times of each physical block;

其中,对于不同擦除次数,物理块的池掩码确定为冷池掩码CPM、普通池掩码NPM或热池掩码HPM;Wherein, for different times of erasing, the pool mask of the physical block is determined as a cold pool mask CPM, a common pool mask NPM or a hot pool mask HPM;

当有物理块的池掩码从NPM变为HPM时,将任一个池掩码为CPM的物理块中的数据复制到所述池掩码为HPM的物理块上,并将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。When the pool mask of a physical block changes from NPM to HPM, copy the data in any physical block whose pool mask is CPM to the physical block whose pool mask is HPM, and set the pool mask Physical blocks for CPM are garbage collected as garbage blocks.

较佳地,所述对于不同擦除次数,物理块的池掩码确定为冷池掩码CPM、普通池掩码NPM或热池掩码HPM,包括:Preferably, for different erasing times, the pool mask of the physical block is determined as a cold pool mask CPM, a common pool mask NPM or a hot pool mask HPM, including:

物理块的擦除次数等于RECC的值时,确定物理块的池掩码为CPM;擦除次数大于等于RECC+TH的值时确定物理块的池掩码为HPM;擦除次数为其他值时确定物理块的池掩码为NPM;When the number of erasures of the physical block is equal to the value of RECC, the pool mask of the physical block is determined to be CPM; when the number of erasures is greater than or equal to the value of RECC+TH, the pool mask of the physical block is determined to be HPM; when the number of erasures is other values Determine the pool mask of the physical block as NPM;

其中,所述RECC是参考擦除次数计数器,其值等于所有物理块中擦除次数最小的物理块的擦除次数;Wherein, the RECC is a reference erasure count counter whose value is equal to the erasure count of the physical block with the minimum erasure count in all physical blocks;

所述TH为预设的阈值,其取值为大于1的正整数。The TH is a preset threshold, and its value is a positive integer greater than 1.

较佳地,该方法进一步包括:Preferably, the method further comprises:

建立用于管理空白块的空白块链表EBL,所述EBL中的空白块按照其擦除次数升序排列;Establishing a blank block linked list EBL for managing blank blocks, the blank blocks in the EBL are arranged in ascending order according to their erasure times;

当需要为写请求分配空白块时,将所述EBL中的首个空白块作为写入块分配给所述写请求。When a blank block needs to be allocated for a write request, the first blank block in the EBL is allocated to the write request as a write block.

较佳地,所述EBL不允许池掩码为HPM的空白块进入。Preferably, the EBL does not allow blank blocks whose pool mask is HPM to enter.

较佳地,该方法进一步包括:Preferably, the method further comprises:

建立用于管理垃圾块的垃圾块链表GBL,所述GBL中的垃圾块按照擦除次数值升序排列。A garbage block linked list GBL for managing garbage blocks is established, and the garbage blocks in the GBL are arranged in ascending order of erasure times.

较佳地,所述GBL不允许池掩码为HPM的垃圾块进入。Preferably, the GBL does not allow garbage blocks whose pool mask is HPM to enter.

较佳地,当所述EBL中的空白块数量小于预设的阈值时,进行如下所述的垃圾回收过程:Preferably, when the number of blank blocks in the EBL is less than a preset threshold, the following garbage collection process is performed:

如果GBL非空,则擦除所述GBL中首个垃圾块的数据,使之变为空白块,并将该空白块插入EBL中;If the GBL is non-empty, then erase the data of the first garbage block in the GBL to make it a blank block, and insert the blank block into the EBL;

如果GBL已空,则把所有掩码为CPM和NPM的物理块中垃圾数据量最多而且擦除次数最少的物理块的有效数据写入到当前分配的写入块上,并将该垃圾数据最多且擦除次数最少的物理块插入GBL;擦除所述GBL中首个垃圾块的数据,使之变为空白块,并将该空白块插入EBL中。If the GBL is empty, write the effective data of the physical block with the largest amount of garbage data and the least number of erasures among all physical blocks masked as CPM and NPM to the currently allocated write block, and write the garbage data with the largest amount of garbage data. And the physical block with the least erasing times is inserted into the GBL; the data of the first garbage block in the GBL is erased to make it a blank block, and the blank block is inserted into the EBL.

较佳地,所述垃圾回收包括:Preferably, the garbage collection includes:

将池掩码为CPM和NPM的垃圾块插入GBL中。Insert garbage blocks with pool masks CPM and NPM into the GBL.

较佳地,若存储器为第一次使用,在执行所述根据每一个物理块的擦除次数,确定每一个物理块的池掩码的步骤之前,置所有物理块的当前的擦除次数为0;所有物理块当前的池掩码为CPM。Preferably, if the memory is used for the first time, before performing the step of determining the pool mask of each physical block according to the erasing times of each physical block, set the current erasing times of all physical blocks as 0; the current pool mask of all physical blocks is CPM.

较佳地,若存储器不是第一次使用,且上一次使用后正常卸载时,在执行所述根据每一个物理块的擦除次数,确定每一个物理块的池掩码的步骤之前,从存储器的备份区读取得到所有物理块当前的擦除次数、池掩码,以及EBL、GBL。Preferably, if the memory is not used for the first time and is normally unloaded after the last use, before performing the step of determining the pool mask of each physical block according to the number of erasing times of each physical block, from the memory Read the backup area of all physical blocks to get the current erasure count, pool mask, EBL, GBL.

较佳地,若存储器不是第一次使用,且上一次使用后没有正常卸载时,在执行所述根据每一个物理块的擦除次数,确定每一个物理块的池掩码的步骤之前,Preferably, if the memory is not used for the first time and has not been normally unloaded after the last use, before performing the step of determining the pool mask of each physical block according to the number of erasures of each physical block,

从存储器的备份区载入最近一次正常卸载时备份的所有物理块的擦除次数、池掩码,以及EBL、GBL;Load the erasure count, pool mask, EBL, GBL of all physical blocks backed up during the last normal unload from the backup area of the memory;

从EBL中首个物理块开始,逐个检测EBL中物理块的存储状况,如果物理块已非空白块,则从EBL中删除这个物理块;检测持续到检测到物理块为空白块或者EBL为空为止;Starting from the first physical block in the EBL, check the storage status of the physical blocks in the EBL one by one. If the physical block is not a blank block, delete the physical block from the EBL; the detection continues until the physical block is detected as a blank block or the EBL is empty. until;

从GBL中首个物理块开始,逐个检查GBL中物理块的存储状况,如果物理块已经为空白块,则从GBL中删除这个物理块,并将这个物理块插入EBL;检测持续到检测到物理块为垃圾块或者GBL为空为止。Starting from the first physical block in the GBL, check the storage status of the physical blocks in the GBL one by one. If the physical block is already a blank block, delete the physical block from the GBL and insert the physical block into the EBL; the detection continues until the physical block is detected. until the block is a garbage block or the GBL is empty.

较佳地,若所有物理块的池掩码均不再是CPM;则根据当前所有物理块中擦除次数最小的物理块的擦除次数修正RECC的值,并根据修正后的RECC重新确定所有物理块的池掩码。Preferably, if the pool masks of all physical blocks are no longer CPM; then modify the value of RECC according to the erasure times of the physical block with the smallest erasure times in all current physical blocks, and re-determine all Pool mask for physical blocks.

较佳地,该方法进一步包括:当存储器正常卸载时,保存所有物理块当前的擦除次数、池掩码以及当前的EBL、GBL到存储器的备份区。Preferably, the method further includes: when the memory is normally unloaded, saving the current erasure times, pool masks, and current EBL and GBL of all physical blocks to the backup area of the memory.

较佳地,每一个物理块的擦除次数还实时存储于该物理块的物理页中。Preferably, the erasure count of each physical block is also stored in the physical page of the physical block in real time.

一种磨损均衡装置,该装置包括:A wear leveling device, the device comprising:

池维护模块,用于根据每一个物理块的擦除次数,确定每一个物理块的池掩码;其中,对于不同擦除次数,物理块的池掩码为冷池掩码CPM、普通池掩码NPM或热池掩码HPM;The pool maintenance module is used to determine the pool mask of each physical block according to the number of erasing times of each physical block; wherein, for different times of erasing, the pool mask of the physical block is a cold pool mask CPM, a common pool mask code NPM or hotpool mask HPM;

静态均衡模块,与所述池维护模块相连,用于在当有物理块的池掩码从NPM变为HPM时,将任一个池掩码为CPM的物理块中的数据复制到所述池掩码为HPM的物理块上;A static balance module, connected to the pool maintenance module, is used to copy the data in any physical block whose pool mask is CPM to the pool mask when the pool mask of the physical block changes from NPM to HPM On the physical block coded as HPM;

垃圾回收模块,与所述静态均衡模块相连,用于将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。The garbage collection module is connected with the static balancing module, and is used for performing garbage collection on the physical block whose pool mask is CPM as a garbage block.

较佳地,所述池维护模块包括:Preferably, the pool maintenance module includes:

确定单元,用于在物理块的擦除次数等于RECC的值时,确定其池掩码为CPM;擦除次数大于等于RECC+TH的值时为HPM;擦除次数为其他值时为NPM;The determination unit is used to determine that the pool mask of the physical block is CPM when the number of erasing times of the physical block is equal to the value of RECC; it is HPM when the number of erasing times is greater than or equal to the value of RECC+TH; it is NPM when the number of times of erasing is other values;

其中,所述RECC是参考擦除次数计数器,其值等于所有物理块中擦除次数最小的物理块的擦除次数;所述TH为预设的阈值,其取值为大于1的正整数。Wherein, the RECC is a reference erasure count counter, whose value is equal to the erasure count of the physical block with the smallest erasure count among all physical blocks; the TH is a preset threshold, and its value is a positive integer greater than 1.

较佳地,该设备进一步包括:Preferably, the device further includes:

EBL模块,维护用于管理空白块的空白块链表EBL;将所述EBL中的空白块按照擦除次数值升序排列;当需要为写请求分配空白块时,将所述EBL中的首个空白块作为写入块分配给所述写请求。The EBL module maintains the blank block linked list EBL for managing blank blocks; arranges the blank blocks in the EBL in ascending order according to the number of erasures; when it is necessary to allocate a blank block for a write request, the first blank in the EBL is allocated A block is allocated to the write request as a write block.

较佳地,所述EBL模块不允许池掩码为HPM的空白块进入。Preferably, the EBL module does not allow blank blocks whose pool mask is HPM to enter.

较佳地,该设备进一步包括:Preferably, the device further includes:

GBL模块,与所述垃圾回收模块及EBL模块分别相连,维护用于管理垃圾块的垃圾块链表GBL;将所述GBL中的垃圾块按照擦除次数值升序排列。The GBL module is connected to the garbage collection module and the EBL module respectively, maintains a garbage block linked list GBL for managing garbage blocks, and arranges the garbage blocks in the GBL in ascending order according to the number of erasures.

较佳地,所述GBL模块不允许池掩码为HPM的垃圾块进入。Preferably, the GBL module does not allow garbage blocks whose pool mask is HPM to enter.

较佳地,所述GBL模块进一步用于,当存储器中的可用空间小于预设的阈值时;Preferably, the GBL module is further used, when the available space in the memory is less than a preset threshold;

若GBL非空,则擦除所述GBL中首个垃圾块的数据,使之变为空白块;并将该空白块插入所述EBL模块维护的EBL中;If GBL is non-empty, then erase the data of the first garbage block in the GBL to make it a blank block; and insert the blank block into the EBL maintained by the EBL module;

若GBL已空,则先将所有池掩码为CPM和NPM的物理块中垃圾数据最多且擦除次数最少的物理块中的有效数据写入到当前分配的写入块上,并将该垃圾数据最多且擦除次数最少的物理块插入GBL;再擦除所述GBL中首个垃圾块的数据,使之变为空白块;并将该空白块插入EBL中。If the GBL is empty, first write the valid data in the physical block with the most garbage data and the least number of erasures among the physical blocks whose pool masks are CPM and NPM to the currently allocated write block, and write the garbage Insert the physical block with the most data and the least erasure times into the GBL; then erase the data of the first garbage block in the GBL to make it a blank block; and insert the blank block into the EBL.

较佳地,所述垃圾回收模块具体用于将池掩码为CPM和NPM的垃圾块插入所述GBL模块维护的GBL中。Preferably, the garbage collection module is specifically configured to insert garbage blocks whose pool masks are CPM and NPM into the GBL maintained by the GBL module.

较佳地,所述池维护模块进一步包括:Preferably, said pool maintenance module further comprises:

当前值确定单元,与所述确定单元相连,用于在存储器为第一次使用时,置所有物理块的当前的擦除次数为0;所有物理块当前的池掩码为CPM。The current value determining unit is connected with the determining unit, and is used to set the current erasure times of all physical blocks to 0 when the memory is used for the first time; the current pool mask of all physical blocks is CPM.

较佳地,所述池维护模块进一步包括:Preferably, said pool maintenance module further comprises:

当前值确定单元,与所述确定单元相连,用于在存储器不是第一次使用,且上一次使用后正常卸载时,从存储器的备份区读取得到所有物理块当前的擦除次数、池掩码,以及EBL、GBL。The current value determination unit is connected with the determination unit, and is used to read the current erasure times and pool mask of all physical blocks from the backup area of the memory when the memory is not used for the first time and is normally unloaded after the last use. Code, and EBL, GBL.

较佳地,所述池维护模块进一步包括:Preferably, said pool maintenance module further comprises:

当前值确定单元,与所述确定单元相连,用于在存储器不是第一次使用,且上一次使用后没有正常卸载时,The current value determination unit is connected to the determination unit, and is used for when the memory is not used for the first time and has not been unloaded normally after the last use,

从存储器的备份区载入最近一次正常卸载时备份的所有物理块当前的擦除次数、池掩码,以及EBL、GBL;Load the current erasure count, pool mask, EBL, GBL of all physical blocks backed up during the last normal unload from the backup area of the memory;

所述EBL模块从EBL中首个物理块开始,逐个检测EBL中物理块的存储状况,如果物理块已非空白块,则从EBL中删除这个物理块;检测持续到检测到物理块为空白块或者EBL为空为止;Described EBL module starts from the first physical block in the EBL, detects the storage status of the physical block in the EBL one by one, if the physical block is not a blank block, then deletes this physical block from the EBL; detection continues until the physical block is detected as a blank block Or until the EBL is empty;

所述GBL模块从GBL中首个物理块开始,逐个检查GBL中物理块的存储状况,如果物理块已经为空白块,则从GBL中删除这个物理块,并将这个物理块插入所述EBL维护的EBL;检测持续到检测到物理块为垃圾块或者GBL为空为止。The GBL module starts from the first physical block in the GBL, checks the storage status of the physical blocks in the GBL one by one, if the physical block is already a blank block, deletes the physical block from the GBL, and inserts the physical block into the EBL for maintenance EBL; the detection continues until the physical block is detected as a garbage block or the GBL is empty.

较佳地,所述池维护模块进一步包括:Preferably, said pool maintenance module further comprises:

重建单元,与所述确定单元相连,当所有物理块的池掩码均不再是CPM时;根据当前所有物理块中擦除次数最小的物理块的擦除次数修正RECC的值,并根据修正后的RECC重新确定所有物理块的池掩码。The reconstruction unit is connected with the determination unit, and when the pool masks of all physical blocks are no longer CPM; the value of RECC is corrected according to the erasure count of the physical block with the smallest erasure count among all current physical blocks, and according to the correction The post-RECC re-determines the pool mask for all physical blocks.

较佳地,该装置进一步包括:Preferably, the device further includes:

备份模块,与所述池维护模块、EBL模块、GBL模块分别相连,用于当存储器正常卸载时,保存所有物理块当前的擦除次数、掩码以及当前的EBL、GBL到存储器的备份区。The backup module is connected to the pool maintenance module, EBL module, and GBL module respectively, and is used to save the current erasure times, masks, and current EBL and GBL of all physical blocks to the backup area of the memory when the memory is unloaded normally.

较佳地,所述备份模块进一步用于,将每一个物理块的擦除次数实时存储于该物理块的物理页中。Preferably, the backup module is further configured to store the erasure count of each physical block in the physical page of the physical block in real time.

由上述的技术方案可见,本发明的这种磨损均衡方法和装置,通过将物理块划分为三池,并对现有的静态均衡部分进行了改进,使本发明的磨损均衡方法只在将冷池掩码的物理块进行垃圾回收时产生一次额外的磨损,相比现有技术降低了额外的磨损。另外,本发明通过EBL、GBL链表对垃圾回收、写入块分配等的控制,磨损均衡的动态部分得到了比现有技术更好的磨损均衡效果,并进一步通过禁止具有热池掩码的物理块进入EBL、GBL,使磨损比较多的物理块不会继续磨损,在得到更好的磨损均衡效果的同时,还减少了本发明磨损均衡方法搜索物理块时的速度,使本发明总体的执行效率和速度比现有技术也有提高。It can be seen from the above technical solution that the wear leveling method and device of the present invention divide the physical block into three pools, and improve the existing static equalization part, so that the wear leveling method of the present invention only divides the cold pool When the physical block of the mask is garbage collected, an additional wear is generated, which reduces the additional wear compared with the existing technology. In addition, the present invention controls garbage collection, write block allocation, etc. through the EBL and GBL linked lists, and the dynamic part of wear leveling obtains a better wear leveling effect than the prior art, and further prohibits the physical Blocks enter EBL and GBL, so that the physical blocks with more wear will not continue to wear, and while better wear leveling effects are obtained, the speed when the wear leveling method of the present invention is searched for physical blocks is also reduced, so that the overall execution of the present invention Efficiency and speed are also improved compared to the prior art.

附图说明 Description of drawings

图1为现有磨损均衡方法流程图;FIG. 1 is a flowchart of an existing wear leveling method;

图2为本发明实施例的磨损均衡方法总体流程图;FIG. 2 is an overall flowchart of a wear leveling method according to an embodiment of the present invention;

图3为本发明实施例的垃圾回收方法流程图;FIG. 3 is a flowchart of a garbage collection method according to an embodiment of the present invention;

图4为本发明实施例的磨损均衡方法中静态均衡部分的流程图;Fig. 4 is a flow chart of the static equalization part in the wear leveling method of the embodiment of the present invention;

图5为本发明实施例的磨损均衡方法总体思想流程图;FIG. 5 is a flow chart of the general thought of the wear leveling method according to the embodiment of the present invention;

图6为本发明实施例的磨损均衡装置结构示意图;6 is a schematic structural diagram of a wear leveling device according to an embodiment of the present invention;

图7为本发明实施例的池维护模块结构示意图。Fig. 7 is a schematic structural diagram of a pool maintenance module according to an embodiment of the present invention.

具体实施方式 Detailed ways

为使本发明的目的、技术方案及优点更加清楚明白,以下参照附图并举实施例,对本发明进一步详细说明。In order to make the object, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and examples.

本发明主要是根据每一个物理块的擦除次数,确定每一个物理块的池掩码;其中,对于不同擦除次数,物理块的掩码为冷池掩码CPM、普通池掩码NPM或热池掩码HPM(为方便描述,后文中将具有冷池掩码的物理块称为冷池块,将具有普通池掩码的物理块称为普通池块,将具有热池掩码的物理块称为热池块);在静态均衡时,当有池掩码为NPM的物理块的池掩码变为HPM时,将一个池掩码为CPM的物理块中的数据复制到所述池掩码变为HPM的物理块上,并将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。由于本发明对现有磨损均衡的静态均衡部分进行了改进,只产生了一次额外的磨损,即将池掩码为CPM的物理块进行垃圾回收时会产生一次擦除动作,所以相比现有技术降低了额外的磨损。The present invention mainly determines the pool mask of each physical block according to the erasing times of each physical block; wherein, for different times of erasing, the mask of the physical block is a cold pool mask CPM, a common pool mask NPM or Hot pool mask HPM (for convenience of description, physical blocks with cold pool masks are called cold pool blocks, physical blocks with common pool masks are called normal pool blocks, and physical blocks with hot pool masks are called The block is called a hot pool block); during static balancing, when the pool mask of a physical block with a pool mask of NPM changes to HPM, copy the data in a physical block with a pool mask of CPM to the pool The mask becomes the physical block of the HPM, and the physical block whose pool mask is the CPM is used as a garbage block for garbage collection. Since the present invention improves the static balance part of the existing wear leveling, only one additional wear is generated, that is, when the physical block whose pool mask is CPM is garbage collected, an erasure action will be generated, so compared with the prior art Additional wear is reduced.

另外,本发明还可以进一步改进现有磨损均衡的动态部分,根据物理块的擦除次数控制垃圾回收过程和写入块的分配过程,热池块不参与写入块的分配和垃圾块的回收,使得所以本发明的磨损均衡方法在执行时,所需搜索物理块的范围更小,速度更快。In addition, the present invention can further improve the dynamic part of the existing wear leveling, and control the garbage collection process and the allocation process of written blocks according to the erasure times of physical blocks, and the hot pool blocks do not participate in the allocation of written blocks and the recovery of garbage blocks , so that when the wear leveling method of the present invention is executed, the required search range of physical blocks is smaller and the speed is faster.

具体地,本发明的总体思想如图5所示,包括如下步骤:Specifically, the general idea of the present invention is shown in Figure 5, including the following steps:

步骤501,根据每一个物理块的擦除次数,确定每一个物理块的池掩码;其中,对于不同擦除次数,物理块的池掩码可以确定为冷池掩码CPM、普通池掩码NPM或热池掩码HPM。Step 501, determine the pool mask of each physical block according to the number of erasing times of each physical block; where, for different times of erasing, the pool mask of the physical block can be determined as cold pool mask CPM, common pool mask NPM or Hot Pool Mask HPM.

在本发明的磨损均衡方法中,对于每一个需要进行磨损均衡的物理块(以下简称块),共设置冷池、普通池和热池三种块属性,并采用池掩码加以标识和区分,池掩码可以采用两位二进制码形式,例如00表示该块属于冷池,01表示该块属于普通池,11表示该块属于热池。另外,每一个块记录其擦除次数,并确定一个参考擦除次数RECC(RECC的值等于所有块中擦除次数最小的块的擦除次数)和预设的表示冷热池之间间距的阈值(TH)用于确定物理块应当对应哪个池掩码,其中,TH为大于1的整数,擦除次数等于RECC的块为冷池掩码,擦除次数大于等于RECC+TH块为热池掩码,擦除次数为其它值的块为普通池掩码。池掩码会根据物理块的擦除次数变化实时修改,具体修改方法为:每次擦除次数改变以后,将改变后的擦除次数和RECC进行作差比较,如果结果为1,则修改当前池掩码为普通池掩码NPM,如果结果为TH,则修改当前池掩码为热池掩码HPM,其他结果则保持当前池掩码不变。In the wear leveling method of the present invention, for each physical block (hereinafter referred to as block) that needs to be wear leveled, three block attributes of cold pool, common pool and hot pool are set, and the pool mask is used to identify and distinguish, The pool mask can be in the form of a two-digit binary code. For example, 00 indicates that the block belongs to the cold pool, 01 indicates that the block belongs to the normal pool, and 11 indicates that the block belongs to the hot pool. In addition, each block records its erasure count, and determines a reference erasure count RECC (the value of RECC is equal to the erase count of the block with the smallest erasure count among all blocks) and a preset threshold representing the distance between hot and cold pools (TH) is used to determine which pool mask the physical block should correspond to, where TH is an integer greater than 1, the block whose erasure times is equal to RECC is a cold pool mask, and the block whose erasure times is greater than or equal to RECC+TH is a hot pool mask code, blocks with erasure counts of other values are common pool masks. The pool mask will be modified in real time according to the change of the number of erase times of the physical block. The specific modification method is: after each change of the number of erase times, compare the changed number of erase times with RECC. If the result is 1, modify the current The pool mask is the normal pool mask NPM, if the result is TH, modify the current pool mask to the hot pool mask HPM, and keep the current pool mask unchanged for other results.

步骤502,当有物理块的池掩码从NPM变为HPM时,将任一个池掩码为CPM的物理块中的数据复制到所述池掩码为HPM的物理块上;并将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。Step 502, when the pool mask of the physical block is changed from NPM to HPM, copy the data in the physical block whose pool mask is CPM to the physical block whose pool mask is HPM; and Physical blocks whose pool mask is CPM are garbage collected as garbage blocks.

本步骤是本发明磨损均衡的静态均衡部分,当有普通池块的擦除次数达到进入热池的标准,即擦除次数大于等于RECC+TH时(例如通过垃圾回收过程而被擦除数据的普通池块变为热池块时),从冷池中选择一个块,将该冷池块上的数据移动到该进入热池的块上,并回收该冷池块(垃圾回收过程可以采用现有的垃圾回收方法,也可以采用本发明改进的方法,本发明改进的垃圾回收方法在后文详述)。通过这一过程,可以使冷池块从冷数据中被释放出来,使之可以被重新写入数据而加快冷池块的磨损,达到更好的磨损均衡效果,同时,这一静态均衡过程只产生了一次额外磨损,即从冷池选出的块被擦除产生一次额外的磨损,而进入热池的块是正常垃圾回收过程的块,其数据擦除不是由本方法额外引起,所以比较双池算法,要少一次额外磨损。This step is the static balancing part of the wear leveling of the present invention, when the erasing times of the common pool blocks reach the standard for entering the hot pool, that is, when the times of erasing is greater than or equal to RECC+TH (for example, data erased by the garbage collection process When the ordinary pool block becomes a hot pool block), select a block from the cold pool, move the data on the cold pool block to the block that enters the hot pool, and recycle the cold pool block (the garbage collection process can use the current Some garbage collection methods can also adopt the improved method of the present invention, and the improved garbage collection method of the present invention will be described in detail later). Through this process, the cold pool block can be released from the cold data, so that it can be rewritten to speed up the wear of the cold pool block and achieve a better wear leveling effect. At the same time, this static balancing process only An additional wear is generated, that is, the blocks selected from the cold pool are erased to generate an additional wear, while the blocks entering the hot pool are blocks in the normal garbage collection process, and their data erasure is not caused by this method, so the comparison of double The pool algorithm requires one less additional wear.

进一步地,本发明还可以对现有技术的动态均衡部分进行改进,构建用于管理空白块的空白块链表EBL和用于管理垃圾块的垃圾块链表GBL,通过EBL控制为写入操作分配写入块过程中的空白块队列,通过GBL控制垃圾块回收过程中垃圾块的队列;其中,EBL和GBL均按照擦除次数升序排列(擦除次数小的块排列靠前,反之靠后,对于擦除次数相同的块,则可以先来的靠前,也可以随意排列;)链表中元素(EBL中为空白块,GBL中为垃圾块),从而保证优先回收擦除次数少的垃圾块,以及优先将擦除次数少的空白块作为写入块分配给写请求,达到良好的磨损均衡效果;且EBL和GBL会将热池块排除在外,不会有热池块进入EBL和GBL,从而能保持热池块不继续被擦除,进一步提高磨损均衡效果,并减小所需搜索物理块的范围,提高搜索速度。Further, the present invention can also improve the dynamic balance part of the prior art, construct a blank block linked list EBL for managing blank blocks and a garbage block linked list GBL for managing garbage blocks, and allocate write operations for write operations through the EBL. The queue of blank blocks in the process of entering blocks is controlled by GBL in the queue of garbage blocks in the process of garbage block recovery; among them, EBL and GBL are arranged in ascending order according to the number of erasures (blocks with a small number of erasures are arranged in the front, and vice versa, for Blocks with the same number of erasures can come first, or can be arranged at will;) elements in the linked list (blank blocks in EBL, garbage blocks in GBL), so as to ensure that garbage blocks with less erasure times are recycled first, And priority is given to assigning blank blocks with fewer erase times as write blocks to write requests to achieve a good wear leveling effect; and EBL and GBL will exclude hot pool blocks, and no hot pool blocks will enter EBL and GBL, thus It can keep the hot pool block from being erased, further improve the effect of wear leveling, reduce the range of physical blocks to be searched, and improve the search speed.

下面将举一些具体的例子,来说明本发明的磨损均衡算法,下文均以同时对现有技术的动态部分和静态部分改进为例:Some specific examples will be given below to illustrate the wear leveling algorithm of the present invention. The following are examples of improving the dynamic part and the static part of the prior art at the same time:

图2为本发明实施例的磨损均衡方法总体流程图,如图2所示,该方法包括如下步骤:Fig. 2 is an overall flowchart of a wear leveling method according to an embodiment of the present invention. As shown in Fig. 2, the method includes the following steps:

步骤201,获取磨损信息;磨损信息是指进行磨损均衡所需的信息,包括每一个物理块的擦除次数,每一个物理块的池掩码,以及EBL、GBL;如果存储器非第一次使用,这些磨损信息的当前值可以从存储器的备份区直接读取获得,如果第一次使用,则需要先创建磨损信息,如将所有块的擦除次数置0,为所有物理块标记池掩码、建立EBL、GBL等,池掩码的确定方法上文已经详述,这里不赘;其中,第一次使用时,所有块的擦除次数为0,所以RECC也为0,即所有块在第一次使用时均会确定为冷池掩码CPM。Step 201, obtain wear information; wear information refers to the information required for wear leveling, including the erasure times of each physical block, the pool mask of each physical block, and EBL, GBL; if the memory is not used for the first time , the current value of these wear information can be directly read from the backup area of the memory. If it is used for the first time, you need to create the wear information first, such as setting the erasure times of all blocks to 0, and marking the pool mask for all physical blocks , Establish EBL, GBL, etc. The method of determining the pool mask has been described in detail above, and will not be repeated here; among them, when it is used for the first time, the erasure times of all blocks is 0, so RECC is also 0, that is, all blocks are in It will be determined as the cold pool mask CPM when it is used for the first time.

对于是否第一次使用,可以通过查看存储器的备份区是否有备份的数据来判断,如果没有备份的数据,即说明是第一次使用,否则不是第一次使用。Whether it is used for the first time can be judged by checking whether there is backup data in the backup area of the memory, if there is no backup data, it means it is the first use, otherwise it is not the first time use.

另外,需要注意的是,如果存储器第一次使用,其初始化过程中还会包括坏块的搜索和处理过程,即找出所有的初始坏块;在找坏块的同时可以检测每一个块的状态,如果有数据,由于首次使用,这些数据对用户是无效的,那么在建立GBL、EBL时,可以把该块放入GBL等候擦除;如果没有数据,那么可以把该块放入EBL待用。其中,坏块由于不能使用,故不记入本发明中所述的所有物理块的范围内。In addition, it should be noted that if the memory is used for the first time, the initialization process will also include the search and processing of bad blocks, that is, to find out all the initial bad blocks; while looking for bad blocks, you can detect each block. state, if there is data, the data is invalid for the user due to the first use, then when establishing GBL and EBL, the block can be put into GBL and wait for erasure; if there is no data, then the block can be put into EBL for waiting use. Wherein, bad blocks are not included in the range of all physical blocks described in the present invention because they cannot be used.

如果存储器不是第一次使用,且在上次使用时不是正常卸载,那么在获取磨损信息时,获取到的GBL和EBL可能不正确,需要对GBL、EBL进行修正;具体地,可以从备份区载入最近一次正常卸载时备份的磨损信息,然后检查EBL中从链表头开始的EBL中每个块的存储状况,如果某个块已经非空,表明上次卸载之前这个块已经分配出去,因此应该从EBL中删除这个块。这个检查过程持续到碰到第一个空白块或者EBL为空为止。类似地,需要检查GBL的状况,从GBL链表头开始检测GBL中每个块的存储状况,如果某个块为空白块,表明上次卸载之前这个块已经被回收,因而应该从GBL删除并且放入EBL;这个检查过程持续到碰到第一个非空白块或者GBL为空为止。If the memory is not used for the first time and was not unloaded normally when it was used last time, the GBL and EBL obtained may be incorrect when obtaining the wear information, and the GBL and EBL need to be corrected; specifically, it can be obtained from the backup area Load the wear information backed up during the last normal unload, and then check the storage status of each block in the EBL starting from the head of the linked list in the EBL. If a block is not empty, it indicates that the block has been allocated before the last unload, so This block should be removed from the EBL. This checking process continues until the first blank block is encountered or the EBL is empty. Similarly, it is necessary to check the status of the GBL, starting from the head of the GBL linked list to detect the storage status of each block in the GBL. If a block is a blank block, it means that the block has been recycled before the last unloading, so it should be deleted from the GBL and placed in the GBL. into the EBL; this check continues until the first non-blank block is encountered or the GBL is empty.

步骤202,判断是否有写请求,若是,进入步骤203,否则进入步骤213;Step 202, determine whether there is a write request, if so, enter step 203, otherwise enter step 213;

步骤203,判断写入块是否已满?若是,则进入步骤204,否则进入步骤205;Step 203, judging whether the write block is full? If so, then enter step 204, otherwise enter step 205;

步骤204,分配EBL链表中的首元素为写入块;Step 204, assigning the first element in the EBL linked list as a write block;

步骤205,响应写请求;Step 205, responding to the write request;

步骤206,判断存储器可用空间是否小于预设的阈值,若是,进入步骤207,否则返回步骤202;Step 206, judging whether the available memory space is less than a preset threshold, if so, proceed to step 207, otherwise return to step 202;

步骤207,垃圾回收,具体过程后文详述;Step 207, garbage collection, the specific process will be described in detail later;

步骤208,判断回收的垃圾块在回收前是否为冷池块,若是,则进入步骤211,否则进入步骤209;Step 208, judging whether the recovered garbage block is a cold pool block before recycling, if so, then enter step 211, otherwise enter step 209;

步骤209;判断回收的垃圾块在回收后是否变为热池块(垃圾块回收时会擦除原来的数据,其擦除次数会加1,若加1后擦除次数达到RECC+TH,则认为该块回收后变为热池块),若是则进入步骤210,否则返回步骤202;Step 209; Judging whether the reclaimed garbage block becomes a hot pool block after reclaiming (the original data will be erased when the garbage block is reclaimed, and the number of times of erasing will be increased by 1, if the number of times of erasing after adding 1 reaches RECC+TH, then think that the block becomes a hot pool block after recycling), if so, enter step 210, otherwise return to step 202;

步骤210,静态均衡,进入步骤211;Step 210, static equalization, enter step 211;

步骤211,判断冷池是否为空,若是,则进入步骤212,否则返回步骤202;Step 211, judge whether the cold pool is empty, if so, then enter step 212, otherwise return to step 202;

步骤212,重构三池,返回步骤202。若冷池为空,则本发明的磨损均衡算法将无法继续,所以需要根据目前所有块中擦除次数最小的块的擦除次数值重新确定新的RECC,然后根据该新的RECC重新确定物理块的池掩码,从而维持三池的结构。Step 212, reconstruct the three pools, and return to step 202. If the cold pool is empty, the wear leveling algorithm of the present invention will not be able to continue, so it is necessary to re-determine the new RECC according to the erasure count value of the block with the smallest erasure times among all the blocks at present, and then re-determine the physical pool according to the new RECC. The pool mask of the block, thus maintaining the three-pool structure.

步骤213,判断存储器是否卸载,若是,进入步骤214,否则返回步骤202;Step 213, determine whether the memory is unloaded, if so, enter step 214, otherwise return to step 202;

步骤214,保存磨损信息,结束流程。Step 214, save the wear information, and end the process.

其中,步骤202~207是本发明的动态均衡部分,其中202、203、205和206与现有技术相同,这里不赘;步骤204中,从EBL中分配写入块的方式是从EBL链表的头元素开始顺序分配,因此能够保证擦除次数小的块可以优先分配给写请求,而步骤207则是本发明动态均衡部分的关键,通过改进了现有垃圾回收过程,使得本发明在垃圾回收过程也能产生磨损均衡效果,使本发明在动态磨损均衡的效果上大大优于现有技术;具体垃圾回收过程将在后文详述。Wherein, steps 202~207 are the dynamic balancing part of the present invention, wherein 202, 203, 205 and 206 are the same as the prior art, and are not repeated here; in step 204, the mode of distributing write blocks from the EBL is from the The header elements are allocated sequentially, so it can be guaranteed that blocks with a small number of erasures can be allocated to write requests first, and step 207 is the key to the dynamic balance part of the present invention. By improving the existing garbage collection process, the present invention can be used in garbage collection. The process can also produce a wear leveling effect, so that the present invention is much better than the prior art in terms of the dynamic wear leveling effect; the specific garbage collection process will be described in detail later.

步骤208~210为静态均衡部分,其中步骤208和209用于判定是否需要进行静态均衡,实际上本发明中静态均衡的触发是在普通池掩码的物理块的池掩码变为热池掩码时,步骤208和209分别用于判断池掩码变化的物理块在变化前的池掩码,以及变化后的池掩码,这两个步骤的先后顺序是可以交换的,不影响最终的判断结果,步骤210的静态均衡具体流程将在后文详述。Steps 208-210 are the static equalization part, in which steps 208 and 209 are used to determine whether static equalization is required. In fact, the trigger of static equalization in the present invention is that the pool mask of the physical block of the normal pool mask changes to the hot pool mask. When coding, steps 208 and 209 are used to judge the pool mask of the physical block before the pool mask change and the pool mask after the change respectively. The order of these two steps can be exchanged without affecting the final As a result of the judgment, the specific process of static equalization in step 210 will be described in detail later.

步骤213和214和现有正常卸载过程相似,这里不赘,其区别只不过在存储磨损信息时,存储的是EBL和GBL以及所有块的擦除次数和SLWM的信息。另外,每一个物理块还会在其物理页中的冗余区保存该物理块的擦除次数。Steps 213 and 214 are similar to the existing normal unloading process and are not repeated here. The difference is that when storing wear information, EBL and GBL, erasure times of all blocks and SLWM information are stored. In addition, each physical block also saves the erasing times of the physical block in the redundant area of its physical page.

下面将详细描述本发明动态均衡部分的垃圾回收过程:The garbage collection process of the dynamic balancing part of the present invention will be described in detail below:

实际上垃圾回收包括两个部分,即普通垃圾回收和强制垃圾回收;普通垃圾回收是指在检测到有垃圾块产生时(如果一个数据被更新,那么它的旧版本被标记为垃圾,当一个块上的数据全部标记为垃圾时,该块为垃圾块)回收垃圾块的过程,这一过程在现有技术中是直接将垃圾块上的数据擦除并加入空白块队列末尾,而在本发明中,则不是立即擦除垃圾块上的数据,而是先将其插入GBL中待用,只在EBL中的空白块数量小于预设的阈值时,再从GBL中选择一个垃圾块,擦除数据后插入EBL中;在EBL中,元素按照擦除次数的升序排列,并在分配写入块时,始终分配头元素;GBL对垃圾块的排列和分配方法与EBL相同,从而保证擦除次数较少的块能够被优先擦除利用,而且对于标记为热池的物理块,即使其已经变为垃圾块,也不进行回收的操作,即不将该垃圾块插入GBL。普通垃圾回收中检测垃圾块的动作可以以一定的时间间隔重复执行,也可以固定在某个动作之后进行,例如在步骤205的响应写请求完成后进行。而强制垃圾回收(如步骤207)只在存储器的可用空间小于预设的阈值(非阈值TH)时进行,具体流程如图3所示,包括如下步骤:In fact, garbage collection includes two parts, namely ordinary garbage collection and mandatory garbage collection; ordinary garbage collection refers to when a garbage block is detected (if a data is updated, then its old version is marked as garbage, when a When all the data on the block is marked as garbage, the block is a garbage block) the process of reclaiming the garbage block, this process is to directly erase the data on the garbage block and add it to the end of the blank block queue in the prior art, but in this In the invention, instead of immediately erasing the data on the garbage block, it is first inserted into the GBL for use. Only when the number of blank blocks in the EBL is less than the preset threshold, a garbage block is selected from the GBL and erased. Insert into EBL after removing data; in EBL, elements are arranged in ascending order of erasure times, and when allocating write blocks, always allocate head elements; GBL arranges and allocates garbage blocks in the same way as EBL, thus ensuring erasure Blocks with fewer times can be erased and utilized first, and for physical blocks marked as hot pools, even if they have become garbage blocks, they will not be recycled, that is, the garbage blocks will not be inserted into the GBL. The action of detecting garbage blocks in ordinary garbage collection can be performed repeatedly at certain time intervals, or can be performed after a certain action, for example, after the response write request in step 205 is completed. And mandatory garbage collection (such as step 207) is only carried out when the available space of the memory is less than the preset threshold (non-threshold TH), and the specific process is as shown in Figure 3, including the following steps:

步骤301,判断GBL是否非空,若是,进入步骤302,否则进入步骤303;Step 301, determine whether the GBL is non-empty, if so, enter step 302, otherwise enter step 303;

步骤302,回收GBL中首元素,并进入步骤306;Step 302, recover the first element in the GBL, and enter step 306;

步骤303,在冷池和普通池中找出垃圾最多且擦除次数最少的块;Step 303, find the block with the most garbage and the least number of erasures in the cold pool and the common pool;

步骤304,将该块上的有效数据写入当前分配的写入块中;Step 304, writing the valid data on the block into the currently allocated write block;

步骤305,将该块插入GBL,返回步骤302。Step 305, insert the block into the GBL, and return to step 302.

步骤306,将回收的垃圾块插入EBL,结束流程。Step 306, insert the recovered garbage block into the EBL, and end the process.

随着上述动态均衡的进行,一些块离开了冷池,而一些块由于写入的数据为冷数据(如系统文件)长时间不更新的缘故停留在了冷池,对于这些长时间停留在冷池的块可以通过本发明的静态均衡过程来加速其磨损,从而提高磨损均衡的效果,具体的方法如图4所示,包括下步骤:With the progress of the above dynamic balance, some blocks leave the cold pool, and some blocks stay in the cold pool because the written data is cold data (such as system files) and are not updated for a long time. For these blocks that stay in the cold pool for a long time The block of the pool can accelerate its wear through the static equalization process of the present invention, thereby improving the effect of wear equalization. The specific method is shown in Figure 4, including the following steps:

步骤401,找出一个冷池块;这个冷池块可以是随机寻找到的任意一个冷池块;也可以是按照一定的规则如找出冷池块上保存的数据的最后修改时间最早的冷池块。Step 401, find a cold pool block; this cold pool block can be any cold pool block found at random; it can also be the earliest cold pool block with the earliest last modification time of the data stored on the cold pool block according to certain rules. pool block.

步骤402,将该冷池块的数据复制到进入热池的垃圾块上;Step 402, copying the data of the cold pool block to the garbage block entering the hot pool;

步骤403,将上述找出的冷池块插入GBL链表,可以插入GBL的首位置,或者按照GBL的排列规则插入。Step 403, insert the cold pool block found above into the GBL linked list, which can be inserted into the first position of the GBL, or inserted according to the arrangement rules of the GBL.

上述介绍的本发明磨损均衡方法的实施例只是本发明的一个较佳的实施例,如果仅实现上述静态部分,则不需要建立EBL和GBL,与EBL、GBL相关的操作也无需执行,可以仍然沿用现有的空白块队列和垃圾回收过程;但如果同时实现上述动态部分和静态部分,除了能够加快执行算法时的物理块搜索速度外,还能够得到更好的磨损均衡效果,经过实验,本发明同时实现上述静态部分和动态部分时,可以将磨损的不均衡程度严格地控制在TH2/4(即预设阈值TH的平方除以4的值)以内,有效地延长了非易失性存储器的使用寿命。The above-described embodiment of the wear leveling method of the present invention is only a preferred embodiment of the present invention. If only the above-mentioned static part is implemented, EBL and GBL do not need to be established, and operations related to EBL and GBL do not need to be executed. The existing blank block queue and garbage collection process are used; however, if the above dynamic part and static part are implemented at the same time, in addition to speeding up the physical block search speed when executing the algorithm, a better wear leveling effect can be obtained. After experiments, this When the invention implements the above-mentioned static part and dynamic part at the same time, the unbalanced degree of wear can be strictly controlled within TH 2 /4 (that is, the value of the square of the preset threshold TH divided by 4), effectively extending the non-volatile The lifespan of the memory.

另外,本发明还提供了一种磨损均衡装置,如图6所示,该装置包括:In addition, the present invention also provides a wear leveling device, as shown in Figure 6, the device includes:

池维护模块601,用于根据每一个物理块的擦除次数,确定每一个物理块的池掩码;其中,对于不同擦除次数,物理块的池掩码为冷池掩码CPM、普通池掩码NPM或热池掩码HPM;The pool maintenance module 601 is used to determine the pool mask of each physical block according to the erasing times of each physical block; wherein, for different times of erasing, the pool mask of the physical block is cold pool mask CPM, common pool mask NPM or hotpool mask HPM;

静态均衡模块602,与所述池维护模块601相连,用于在有物理块的池掩码从NPM变为HPM时,将任一个池掩码为CPM的物理块中的数据复制到所述池掩码为HPM的物理块上;Static balancing module 602, connected to the pool maintenance module 601, is used to copy the data in the physical block whose pool mask is CPM to the pool when the pool mask of the physical block changes from NPM to HPM On the physical block masked as HPM;

垃圾回收模块603,与所述静态均衡模块602相连,用于将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。The garbage collection module 603 is connected to the static balance module 602, and is configured to use the physical block whose pool mask is CPM as a garbage block for garbage collection.

其中,所述池维护模块如图7所示,包括:Wherein, the pool maintenance module is as shown in Figure 7, including:

确定单元701,用于在物理块的擦除次数等于RECC的值时,确定其池掩码为冷池掩码;擦除次数大于等于RECC+TH的值时为热池掩码;擦除次数为其他值时为普通池掩码;Determining unit 701 is used to determine that the pool mask is a cold pool mask when the number of erasing times of the physical block is equal to the value of RECC; it is a hot pool mask when the number of erasing times is greater than or equal to the value of RECC+TH; the number of times of erasing Normal pool mask for other values;

其中,所述RECC是参考擦除次数计数器,其值等于所有物理块中擦除次数最小的物理块的擦除次数;所述TH为预设的阈值,其取值为大于1的正整数,它表示冷池和热池的间距。Wherein, the RECC is a reference erasure count counter, whose value is equal to the erasure count of the physical block with the smallest erasure count among all physical blocks; the TH is a preset threshold, and its value is a positive integer greater than 1, It represents the distance between the cold pool and the hot pool.

较佳地,该装置可以进一步包括:Preferably, the device may further include:

EBL模块604,维护用于管理空白块的空白块链表EBL;将所述EBL中的空白块按照擦除次数值升序排列;当需要为写请求分配空白块时,将所述EBL中的首个空白块作为写入块分配给所述写请求。The EBL module 604 maintains a blank block linked list EBL for managing blank blocks; arranges the blank blocks in the EBL in ascending order according to the number of erasures; when it is necessary to allocate a blank block for a write request, the first A blank block is allocated to the write request as a write block.

另外,EBL模块604还可以进一步禁止池掩码为HPM的空白块进入,从而保护热池块不会进一步磨损。In addition, the EBL module 604 can further prohibit the entry of the blank blocks whose pool mask is HPM, so as to protect the hot pool blocks from being further worn out.

较佳地,该装置还可以进一步包括:Preferably, the device can further include:

GBL模块605,与所述垃圾回收模块603及EBL模块604分别相连,维护用于管理垃圾块的垃圾块链表GBL;将所述GBL中的垃圾块按照擦除次数值升序排列。The GBL module 605 is connected to the garbage collection module 603 and the EBL module 604 respectively, and maintains a garbage block linked list GBL for managing garbage blocks; arranges the garbage blocks in the GBL in ascending order according to the number of erasures.

另外,GBL模块605也可以进一步禁止池掩码为HPM的垃圾块进入,从而保护热池块不会进一步磨损。In addition, the GBL module 605 may further prohibit the entry of garbage blocks whose pool mask is HPM, so as to protect the hot pool blocks from further wear.

当所述EBL模块604维护的EBL中的空白块数量小于预设的阈值时,GBL模块605还可以进一步用于判断GBL是否非空;When the number of blank blocks in the EBL maintained by the EBL module 604 is less than a preset threshold, the GBL module 605 can further be used to determine whether the GBL is not empty;

若GBL非空,则擦除所述GBL中首个垃圾块的数据,使之变为空白块;并将该空白块插入所述EBL模块604维护的EBL中;If the GBL is not empty, then erase the data of the first garbage block in the GBL to make it a blank block; and insert the blank block into the EBL maintained by the EBL module 604;

若GBL已空,则先将所有池掩码为冷池掩码和普通池掩码的物理块中垃圾数据最多且擦除次数最少的物理块中的有效数据写入到当前分配的写入块上,并将该垃圾数据最多且擦除次数最少的物理块插入GBL;再擦除所述GBL中首个垃圾块的数据,使之变为空白块;并将该空白块插入EBL中。If the GBL is empty, first write the valid data in the physical block with the most garbage data and the least number of erasures among the physical blocks whose pool mask is cold pool mask and normal pool mask to the currently allocated write block on, and insert the physical block with the most garbage data and the least number of times of erasure into the GBL; then erase the data of the first garbage block in the GBL to make it a blank block; and insert the blank block into the EBL.

所述垃圾回收模块603具体用于将掩码为冷池掩码和普通池掩码的垃圾块插入所述GBL模块维护的GBL中。The garbage collection module 603 is specifically configured to insert garbage blocks masked as cold pool masks and common pool masks into the GBL maintained by the GBL module.

较佳地,所述池维护模块601可以进一步包括:Preferably, the pool maintenance module 601 may further include:

当前值确定单元702,与所述确定单元701相连,用于在存储器为第一次使用时,置所有物理块的当前的擦除次数为0;所有物理块当前的池掩码为冷池掩码。The current value determining unit 702 is connected with the determining unit 701, and is used to set the current erasure times of all physical blocks to 0 when the memory is used for the first time; the current pool mask of all physical blocks is a cold pool mask code.

或者,所述池维护模块601可以进一步包括:Alternatively, the pool maintenance module 601 may further include:

当前值确定单元702,与所述确定单元701相连,用于在存储器不是第一次使用,且上一次使用后正常卸载时,从存储器的备份区读取得到所有物理块当前的擦除次数、池掩码,以及EBL、GBL。The current value determination unit 702 is connected with the determination unit 701, and is used to read the current erasure times, the current erasure times, Pool mask, and EBL, GBL.

或者,所述池维护模块601可以进一步包括:Alternatively, the pool maintenance module 601 may further include:

当前值确定单元702,与所述确定单元701相连,用于在存储器不是第一次使用,且上一次使用后没有正常卸载时,The current value determining unit 702 is connected to the determining unit 701, and is used for when the memory is not used for the first time and has not been unloaded normally after the last use,

从存储器的备份区载入最近一次正常卸载时备份的所有物理块当前的擦除次数、池掩码,以及EBL、GBL;Load the current erasure count, pool mask, EBL, GBL of all physical blocks backed up during the last normal unload from the backup area of the memory;

所述EBL模块604从EBL中首个物理块开始,逐个检测EBL中物理块的存储状况,如果物理块已非空白块,则从EBL中删除这个物理块;检测持续到检测到物理块为空白块或者EBL为空为止;Described EBL module 604 starts from the first physical block in the EBL, detects the storage status of the physical blocks in the EBL one by one, if the physical block is not a blank block, then deletes this physical block from the EBL; detection continues until the physical block is detected to be blank until the block or EBL is empty;

所述GBL模块605从GBL中首个物理块开始,逐个检查GBL中物理块的存储状况,如果物理块已经为空白块,则从GBL中删除这个物理块,并将这个物理块插入所述EBL维护的EBL;检测持续到检测到物理块为垃圾块或者GBL为空为止。The GBL module 605 starts from the first physical block in the GBL, checks the storage status of the physical blocks in the GBL one by one, if the physical block is a blank block, deletes the physical block from the GBL, and inserts the physical block into the EBL Maintained EBL; detection continues until either the physical block is detected as a garbage block or the GBL is empty.

较佳地,所述池维护模块601可以进一步包括:Preferably, the pool maintenance module 601 may further include:

重建单元703,与所述确定单元701相连,当所有物理块的池掩码均不再是冷池掩码时;根据当前所有物理块中擦除次数最小的物理块的擦除次数修正RECC的值,并根据修正后的RECC重新确定所有物理块的池掩码。Reconstruction unit 703, connected to the determination unit 701, when the pool masks of all physical blocks are no longer cold pool masks; correct the RECC according to the erasure count of the physical block with the smallest erasure count among all current physical blocks value, and re-determine the pool mask of all physical blocks according to the revised RECC.

另外,该装置还可以进一步包括:In addition, the device may further include:

备份模块606,与所述池维护模块601、EBL模块604、GBL模块605分别相连,用于当存储器正常卸载时,保存所有物理块当前的擦除次数、掩码以及当前的EBL、GBL到存储器的备份区。The backup module 606 is connected to the pool maintenance module 601, the EBL module 604, and the GBL module 605 respectively, and is used to save the current erasure times, masks, and current EBL and GBL of all physical blocks to the memory when the memory is unloaded normally backup area.

较佳地,所述备份模块606可以进一步用于,将每一个物理块的擦除次数实时存储于该物理块的物理页中。Preferably, the backup module 606 can be further configured to store the erasure count of each physical block in the physical page of the physical block in real time.

由上述的实施例可见,本发明的这种磨损均衡方法和装置,通过将物理块划分为三池,并对现有的静态均衡部分进行了改进,使本发明的磨损均衡方法只在将具有冷池掩码的物理块进行垃圾回收时产生一次额外的磨损,相比现有技术降低了额外的磨损。It can be seen from the above-mentioned embodiments that the wear leveling method and device of the present invention divide the physical block into three pools and improve the existing static equalization part, so that the wear leveling method of the present invention only has cold When the physical block of the pool mask is garbage collected, an additional wear is generated, which reduces the additional wear compared with the existing technology.

Claims (26)

1.一种磨损均衡方法,其特征在于,该方法包括:  1. A wear leveling method, characterized in that the method comprises: 根据每一个物理块的擦除次数,确定每一个物理块的池掩码;  Determine the pool mask of each physical block according to the erasure times of each physical block; 其中,对于不同擦除次数,物理块的池掩码确定为冷池掩码CPM、普通池掩码NPM或热池掩码HPM,具体包括:物理块的擦除次数等于RECC的值时,确定物理块的池掩码为CPM;擦除次数大于等于RECC+TH的值时确定物理块的池掩码为HPM;擦除次数为其他值时确定物理块的池掩码为NPM;其中,所述RECC是参考擦除次数计数器,其值等于所有物理块中擦除次数最小的物理块的擦除次数;所述TH为预设的阈值,其取值为大于1的正整数; Wherein, for different erasing times, the pool mask of the physical block is determined as a cold pool mask CPM, a common pool mask NPM or a hot pool mask HPM, specifically including: when the erasing times of the physical block is equal to the value of RECC, determine The pool mask of the physical block is CPM; the pool mask of the physical block is determined to be HPM when the number of erasures is greater than or equal to the value of RECC+TH; the pool mask of the physical block is determined to be NPM when the number of erasures is other values; The RECC is a reference erasure count counter, whose value is equal to the erasure count of the physical block with the smallest erasure count among all physical blocks; the TH is a preset threshold, and its value is a positive integer greater than 1; 当有物理块的池掩码从NPM变为HPM时,将任一个池掩码为CPM的物理块中的数据复制到所述池掩码为HPM的物理块上,并将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。  When the pool mask of a physical block changes from NPM to HPM, copy the data in any physical block whose pool mask is CPM to the physical block whose pool mask is HPM, and set the pool mask Physical blocks for CPM are garbage collected as garbage blocks. the 2.如权利要求1所述的磨损均衡方法,其特征在于,该方法进一步包括:  2. The wear leveling method according to claim 1, characterized in that the method further comprises: 建立用于管理空白块的空白块链表EBL,所述EBL中的空白块按照其擦除次数升序排列;  Establish a blank block chain list EBL for managing blank blocks, and the blank blocks in the EBL are arranged in ascending order according to their erasure times; 当需要为写请求分配空白块时,将所述EBL中的首个空白块作为写入块分配给所述写请求。  When a blank block needs to be allocated for a write request, the first blank block in the EBL is allocated to the write request as a write block. the 3.如权利要求2所述的磨损均衡方法,其特征在于,所述EBL不允许池掩码为HPM的空白块进入。  3. The wear leveling method according to claim 2, wherein the EBL does not allow a blank block whose pool mask is HPM to enter. the 4.如权利要求2所述的磨损均衡方法,其特征在于,该方法进一步包括:  4. The wear leveling method according to claim 2, characterized in that the method further comprises: 建立用于管理垃圾块的垃圾块链表GBL,所述GBL中的垃圾块按照擦除次数值升序排列。  A garbage block linked list GBL for managing garbage blocks is established, and the garbage blocks in the GBL are arranged in ascending order of erasure times. the 5.如权利要求4所述的磨损均衡方法,其特征在于,所述GBL不允许池 掩码为HPM的垃圾块进入。  5. wear leveling method as claimed in claim 4, is characterized in that, described GBL does not allow pool mask to enter for the garbage piece of HPM. the 6.如权利要求5所述的磨损均衡方法,其特征在于,当所述EBL中的空白块数量小于预设的阈值时,进行如下所述的垃圾回收过程:  6. The wear leveling method according to claim 5, wherein when the number of blank blocks in the EBL is less than a preset threshold, the following garbage collection process is performed: 如果GBL非空,则擦除所述GBL中首个垃圾块的数据,使之变为空白块,并将该空白块插入EBL中;  If the GBL is non-empty, then erase the data of the first garbage block in the GBL to make it a blank block, and insert the blank block into the EBL; 如果GBL已空,则把所有掩码为CPM和NPM的物理块中垃圾数据量最多而且擦除次数最少的物理块的有效数据写入到当前分配的写入块上,并将该垃圾数据最多且擦除次数最少的物理块插入GBL;擦除所述GBL中首个垃圾块的数据,使之变为空白块,并将该空白块插入EBL中。  If the GBL is empty, write the effective data of the physical block with the largest amount of garbage data and the least number of erasures among all physical blocks masked as CPM and NPM to the currently allocated write block, and write the garbage data with the largest amount of garbage data. And the physical block with the least erasing times is inserted into the GBL; the data of the first garbage block in the GBL is erased to make it a blank block, and the blank block is inserted into the EBL. the 7.如权利要求5所述的磨损均衡方法,其特征在于,所述垃圾回收包括:  7. The wear leveling method according to claim 5, wherein the garbage collection comprises: 将池掩码为CPM和NPM的垃圾块插入GBL中。  Insert garbage blocks with pool masks CPM and NPM into the GBL. the 8.如权利要求1所述的磨损均衡方法,其特征在于,若存储器为第一次使用,在执行所述根据每一个物理块的擦除次数,确定每一个物理块的池掩码的步骤之前,置所有物理块的当前的擦除次数为0;所有物理块当前的池掩码为CPM。  8. The wear leveling method according to claim 1, wherein, if the memory is used for the first time, the step of determining the pool mask of each physical block according to the erasure times of each physical block is performed Before, set the current erasure count of all physical blocks to 0; the current pool mask of all physical blocks is CPM. the 9.如权利要求4所述的磨损均衡方法,其特征在于,若存储器不是第一次使用,且上一次使用后正常卸载时,在执行所述根据每一个物理块的擦除次数,确定每一个物理块的池掩码的步骤之前,从存储器的备份区读取得到所有物理块当前的擦除次数、池掩码,以及EBL、GBL。  9. The wear leveling method according to claim 4, wherein if the memory is not used for the first time and is normally unloaded after the last use, when performing the erasing times according to each physical block, determine Before the step of the pool mask of a physical block, the current erasure times, pool mask, EBL, and GBL of all physical blocks are read from the backup area of the memory. the 10.如权利要求4所述的磨损均衡方法,其特征在于,若存储器不是第一次使用,且上一次使用后没有正常卸载时,在执行所述根据每一个物理块的擦除次数,确定每一个物理块的池掩码的步骤之前,  10. The wear leveling method according to claim 4, wherein, if the memory is not used for the first time and has not been unloaded normally after the last use, when performing the erasing times according to each physical block, determine Before the step of the pool mask of each physical block, 从存储器的备份区载入最近一次正常卸载时备份的所有物理块的擦除次 数、池掩码,以及EBL、GBL;  Load the erasure times, pool mask, and EBL, GBL of all physical blocks backed up during the latest normal unloading from the backup area of the memory; 从EBL中首个物理块开始,逐个检测EBL中物理块的存储状况,如果物理块已非空白块,则从EBL中删除这个物理块;检测持续到检测到物理块为空白块或者EBL为空为止;  Starting from the first physical block in the EBL, check the storage status of the physical blocks in the EBL one by one. If the physical block is not a blank block, delete the physical block from the EBL; the detection continues until the physical block is detected as a blank block or the EBL is empty. so far; 从GBL中首个物理块开始,逐个检查GBL中物理块的存储状况,如果物理块已经为空白块,则从GBL中删除这个物理块,并将这个物理块插入EBL;检测持续到检测到物理块为垃圾块或者GBL为空为止。  Starting from the first physical block in the GBL, check the storage status of the physical blocks in the GBL one by one. If the physical block is already a blank block, delete the physical block from the GBL and insert the physical block into the EBL; the detection continues until the physical block is detected. until the block is a garbage block or the GBL is empty. the 11.如权利要求1所述的磨损均衡方法,其特征在于,若所有物理块的池掩码均不再是CPM;则根据当前所有物理块中擦除次数最小的物理块的擦除次数修正RECC的值,并根据修正后的RECC重新确定所有物理块的池掩码。  11. The wear leveling method according to claim 1, wherein, if the pool masks of all physical blocks are no longer CPM; then correct according to the number of erasures of the physical block with the smallest number of erasures in all current physical blocks RECC value, and re-determine the pool mask of all physical blocks according to the revised RECC. the 12.如权利要求4所述的磨损均衡方法,其特征在于,该方法进一步包括:当存储器正常卸载时,保存所有物理块当前的擦除次数、池掩码以及当前的EBL、GBL到存储器的备份区。  12. The wear leveling method according to claim 4, characterized in that the method further comprises: when the memory is unloaded normally, saving the current erasure times, pool masks, and current EBL and GBL of all physical blocks to the memory backup area. the 13.如权利要求12所述的磨损均衡方法,其特征在于,每一个物理块的擦除次数还实时存储于该物理块的物理页中。  13. The wear leveling method according to claim 12, wherein the erasure count of each physical block is also stored in a physical page of the physical block in real time. the 14.一种磨损均衡装置,其特征在于,该装置包括:  14. A wear leveling device, characterized in that the device comprises: 池维护模块,用于根据每一个物理块的擦除次数,确定每一个物理块的池掩码;其中,对于不同擦除次数,物理块的池掩码为冷池掩码CPM、普通池掩码NPM或热池掩码HPM;所述池维护模块包括:确定单元,用于在物理块的擦除次数等于RECC的值时,确定其池掩码为CPM;擦除次数大于等于RECC+TH的值时为HPM;擦除次数为其他值时为NPM;其中,所述RECC是参考擦除次数计数器,其值等于所有物理块中擦除次数最小的物理块的擦除次数;所述TH为预设的阈值,其取值为大于1的正整数;  The pool maintenance module is used to determine the pool mask of each physical block according to the number of erasing times of each physical block; wherein, for different times of erasing, the pool mask of the physical block is a cold pool mask CPM, a common pool mask Code NPM or hot pool mask HPM; The pool maintenance module includes: a determination unit, used to determine that the pool mask is CPM when the number of erasing times of the physical block is equal to the value of RECC; the number of times of erasing is greater than or equal to RECC+TH When the value is HPM; when the number of erasures is other values, it is NPM; wherein, the RECC is a reference erasure count counter, and its value is equal to the number of erasures of the physical block with the smallest number of erasures in all physical blocks; the TH is a preset threshold, and its value is a positive integer greater than 1; 静态均衡模块,与所述池维护模块相连,用于在当有物理块的池掩码从NPM变为HPM时,将任一个池掩码为CPM的物理块中的数据复制到所述池掩码为HPM的物理块上;  A static balance module, connected to the pool maintenance module, is used to copy the data in any physical block whose pool mask is CPM to the pool mask when the pool mask of the physical block changes from NPM to HPM On the physical block coded as HPM; 垃圾回收模块,与所述静态均衡模块相连,用于将所述池掩码为CPM的物理块作为垃圾块进行垃圾回收。  The garbage collection module is connected with the static balance module, and is used for performing garbage collection on the physical block whose pool mask is CPM as a garbage block. the 15.如权利要求14所述的磨损均衡装置,其特征在于,该装置进一步包括:  15. The wear leveling device of claim 14, wherein the device further comprises: EBL模块,维护用于管理空白块的空白块链表EBL;将所述EBL中的空白块按照擦除次数值升序排列;当需要为写请求分配空白块时,将所述EBL中的首个空白块作为写入块分配给所述写请求。  The EBL module maintains the blank block linked list EBL for managing blank blocks; arranges the blank blocks in the EBL in ascending order according to the number of erasures; when it is necessary to allocate a blank block for a write request, the first blank in the EBL is allocated A block is allocated to the write request as a write block. the 16.如权利要求15所述的磨损均衡装置,其特征在于,所述EBL模块不允许池掩码为HPM的空白块进入。  16 . The wear leveling device according to claim 15 , wherein the EBL module does not allow blank blocks whose pool mask is HPM to enter. the 17.如权利要求15所述的磨损均衡装置,其特征在于,该装置进一步包括:  17. The wear leveling device of claim 15, further comprising: GBL模块,与所述垃圾回收模块及EBL模块分别相连,维护用于管理垃圾块的垃圾块链表GBL;将所述GBL中的垃圾块按照擦除次数值升序排列。  The GBL module is connected to the garbage collection module and the EBL module respectively, maintains a garbage block linked list GBL for managing garbage blocks, and arranges the garbage blocks in the GBL in ascending order according to the number of erasures. the 18.如权利要求17所述的磨损均衡装置,其特征在于,所述GBL模块不允许池掩码为HPM的垃圾块进入。  18. The wear leveling device according to claim 17, wherein the GBL module does not allow garbage blocks whose pool mask is HPM to enter. the 19.如权利要求18所述的磨损均衡装置,其特征在于,所述GBL模块进一步用于,当存储器中的可用空间小于预设的阈值时;  19. The wear leveling device according to claim 18, wherein the GBL module is further configured to, when the available space in the memory is less than a preset threshold; 若GBL非空,则擦除所述GBL中首个垃圾块的数据,使之变为空白块;并将该空白块插入所述EBL模块维护的EBL中;  If GBL is non-empty, then erase the data of the first garbage block in the GBL to make it a blank block; and insert this blank block into the EBL maintained by the EBL module; 若GBL已空,则先将所有池掩码为CPM和NPM的物理块中垃圾数据最多且擦除次数最少的物理块中的有效数据写入到当前分配的写入块上,并将该垃圾数据最多且擦除次数最少的物理块插入GBL;再擦除所述GBL中首个垃圾块的数据,使之变为空白块;并将该空白块插入EBL中。  If the GBL is empty, first write the valid data in the physical block with the most garbage data and the least number of erasures among the physical blocks whose pool masks are CPM and NPM to the currently allocated write block, and write the garbage Insert the physical block with the most data and the least erasure times into the GBL; then erase the data of the first garbage block in the GBL to make it a blank block; and insert the blank block into the EBL. the 20.如权利要求17所述的磨损均衡装置,其特征在于,所述垃圾回收模块具体用于将池掩码为CPM和NPM的垃圾块插入所述GBL模块维护的GBL中。  20. The wear leveling device according to claim 17, wherein the garbage collection module is specifically configured to insert the garbage blocks whose pool masks are CPM and NPM into the GBL maintained by the GBL module. the 21.如权利要求14所述的磨损均衡装置,其特征在于,所述池维护模块进一步包括:  21. The wear leveling device of claim 14, wherein the pool maintenance module further comprises: 当前值确定单元,与所述确定单元相连,用于在存储器为第一次使用时,置所有物理块的当前的擦除次数为0;所有物理块当前的池掩码为CPM。  The current value determining unit is connected with the determining unit, and is used to set the current erasure times of all physical blocks to 0 when the memory is used for the first time; the current pool mask of all physical blocks is CPM. the 22.如权利要求17所述的磨损均衡装置,其特征在于,所述池维护模块进一步包括:  22. The wear leveling device of claim 17, wherein the pool maintenance module further comprises: 当前值确定单元,与所述确定单元相连,用于在存储器不是第一次使用,且上一次使用后正常卸载时,从存储器的备份区读取得到所有物理块当前的擦除次数、池掩码,以及EBL、GBL。  The current value determination unit is connected with the determination unit, and is used to read the current erasure times and pool mask of all physical blocks from the backup area of the memory when the memory is not used for the first time and is normally unloaded after the last use. Code, and EBL, GBL. the 23.如权利要求17所述的磨损均衡装置,其特征在于,所述池维护模块进一步包括:  23. The wear leveling device of claim 17, wherein the pool maintenance module further comprises: 当前值确定单元,与所述确定单元相连,用于在存储器不是第一次使用,且上一次使用后没有正常卸载时,  The current value determination unit is connected to the determination unit, and is used for when the memory is not used for the first time and has not been unloaded normally after the last use, 从存储器的备份区载入最近一次正常卸载时备份的所有物理块当前的擦除次数、池掩码,以及EBL、GBL;  Load the current erasure count, pool mask, EBL, GBL of all physical blocks backed up during the last normal unload from the backup area of the memory; 所述EBL模块从EBL中首个物理块开始,逐个检测EBL中物理块的存储 状况,如果物理块已非空白块,则从EBL中删除这个物理块;检测持续到检测到物理块为空白块或者EBL为空为止;  Described EBL module starts from the first physical block in the EBL, detects the storage situation of the physical block in the EBL one by one, if the physical block is not a blank block, then deletes this physical block from the EBL; detection continues until the physical block is detected as a blank block Or until the EBL is empty; 所述GBL模块从GBL中首个物理块开始,逐个检查GBL中物理块的存储状况,如果物理块已经为空白块,则从GBL中删除这个物理块,并将这个物理块插入所述EBL维护的EBL;检测持续到检测到物理块为垃圾块或者GBL为空为止。  The GBL module starts from the first physical block in the GBL, checks the storage status of the physical blocks in the GBL one by one, if the physical block is already a blank block, deletes the physical block from the GBL, and inserts the physical block into the EBL for maintenance EBL; the detection continues until the physical block is detected as a garbage block or the GBL is empty. the 24.如权利要求14所述的磨损均衡装置,其特征在于,所述池维护模块进一步包括:  24. The wear leveling device of claim 14, wherein the pool maintenance module further comprises: 重建单元,与所述确定单元相连,当所有物理块的池掩码均不再是CPM时;根据当前所有物理块中擦除次数最小的物理块的擦除次数修正RECC的值,并根据修正后的RECC重新确定所有物理块的池掩码。  The reconstruction unit is connected with the determination unit, and when the pool masks of all physical blocks are no longer CPM; the value of RECC is corrected according to the erasure count of the physical block with the smallest erasure count among all current physical blocks, and according to the correction The post-RECC re-determines the pool mask for all physical blocks. the 25.如权利要求17所述的磨损均衡装置,其特征在于,该装置进一步包括:  25. The wear leveling device of claim 17, further comprising: 备份模块,与所述池维护模块、EBL模块、GBL模块分别相连,用于当存储器正常卸载时,保存所有物理块当前的擦除次数、掩码以及当前的EBL、GBL到存储器的备份区。  The backup module is connected to the pool maintenance module, EBL module, and GBL module respectively, and is used to save the current erasure times, masks, and current EBL and GBL of all physical blocks to the backup area of the memory when the memory is unloaded normally. the 26.如权利要求25所述的磨损均衡装置,其特征在于,所述备份模块进一步用于,将每一个物理块的擦除次数实时存储于该物理块的物理页中。  26. The wear leveling device according to claim 25, wherein the backup module is further configured to store the erasure count of each physical block in a physical page of the physical block in real time. the
CN 201110154330 2011-06-09 2011-06-09 Abrasion equilibrium method and device Active CN102222046B (en)

Priority Applications (3)

Application Number Priority Date Filing Date Title
CN 201110154330 CN102222046B (en) 2011-06-09 2011-06-09 Abrasion equilibrium method and device
US13/519,230 US9405670B2 (en) 2011-06-09 2012-03-15 Wear leveling method and apparatus
PCT/CN2012/072372 WO2012167642A1 (en) 2011-06-09 2012-03-15 Wear leveling method and apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 201110154330 CN102222046B (en) 2011-06-09 2011-06-09 Abrasion equilibrium method and device

Publications (2)

Publication Number Publication Date
CN102222046A CN102222046A (en) 2011-10-19
CN102222046B true CN102222046B (en) 2013-09-18

Family

ID=44778602

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 201110154330 Active CN102222046B (en) 2011-06-09 2011-06-09 Abrasion equilibrium method and device

Country Status (1)

Country Link
CN (1) CN102222046B (en)

Families Citing this family (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9405670B2 (en) 2011-06-09 2016-08-02 Tsinghua University Wear leveling method and apparatus
CN102508785B (en) * 2011-11-02 2015-08-19 清华大学 A kind of abrasion equilibrium method and device
CN102495806B (en) * 2011-11-25 2014-09-03 清华大学 Periodic wear balancing method and memory management method of phase change memory
CN102592678B (en) * 2011-12-30 2014-12-03 记忆科技(深圳)有限公司 Dynamic window management-based wear equilibrium method and device
CN103425437B (en) * 2012-05-25 2016-05-25 华为技术有限公司 Initial writing address system of selection and device
CN102880556B (en) * 2012-09-12 2015-05-20 浙江大学 Wear leveling method and system of Nand Flash
CN103870205B (en) * 2012-12-11 2018-08-07 联想(北京)有限公司 The method and apparatus of method and apparatus and information processing for storing control
CN103020004B (en) * 2012-12-14 2015-09-09 杭州华为数字技术有限公司 The access method of the asymmetric consistance internal storage access system of high-speed cache and device
CN102981972A (en) * 2012-12-25 2013-03-20 重庆大学 Wear-leveling method for phase change memory
CN103064792A (en) * 2012-12-26 2013-04-24 北京创毅讯联科技股份有限公司 Method and device for writing data
TWI529719B (en) * 2013-08-30 2016-04-11 慧榮科技股份有限公司 Data storage device and flash memory control method
CN104714894B (en) * 2015-03-18 2017-08-11 清华大学 The phase transition internal memory abrasion equilibrium method based on Random Maps and system of a kind of layering
CN105117169B (en) * 2015-08-20 2018-07-06 浪潮(北京)电子信息产业有限公司 A kind of method and device of the disk space management of optimization
CN105260135A (en) * 2015-09-23 2016-01-20 Tcl移动通信科技(宁波)有限公司 Storage space read-write control method and system
CN106021124B (en) * 2016-05-09 2019-05-07 深圳大学 Data storage method and storage system
CN106844227A (en) * 2017-01-14 2017-06-13 郑州云海信息技术有限公司 Solid state hard disc abrasion equilibrium method and device based on grouping mechanism
CN108733577B (en) * 2017-04-21 2021-10-22 群联电子股份有限公司 Memory management method, memory control circuit unit, and memory storage device
CN109947353B (en) * 2017-12-20 2021-03-09 浙江宇视科技有限公司 Storage management method, solid state disk and readable storage medium
CN108182035A (en) * 2017-12-28 2018-06-19 湖南国科微电子股份有限公司 A kind of method for improving SSD reliabilities
CN108563586B (en) * 2018-04-12 2021-11-02 华中科技大学 A method for separating garbage collection data and user data in solid state disk
CN111435403B (en) * 2018-12-26 2024-05-07 深圳市中兴微电子技术有限公司 Wear leveling method and device for flash memory system
CN113032288B (en) * 2019-12-25 2023-02-28 杭州海康存储科技有限公司 Method, device and equipment for determining cold and hot data threshold
CN112286843B (en) * 2020-08-12 2022-04-08 深圳安捷丽新技术有限公司 System and method for data storage system
CN112612420A (en) * 2020-12-28 2021-04-06 苏州浪潮智能科技有限公司 Flash wear leveling method, device, equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1815629A (en) * 2005-11-25 2006-08-09 康佳集团股份有限公司 Dirty block recovery method for flash memory device
CN102081576A (en) * 2011-03-01 2011-06-01 华中科技大学 Flash memory wear balance method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI375887B (en) * 2008-10-31 2012-11-01 A Data Technology Co Ltd Flash memory device with wear-leveling mechanism and controlling method thereof

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1815629A (en) * 2005-11-25 2006-08-09 康佳集团股份有限公司 Dirty block recovery method for flash memory device
CN102081576A (en) * 2011-03-01 2011-06-01 华中科技大学 Flash memory wear balance method

Also Published As

Publication number Publication date
CN102222046A (en) 2011-10-19

Similar Documents

Publication Publication Date Title
CN102222046B (en) Abrasion equilibrium method and device
CN102508785B (en) A kind of abrasion equilibrium method and device
US9405670B2 (en) Wear leveling method and apparatus
EP2921963B1 (en) Memory recycling method and device
CN103577336B (en) A storage data processing method and device
CN106484323A (en) A kind of loss equalizing method of solid-state storage and system
CN109496300B (en) Storage medium garbage collection method, storage medium and program product
TWI632457B (en) Method of wear leveling for data storage device
US9111618B2 (en) De-duplication in flash memory module
CN103092766B (en) A kind of loss equalizing implementation method for NAND FLASH
WO2017050028A1 (en) Solid state drive data erasing method and device
JP5983019B2 (en) Control device, storage device, and storage control method
US20150127889A1 (en) Nonvolatile memory system
WO2010132140A1 (en) Wear leveling technique for storage devices
KR20210099870A (en) Memory system and operating method thereof
CN107491272B (en) A method, device, device and storage medium for data migration
CN111090392A (en) Cold and hot data separation method based on feature codes
CN110633047A (en) Method for managing flash memory module and related flash memory controller and electronic device
CN111159059A (en) Garbage recycling method and device and nonvolatile storage equipment
CN111104045A (en) A storage control method, apparatus, device and computer storage medium
CN109815166B (en) Dynamic recovery processing method of stored data and storage device
CN105376269B (en) Virtual machine storage system and its implementation and device
US11226738B2 (en) Electronic device and data compression method thereof
US20100180072A1 (en) Memory controller, nonvolatile memory device, file system, nonvolatile memory system, data writing method and data writing program
WO2024148874A1 (en) Wear leveling method and apparatus, and electronic device and storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant