WO2011072538A1 - Nandflash擦除均衡的方法及装置 - Google Patents

Nandflash擦除均衡的方法及装置 Download PDF

Info

Publication number
WO2011072538A1
WO2011072538A1 PCT/CN2010/076681 CN2010076681W WO2011072538A1 WO 2011072538 A1 WO2011072538 A1 WO 2011072538A1 CN 2010076681 W CN2010076681 W CN 2010076681W WO 2011072538 A1 WO2011072538 A1 WO 2011072538A1
Authority
WO
WIPO (PCT)
Prior art keywords
physical block
block
physical
interval
threshold
Prior art date
Application number
PCT/CN2010/076681
Other languages
English (en)
French (fr)
Inventor
熊泉
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2011072538A1 publication Critical patent/WO2011072538A1/zh

Links

Classifications

    • GPHYSICS
    • G11INFORMATION STORAGE
    • G11CSTATIC STORES
    • G11C16/00Erasable programmable read-only memories
    • G11C16/02Erasable programmable read-only memories electrically programmable
    • G11C16/06Auxiliary circuits, e.g. for writing into memory
    • G11C16/10Programming or data input circuits
    • G11C16/14Circuits for erasing electrically, e.g. erase voltage switching circuits
    • G11C16/16Circuits for erasing electrically, e.g. erase voltage switching circuits for erasing blocks, e.g. arrays, words, groups
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0238Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
    • G06F12/0246Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/72Details relating to flash memory management
    • G06F2212/7211Wear leveling

Definitions

  • the present invention relates to the field of memory technologies, and in particular, to a method and apparatus for Nand Flash erasure equalization. Background technique
  • Nand Flash has a low cost, large capacity and good stability, and is widely used in the embedded field.
  • Nand Flash The physical structure of Nand Flash consists of a page structure and a block structure.
  • the size of one page is 512 Bytes.
  • Each page has a 16 Bytes Spare Area. This area is not a data area and can be used to store the page. Some information, such as checksums, etc.;
  • a block consists of 32 adjacent pages (or 64 pages), which is 16KB (or 32KB).
  • the page is the basic unit of the read operation, and the block is the basic unit of the erase (write) operation. Before writing an area, if the area was previously written, you need to erase the entire block containing the area (first erase and write). Nand Flash needs to erase the block it is in before writing.
  • Nand Flash If the write operation of Nand Flash is not processed, when the amount of data written each time is small, the entire block needs to be erased, and at the same time, a block is required. The data of other areas are saved at the same time, which seriously affects the efficiency. At the same time, due to the technology of Nand Flash, its life is limited (the number of erasures of blocks is limited), and in the file system, some blocks of memory have very high read and write. Frequency, if the file system directly operates the physical block of Nand Flash, the block with high frequency will exceed the number of erasures, which will reduce the storage space of Nand Flash and affect the life of Nand Flash.
  • the technical problem to be solved by the present invention is to provide a method and apparatus for Nand Flash erasure equalization, which solves the problem that the lifetime of the Nand Flash is affected by the excessive number of erasures of some physical blocks in the prior art.
  • the present invention proposes a method for implementing erasure equalization, the method comprising the following steps: At least setting a first erasure threshold, and a second erasure threshold less than or equal to the first erasure threshold; setting at least a first usage frequency threshold, and a second usage greater than or equal to the first usage frequency threshold Frequency threshold; dividing the physical block of the Nand Flash into different physical block intervals according to the first erasure number threshold, the second erasure number threshold, the first usage frequency threshold, and the second usage frequency threshold; according to Nand Flash
  • the frequency of use of the logical block and the original mapping relationship respectively map the logical blocks to physical blocks within the corresponding physical block interval.
  • the physical block in which the number of erasures is higher than the first erasure threshold and the frequency of use of the mapped logical block is lower than the first use frequency threshold is used to divide the physical block into the physical block An interval; the number of erasures is used in the second erasure threshold, and the frequency of use of the mapped logic block is used in the second block of the physical block using the physical block of the first use frequency threshold; And the used physical block whose usage frequency is lower than the second erasure threshold and is used by the mapped logic block is higher than the second usage frequency threshold into the third interval of using the physical block; The first erasure threshold is used, and the used physical block whose frequency of use of the mapped logic block is higher than the second usage frequency threshold is assigned to the fourth block of the physical block.
  • mapping the logical blocks to the physical blocks in the corresponding physical block intervals respectively includes: when the logical blocks have no physical blocks mapped, and the used frequency of the logical blocks is higher than the second used frequency: determining Whether the second interval of the idle physical block is empty; If not empty, the logical block maps the first physical block in the second interval of the idle physical block, and puts the first physical block into the third interval of the used physical block; if it is empty, determines the Whether the second interval of the first block of the physical block is taken out, and if the space is not empty, the second physical block in the second interval of the used physical block is taken out, and the third physical block of the first interval of the free physical block is taken out, The logical block is mapped to the second physical block, and the second physical block is placed into the third interval using the physical block, the logical block originally mapped by the second physical block is mapped to the third physical block, and the third physical block is Putting into the first interval of using the physical block; if it is empty, mapping the logical block to the
  • mapping the logical blocks to the physical blocks in the corresponding physical block intervals respectively includes: when the logical blocks do not map the physical blocks, and the used frequency of the logical blocks is at the first use frequency: determining the idle physical Whether the first interval of the block is empty, if not empty, the logical block is mapped to the fifth physical block of the first interval of the idle physical block, and the fifth physical block is placed into the first interval of the used physical block If it is empty, it is determined whether the fourth interval of the used physical block is empty, and if not, the sixth physical block is taken out from the fourth interval of the used physical block, and from the free physical block Extracting a seventh physical block of the second interval, mapping the logical block to the sixth physical block, placing the sixth physical block into the first interval of the used physical block, and mapping the logical block originally mapped by the sixth physical block to a seventh physical block, and placing the seventh physical block into the third interval of using the physical block; if the fourth interval of the used physical block is empty, mapping the logical block to the eighth interval of
  • the logical block is mapped to the physical block in the corresponding physical block interval, and the method includes the following steps: when the logical block is mapped with a physical block, and the mapped physical block is in the first interval or the third interval of the physical block. If the remapping is not performed, the mapped physical block is directly erased, and the physical block is divided into corresponding physical block intervals using the physical block according to the frequency of use of the logical block and the number of erasures of the mapped physical block. .
  • mapping the logical blocks to the physical blocks in the corresponding physical block intervals separately includes the following steps: when the logical blocks are mapped with physical blocks, and the mapped tenth physical blocks are in the second interval of using the physical blocks, And then re-mapping the logical block, including the following steps: determining whether the fourth interval of the physical block is empty, and if not, extracting the eleventh physical block of the interval, and the tenth physical block And the mapping relationship of the eleventh physical block is interchanged, and after completion, the tenth physical block and the eleventh physical block are put into corresponding according to the frequency of use and the number of erasures.
  • the fourth interval of the physical block determines whether the first interval of the idle physical block is empty, and if not, extracting the tenth from the first interval of the idle physical block Two physical blocks, mapping the logical block to the twelfth physical block, and placing the tenth physical block into the second interval of the idle physical block, and then using the frequency of the twelfth physical block and the number of erasures, If the first interval of the free physical block is empty, the remapping is not performed, and the original tenth physical block is directly erased.
  • mapping the logical blocks to the physical blocks in the corresponding physical block intervals separately includes the following steps: when the logical blocks are mapped with physical blocks, and the mapped ninth physical blocks are using the fourth interval of the physical blocks, Re-mapping the logical block includes the following steps: determining whether the second interval of the physical block is empty, and if not, extracting the thirteenth physical block from the second interval of using the physical block, The mapping relationship between the ninth physical block and the thirteenth physical block is exchanged, and after completion, the ninth physical block and M are placed into the corresponding physical block interval according to the frequency of use and the number of erasures; If the second interval of the block is empty, it is determined whether the second interval of the idle physical block is empty.
  • the fourteenth physical block that is taken out from the second interval of the idle physical block re-creates the logical block. Maps to the fourteenth physical block, and puts the ninth physical block into the first interval of the free physical block, using the frequency of use and the number of erasures, and placing the fourteenth physical block into the physical block. Within the corresponding interval; if the second interval of the free physical block is empty, no remapping is performed, the ninth physical block is directly erased, and the ninth physical block is placed into the corresponding use according to the frequency of use and the number of erasures. Within the physical block interval.
  • the method when performing the write operation, includes the following steps: determining whether the logical block to be written has a physical block mapped, and if not, according to the logical block The frequency of use, and the first usage frequency threshold and the second usage frequency threshold, mapping the logical block; if yes, further determining whether the page to be written by the physical block has been written, and if so, The logic block is remapped according to the frequency of use of the logic block, and the first frequency of use threshold and the second frequency of use threshold. If not, the physical block is written.
  • the method further includes: When the identified file system releases the physical block, the mapping relationship of the released physical block is broken. Further, before performing the write operation, the method further includes the step of: setting a flag bit for each page of the physical block, wherein the flag bit is used to indicate whether the page has been written.
  • the present invention further provides an apparatus for Nand Flash erasure equalization, the apparatus comprising: an erasure number threshold setting unit, configured to set a first erasure threshold, and less than or equal to the first erasure a second erasure threshold of the number threshold; a frequency threshold setting unit, configured to set a first usage frequency threshold, and a second usage frequency threshold greater than or equal to the first usage frequency threshold; a physical block interval dividing unit, configured to The first erasure number threshold, the second erasure number threshold, the first usage frequency threshold, and the second usage frequency threshold are used to divide the physical block of the Nand Flash into different physical block intervals; the address mapping unit is configured to The frequency of use of the logical block of the Nand Flash and the original mapping relationship respectively map the logical blocks to the physical blocks in the corresponding physical block intervals.
  • the device further includes: a mapping relationship determining unit, configured to determine whether a logical block to be written has a physical block mapped; a page write determining unit, configured to determine whether a page to be written by the physical block has been written;
  • the mapping relationship determining unit determines that the logical block that needs to be written is not mapped with the physical block, according to the frequency of use of the logical block, and the first used frequency threshold and the second used frequency threshold, the address mapping unit pairs
  • the logic block performs remapping; when the mapping relationship determining unit determines that the logical block to be written has a physical block mapped, the page write determining unit further determines whether the page to be written by the physical block has been written, and if so, And using the frequency of use of the logic block, and the first usage frequency threshold and the second usage frequency threshold, the logic block is remapped by the address mapping unit; if not, the physical block is written.
  • the device further includes: a mapping relationship adjusting unit, configured to identify the file system When the physical block is released, the mapping relationship of the released physical block is disconnected. Further, the device further includes: a flag setting unit, configured to set, for each page of the physical block, a flag bit indicating whether the page has been written.
  • the beneficial effects of the present invention are as follows: by mapping a physical block having a higher erasure number to a logical block having a lower frequency of use, limiting the number of erasures of a physical block having a higher erasure number, and using a logical block mapping having a higher frequency of use
  • the number of erasures of physical blocks with low erasure times is increased, and the number of erasures of each physical block of Nand Flash is equalized, thereby avoiding that the number of erasures of some physical blocks exceeds Nand Flash.
  • the number of physical block settings (rated) erases, resulting in a reduction in the storage space of Nand Flash, and ultimately to improve the life of Nand Flash.
  • FIG. 1 is a flowchart of a method for Nand Flash erasure equalization according to Embodiment 1 of the present invention
  • FIG. 2 is a flowchart of a method for Nand Flash erasure equalization according to Embodiment 2 of the present invention
  • FIG. 4 is a schematic structural diagram of a device for performing Nand Flash erasure equalization according to Embodiment 3 of the present invention
  • FIG. 5 is a Nand Flash of Embodiment 4 of the present invention
  • the present invention provides a Nand Flash erasure equalization method and apparatus, and the present invention will be described below with reference to the accompanying drawings and embodiments. Further details will be given. It is understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
  • Nand Flash erasing requires equalization of the number of erasures of each physical block. Therefore, the number of erasures of physical blocks is a very important reference for improving the lifetime of Nand Flash. At the same time, due to the nature of the file system, the frequency of use of the logic blocks is different. If only the number of erasures of the physical blocks is considered, regardless of the frequency of use of the logic blocks, a good equalization effect is not obtained. Needle of the invention Aiming at the above characteristics, a method of implementing Nand Flash erasure equalization by block address mapping is proposed, that is, the mapping relationship is determined according to the use frequency of the logic block and the number of physical block erasures.
  • Embodiment 1 of the present invention relates to a method for erasing Nand Flash, including the following steps:
  • the frequency threshold is used; the first erasure threshold is mainly used to filter the physical blocks that have a high number of erasures, and if the erasure continues to exceed the set (nominal) erasure times and affect the life of the Nand Flash.
  • the first erasure threshold may be set according to experience, for example, taking the average number of erasures of all physical blocks (the number of erasures of each physical block is summed and then divided by the number of physical blocks) as the first erasure threshold. .
  • the first erasure count threshold is 80% or 60% of the set (rated) erasure count, and the specific ratio can be freely determined. For example, according to the average number of erasures of all physical blocks of Nand Flash, if the average number of erasures of all physical blocks of Nand Flash is low, the ratio is also lower, and the first erasure threshold is set to be set (rated) ) 60% of the number of erasures; if the average number of erasures of all physical blocks of Nand Flash is higher, the ratio is also higher, and setting the first erasure count threshold is 100 of the set (rated) erasure times. Eighty points.
  • the first erasure threshold may also be a dynamically changing value, for example, associating the first erasure threshold with the average number of erasures of all physical blocks of the Nand Flash, for example, setting the first erasure threshold.
  • the average number of erasures of all physical blocks of Nand Flash is 1.2 times, and the specific multiple can be set according to the specific situation.
  • the threshold of the first erasure number also dynamically changes, thereby adjusting the physical block including the different physical blocks in the first physical block interval.
  • the second erasure threshold is mainly used to filter physical blocks with a lower number of erasures.
  • the setting of the second erasure threshold is similar to the setting of the first erasure threshold, and may be set according to experience, or may be set according to the average erasure times of all physical blocks, or according to the set (rated) erasure times. Settings. Since the number of erasures of the physical block is related to the frequency of use of the mapped logical block, in order to achieve equalization of the number of erasures of each physical block in the Nand Flash, it is necessary to limit the number of erasures of the physical block.
  • a threshold for determining the frequency of use of the logic block is set, that is, the first use frequency threshold and the second use frequency threshold are set.
  • the first use frequency threshold is mainly used to filter the logic block with lower frequency of use.
  • the setting of the first use frequency threshold can be set by the ⁇ - ⁇ , or the average frequency of use of all the logic blocks (the frequency of use of each logic block) Set after dividing by the number of logical blocks.
  • setting the first usage frequency threshold is 20% or 30% of the average frequency of use of all logic blocks of Nand Flash.
  • the second usage frequency threshold is mainly used for screening logic blocks with higher frequency of use, and the setting of the second usage frequency threshold is similar to the setting of the first usage frequency threshold, and may be set according to experience or according to average usage of all logic blocks.
  • the frequency (the number of used logic blocks is summed and divided by the number of logical blocks) is set.
  • the physical blocks of the Nand Flash are classified into different physical block intervals according to the first erasure number threshold, the second erasure number threshold, the first usage frequency threshold, and the second usage frequency threshold. Step: dividing the idle physical block whose erasure times are higher than the first erasure number threshold into the first interval of the idle physical block; and dividing the idle physical block whose erasure count is lower than the threshold of the second erasure count Within the second interval of the idle physical block; when the physical block is mapped with the logical block, the number of erasures of the used physical block is higher than the first erasure threshold, and the used frequency of the mapped logical block is lower than the first use a frequency threshold, the physical block is used to be used to use the first block of the physical block; when the physical block is mapped with the logical block, the number of erasures of the used physical block is equal to the second erasure threshold, and the mapping logic is The use frequency of the block is at the first use frequency threshold, and the physical block is used to
  • the fourth interval of the physical block refers to the number of times the physical block is erased; the frequency of use refers to the set time The number of times the inner logic block was written. The frequency of use can be obtained by counting the number of times the logic block is written during the set time.
  • physical blocks are divided into free physical blocks and used physical blocks, and free physical blocks are physical blocks that are not mapped by logical blocks; physical blocks are used as physical blocks mapped by logical blocks.
  • S103 Map the logical blocks to the physical blocks in the corresponding physical block intervals according to the use frequency of the logical blocks of the Nand Flash and the original mapping relationship.
  • the original mapping relationship of the logical block includes whether the logical block is mapped with a physical block, and when the logical block is mapped with the physical block, the interval of the physical block to which the mapped physical block belongs. In this step, a logical block having no mapping relationship is mapped, and a logical block of the existing mapping relationship is remapped. Mapping the logical blocks to the physical blocks in the corresponding physical block intervals respectively includes the following steps: when the logical blocks are not mapped with physical blocks, and the used frequency of the logical blocks is higher than the second used frequency: Whether the second interval of the idle physical block is empty, not empty, the logical block maps the first physical block in the second interval of the idle physical block, and puts the first physical block into the first physical block.
  • a third interval if it is empty, determining whether the second interval of the physical block is empty, and if not, extracting one of the second physical blocks from the second interval of using the physical block, and taking out the idle physical a third physical block of the first interval of the block, mapping the logical block to the second physical block, and placing the second physical block into the third interval using the physical block, and mapping the logical block originally mapped by the second physical block to And on the third physical block, the third physical block is placed into the first section of the used physical block; if the second interval of using the physical block is empty, the logical block is mapped to the idle The fourth physical block in the block of the first processing section, and the fourth physical block is put into the fourth section provided with a physical block.
  • the use frequency of the logical block is at the first use frequency: determining whether the first interval of the idle physical block is empty, if not, the logical block is mapped to And deleting, by the fifth physical block, the fifth physical block in the first interval of the physical block, and placing the fifth physical block into the first interval of the used physical block; if it is empty, determining whether the fourth interval of the used physical block is empty If not empty, extracting the sixth physical block from the fourth interval of using the physical block, and extracting the seventh physical block from the second interval of the idle physical block, and mapping the logical block to the sixth physical block Inserting a sixth physical block into the first interval of using the physical block, and logically mapping the sixth physical block Mapping the block to the seventh physical block, and placing the seventh physical block into the third interval of using the physical block; if the fourth interval of the used physical block is empty, mapping the logical block to the second interval of the idle physical block The eighth physical block, and the eighth physical block is placed into the second interval
  • the remapping is not performed, and the mapped physical block is directly erased, and the logical block is used again.
  • the frequency and the number of erasures of the mapped physical block are divided into corresponding physical block intervals using the physical block.
  • re-mapping the logical block includes the following steps: determining the fourth interval of using the physical block Whether it is empty, if it is not empty, the eleventh physical block of the interval is taken out, and the mapping relationship between the tenth physical block and the eleventh physical block is interchanged, and after the completion, the frequency of use and rubbing are used.
  • the logical block is mapped with a physical block, and the mapped ninth physical block is in the fourth interval of the physical block, the logical block is remapped, and the following step is included: determining that the physical block is used second Whether the interval is empty, if not empty, the thirteenth physical block is taken out from the second interval of the used physical block, and the mapping relationship between the ninth physical block and the thirteenth physical block is exchanged, and then Using the frequency and the number of erasures, the ninth physical block and the M are placed in the corresponding physical block interval; if the second interval of the physical block is empty, determining whether the second interval of the free physical block is empty, If not empty, the fourteenth physical block extracted from the second interval of the free physical block, the logical block is remapped to the fourteenth physical block, and the ninth physical block is placed into the idle physical block.
  • the physical block is re-arranged in the above method. Enter the free physical block or use the corresponding interval of the physical block.
  • the mapping relationship between the physical block and the logical block can be any mapping method between the logical block and the physical block.
  • a random mapping, or a logical block whose frequency is used from high to highest is sequentially mapped to a physical block whose number of erasures is from high to high.
  • the frequency of use of these logic blocks is higher relative to a logic block having a frequency lower than the first usage frequency threshold, and relative to a logic block having a frequency higher than the second usage frequency threshold Low, therefore, the physical blocks that are mapped to these logical blocks have a higher number of erasures, and are relatively balanced with respect to other physical blocks. In this way, the purpose of equalization erasing is achieved, and the problem that the physical block of relatively high erasure times is frequently erased is avoided, which affects the life of the Nand Flash.
  • a third erasure threshold, a fourth erasure, from low to high between the first erasure threshold and the second erasure threshold may be set.
  • the physical blocks of the Nand Flash are classified into different physical block intervals, and the logical blocks with high frequency of use are mapped to the physical blocks with low erasure times, and the logic of the frequency is used.
  • the block maps to the rule of the physical block with a high number of erasures, and performs address mapping.
  • Embodiment 2 of the present invention relates to a method for erasing equalization of Nand Flash, which includes the following steps: Step S201: setting a first erasure threshold, and less than or equal to the first erasure a second erasure threshold of the threshold; setting a first usage frequency threshold, and a second usage frequency threshold greater than or equal to the first usage frequency threshold; Step S202: The physical blocks of the Nand Flash are classified into different physical block intervals according to the first erasure number threshold, the second erasure number threshold, the first usage frequency threshold, and the second usage frequency threshold. Step S203, The frequency of use of the logical block and the mapping relationship are mapped to the physical block within the corresponding physical block interval.
  • Steps S201, S202, and S203 are the same as those in Embodiment 1, and the present embodiment will not be described in detail.
  • Nand Flash has the characteristics of page-by-page write and block erase, there is also the possibility of address remapping when writing to Nand Flash.
  • the conditions for address remapping are: The logical address space to be written has a physical address corresponding to it, and the corresponding space of the corresponding physical block has been written (equivalent to the mapping relationship rewriting operation); or, the logical address space to be written is not and The physical address is mapped (equivalent to the mapping relationship appending operation).
  • mapping is performed according to the principle of low usage frequency mapping high erasure times and high usage frequency mapping low erasure times.
  • a replacement between two physical blocks is involved, which greatly reduces efficiency.
  • the file system file deletion operation only updates the directory and block allocation table. There is no real deletion of the file. This will happen.
  • all logical addresses have been operated once, all physical addresses will have corresponding logic. Address mapping, any remapping requires two physical blocks to replace, greatly slowing down the write speed.
  • Step S204 When the identified file system releases the physical block, the mapping relationship of the released physical block is disconnected.
  • the FAT file system allocates storage space in units of clusters. It uses the FAT table to allocate the required storage space.
  • the FAT table set flag
  • the cluster space corresponding to the deleted file is released.
  • Step S205 setting a flag bit for each page of the physical block to indicate whether the page has been written. That is, the page flag position 0 that has been written, and the page flag position 1 that has not been written.
  • Step S206 determining whether the logical block to be written has a physical block mapped, if not, performing an additional mapping operation on the logical block, copying the data to be written into the corresponding buffer of the write buffer, and proceeding to step S209; If yes, go to step S207.
  • Step S207 since the Nand Flash is written by page, it is erased by the block.
  • Step S209 mapping the logical block according to the frequency of use of the logic block, and the first usage frequency threshold and the second usage frequency threshold.
  • the mapping method is steps S201-S204, and then proceeds to step S206 until all write operations are completed.
  • the number of uses of the logic block to be written is incremented by one, and the frequency of use is re-averaged. If the average frequency of use changes, the linked list of the physical block is updated.
  • the high usage frequency logic block mapping low erasure physical block the low frequency logic block mapping high erasure number physical block principle finds the physical block that needs to be mapped.
  • the first erasure number threshold is equal to the second erasure threshold
  • the first usage frequency threshold is equal to the second usage frequency threshold
  • the simplest two-part address mapping method is used, and the logic block usage frequency is used. It is divided into two states: high and low.
  • the logic block whose frequency is greater than the average frequency is the high frequency logic block, and the logical address less than or equal to the average frequency is the low frequency logic block.
  • the physical block is also divided into two states.
  • the physical block above the average number of erasures is divided into physical blocks of high erasure times, and physical blocks less than or equal to the average number of erasures are classified as physical blocks of erasure times.
  • Such a logical block and a physical block mapping relationship can be divided into four cases: the frequency of use of the frequency of erasure; the low frequency of use and the high number of erasures; the high frequency of use and the number of low erasures; As shown in FIG.
  • the black dots in the figure represent a pair of mapping relationship between a logical block and a physical block
  • the coordinates are the frequency of use of the logical block and the number of erasures using the physical block
  • the dotted lines in the middle respectively indicate the average number of erasures and Average frequency of use.
  • the mapping pair should be able to fall into the space of high use frequency, low erase frequency, low use frequency and high erase frequency as much as possible. To do this, you can implement a simple data structure for the physical block: struct
  • the data structure of the logical block is defined as follows: struct ⁇ mapped physical block number; / * physical block corresponding to the logical block * / frequency of use; / * number of writes of the logical block * / ⁇ ; With a complex data structure, you get a very good balance. Then the state of the physical block establishes the following six doubly linked lists, namely: the frequency of the erasing frequency list; the low frequency of high erasure times list; the high frequency of low erasure times list; the high frequency of high erasure times list ; low erase times free list; high erase times free list.
  • Step 1 Initialize the physical parameters, logical block parameters; Set the physical block list to be empty;
  • Step 2 Determine whether the physical block parameters (the number of erasures, the logical block number of the mapping, the page usage flag) and the logic block parameters (the physical block number of the mapping, the frequency of use) are set in the Nand Flash. If the above parameters are not set, It indicates that the Nand Flash is the first time to use the method of this embodiment, then go to step 3. If the above parameters are set, go to step 4.
  • Step 3 The Nand Flash physical block is completely erased, the number of erasures of the updated physical block is 1, the mapping relationship is empty, and the flag of the page is unused; the mapping relationship of the updated logical block is empty, and the number of uses is 0; Update the corresponding Spare area of each physical block and set the number of erasures to 1. Go to step 5.
  • Step 4 reading the parameters of the physical block, updating the physical block parameters; mapping the physical block to the logical block, updating the mapped physical block number in the logical block parameter; calculating the average erasure number, traversing the physical block, and wiping according to the physical block In addition to the number of times, the number of times the mapped logical block is used is updated.
  • Step 5 Determine whether the file system can be identified.
  • Step 6 Re-update the physical block and the logical block parameters according to the free physical block in the allocation table (the physical block of the disconnected relationship:).
  • Step 7. Create a physical block linked list: traverse the physical block, and add the physical block to different linked lists according to the mapping relationship, the number of erasures, and the frequency of use of the mapped logical block.
  • Step 8. Initial ⁇ is completed.
  • the parameters of the physical block (the number of erasures, the logical block number of the mapping, the page usage identifier) are very important and must be saved; for the parameters of the logical block (the physical block number of the mapping, the frequency of use), the mapping relationship can be obtained by the physical block. .
  • the frequency of use is reset after each power-down restart.
  • the setting principle is:
  • the initial usage count of the idle logic block is 1, and the logic of the physical block mapped to the high erase count
  • the initial number of uses of the block is 0, and the initial number of uses of the logical block mapped to the number of erased physical blocks is 1.
  • the basis for such initialization is: Using the equalization erasure method, the physical blocks are basically concentrated in the space of low use frequency high erasure times and high use frequency erasure times, and physical blocks are mapped to these two spaces and actuals at the time of initialization. The situation is close; the frequency of use of idle logic blocks is relatively high.
  • the present invention saves the parameters of the physical block in the Spare area of the last page of each physical block, and needs to update the Spare area every time the physical block is reassigned, since the Spare area is small, compared with the write data area. The timing of the operation can be ignored. This method can be used to dynamically update these important parameters during Nand Flash access without affecting access efficiency.
  • the Nand Flash process includes the following steps: S1, the read address is divided into pages, and the read operation is performed in units of pages; if there are more than one, the step 4 is repeatedly called S2-S5.
  • S2 Determine whether the logical block corresponding to the page to be read has a physical block mapped, and if not, go to S3; if there is a mapping relationship, go to S4.
  • S3. Set all bytes of the buffer to 0XFF and go to S5.
  • S4 Converting the logical block address to a physical block address, and then adding an offset of the access page address in the block to the physical address, and calling a read function of the Nand Flash to perform a read operation. After completion, transfer to S5.
  • Embodiment 3 of the present invention relates to a Nand Flash erasure equalization apparatus, including: an erasure number threshold setting unit 401, configured to set a first erasure threshold, and less than or equal to the first a second erasure threshold of the erasure threshold; a usage frequency threshold setting unit 402, configured to set a first usage frequency threshold, and a second usage frequency threshold greater than or equal to the first usage frequency threshold; the physical block interval dividing unit 403 And respectively connected to the erasure number threshold setting unit 401 and the usage frequency threshold setting unit 402, configured to occupy the first erasure number threshold, the second erasure number threshold, the first usage frequency threshold, and the second usage frequency Threshold, the physical block of Nand Flash is divided into different physical block intervals;
  • the address mapping unit 404 is respectively connected to the erasure number threshold setting unit 401, the usage frequency threshold setting unit 402, and the physical block interval dividing unit 403, and is used for the frequency of use of the logical
  • the embodiment 4 of the present invention relates to a Nand Flash erasure equalization apparatus, including: an erasure number threshold setting unit 501, configured to set a first erasure threshold, and less than or equal to the first a second erasure threshold of the erasure threshold; a frequency threshold setting unit 502, configured to set a first usage frequency threshold, and a second usage frequency threshold greater than or equal to the first usage frequency threshold; the physical block interval dividing unit 503 And respectively connected to the erasure number threshold setting unit 501 and the usage frequency threshold setting unit 502, configured to be used according to the first erasure number threshold, the second erasure number threshold, the first usage frequency threshold, and the second usage frequency.
  • the physical block of the Nand Flash is divided into different physical block intervals;
  • the address mapping unit 504 is respectively connected to the erasure count threshold setting unit 501, the use frequency threshold setting unit 502, and the physical block interval dividing unit 503, Depending on the frequency of use of the logic block and the original mapping relationship, the logical blocks are respectively mapped to the physical blocks in the corresponding physical block interval.
  • the mapping relationship adjusting unit 505 is connected to the address mapping unit 504, and is configured to disconnect the mapped physical block when the identified file system releases the physical block.
  • the mapping relationship determining unit 506 is connected to the mapping relationship adjusting unit 505, and is configured to determine whether a logical block that needs to be written is mapped with a physical block.
  • the page writing determining unit 507 is connected to the mapping relationship determining unit 506, and is configured to determine that the physical block is to be written. Whether the entered page has been written; when the mapping relationship determining unit 506 determines that the logical block to be written is not mapped with the physical block, according to the frequency of use of the logical block, and the first used frequency threshold and the second used frequency threshold, The logical block is mapped by the address mapping unit 504.
  • the page write determining unit 507 further determines whether the page to be written by the physical block has been Write, if yes, Then, according to the frequency of use of the logic block, and the first usage frequency threshold and the second usage frequency threshold, the logic block is mapped by the address mapping unit 504; if not, the physical block is written.
  • the flag bit setting unit 508 is connected to the page write determination unit 507 for setting a flag bit for indicating whether the page has been written to each page of the physical block.

Description

Nand Flash擦除均衡的方法及装置 技术领域 本发明涉及存储器技术领域, 特别是涉及一种 Nand Flash擦除均衡的方 法及装置。 背景技术
Nand Flash具有成本低, 容量大, 稳定性较好的特点, 在嵌入式领域得 到广泛应用。
Nand Flash 的物理结构由页结构和块结构组成, 一个页的大小为 512 Bytes, 每个页有 16 Bytes的附力口区 Spare Area, 这个区域不是数据区, 可以 用来存放与该页相关的一些信息, 如校验码等; 一个块由相邻的 32个页(或 者 64个页)组成, 也就是 16KB (或者 32KB)。 页为读操作的基本单位, 块为 擦除 (写) 操作的基本单位。 在写某一区域之前, 如果该区域以前被写过, 则需要先擦除包含该区域 的整个块(先擦后写)。 Nand Flash在写之前需要对它所在块进行擦除, 如果 不对 Nand Flash的写操作进行处理, 则当每次写的数据量不大时, 就需要擦 除整个块, 同时还要将一个块的其他区域的数据同时保存, 严重影响效率; 同时, 由于 Nand Flash实现技术, 使得它的寿命有限(块的擦除次数有限 ) , 而在文件系统中, 存储器的某些块具有非常高的读写频率, 如果让文件系统 直接操作 Nand Flash的物理块, 则其中使用频率高的块就会超过擦除次数, 从而使得 Nand Flash的存储空间减少, 影响 Nand Flash的寿命。 发明内容 本发明要解决的技术问题是提供一种 Nand Flash 擦除均衡的方法及装 置, 用以解决现有技术中由于部分物理块擦除次数过多影响 Nand Flash寿命 的问题。 为解决上述技术问题, 本发明提出了一种实现擦除均衡的方法, 所述方 法包括以下步 4聚: 至少设置第一擦除次数阈值, 以及小于或等于所述第一擦除次数阈值的 第二擦除次数阈值; 至少设置第一使用频率阈值, 以及大于或等于第一使用 频率阈值的第二使用频率阈值; 根据所述第一擦除次数阈值、 第二擦除次数阈值、 第一使用频率阈值和 第二使用频率阈值, 将 Nand Flash的物理块划入不同的物理块区间内; 根据 Nand Flash的逻辑块的使用频率和原有映射关系, 将逻辑块分别映 射到相应物理块区间内的物理块上。
将擦除次数高于所述第一擦除次数阈值的空闲物理块划入空闲物理块第 一区间内; 将擦除次数低于所述第二擦除次数阈值的空闲物理块划入空闲物理块第 二区间内;
将擦除次数高于第一擦除次数阈值、 且被映射逻辑块的使用频率低于所 述第一使用频率阈值的物理块中的使用物理块划入到物理块区间中的使用物 理块第一区间; 将擦除次数氏于第二擦除次数阀值、 且被映射逻辑块的使用频率氏于所 述第一使用频率阀值的使用物理块划入到使用物理块第二区间; 将擦除次数低于第二擦除次数阈值、 且被映射逻辑块的使用频率高于所 述第二使用频率阈值的使用物理块划入到使用物理块第三区间内; 将擦除次数高于第一擦除次数阀值、 且被映射逻辑块的使用频率高于所 述第二使用频率阀值的使用物理块划入到使用物理块第四区间。 进一步, 将逻辑块分别映射到相应物理块区间内的物理块上包括: 当所 述逻辑块没有映射物理块、 且所述逻辑块的使用频率高于所述第二使用频率 时: 判断所述空闲物理块第二区间是否为空; 如果不为空, 则该逻辑块映射空闲物理块第二区间内的第一物理块, 并 将第一物理块放入到所述使用物理块的第三区间; 如果为空, 则判断所述使 用物理块第二区间是否为空, 如果不为空, 则取出所述使用物理块第二区间 内的第二物理块, 同时取出所述空闲物理块第一区间的第三物理块, 将该逻 辑块映射到第二物理块, 同时将第二物理块放入到使用物理块的第三区间, 将第二物理块原来映射的逻辑块映射到第三物理块上, 并将第三物理块放入 到所述使用物理块第一区间; 如果为空, 则将该逻辑块映射到所述空闲物理 块第一区间内的第四物理块上, 并将第四物理块放入到所述使用物理块第四 区间内。 进一步, 将逻辑块分别映射到相应物理块区间内的物理块上包括: 当所 述逻辑块没有映射物理块、 且所述逻辑块的使用频率氏于第一使用频率时: 判断所述空闲物理块第一区间是否为空, 如果不为空, 则该逻辑块映射 到所述空闲物理块第一区间的第五物理块, 并将第五物理块放入到所述使用 物理块第一区间内; 如果为空, 则判断所述使用物理块第四区间是否为空, 如果不为空, 则从所述使用物理块第四区间内取出第六物理块, 并从所述空 闲物理块第二区间的取出第七物理块, 将该逻辑块映射到第六物理块, 将第 六物理块放入到所述使用物理块第一区间, 将第六物理块原先被映射的逻辑 块映射到第七物理块, 并将第七物理块放入到使用物理块第三区间; 如果所 述使用物理块第四区间为空, 则将该逻辑块映射到空闲物理块第二区间的第 八物理块, 并将第八物理块放入到使用物理块的第二区间。 进一步, 将逻辑块分别映射到相应物理块区间内的物理块上, 具体包括 以下步骤: 当所述逻辑块映射有物理块、 且被映射的物理块在使用物理块第 一区间或第三区间内, 则不进行重新映射, 直接擦写被映射的物理块, 再根 据逻辑块的使用频率与被映射的物理块的擦除次数, 将该物理块划分到使用 物理块的相应物理块区间内。 进一步, 将逻辑块分别映射到相应物理块区间内的物理块上, 具体包括 以下步骤: 当所述逻辑块映射有物理块、 且被映射的第十物理块在使用物理 块第二区间内, 则对所述逻辑块进行重新映射, 包括以下步骤: 判断所述使用物理块第四区间是否为空, 如果不为空, 则取出该区间的 第十一物理块,将所述第十物理块和第十一物理块的映射关系互换, 完成后, 再才艮据使用频率和擦除次数, 将所述第十物理块和第十一物理块放入到相应 的物理块区间内; 如果所述使用物理块第四区间为空, 则判断所述空闲物理 块第一区间是否为空, 如果不为空, 则从所述空闲物理块第一区间取出第十 二物理块, 将所述逻辑块映射到第十二物理块上, 同时将第十物理块放入到 空闲物理块第二区间, 再 居第十二物理块的使用频率和擦除次数, 放入到 相应的物理块区间内; 如果所述空闲物理块第一区间为空, 则不进行重新映 射, 直接擦写原来第十物理块。 进一步, 将逻辑块分别映射到相应物理块区间内的物理块上, 具体包括 以下步骤: 当所述逻辑块映射有物理块、 且被映射的第九物理块在使用物理 块第四区间, 则对所述逻辑块进行重新映射, 包括以下步骤: 判断所述使用物理块第二区间是否为空, 如果不为空, 则从所述使用物 理块第二区间中取出第十三物理块, 将第九物理块和第十三物理块的映射关 系进行互换, 完成后再根据使用频率和擦除次数, 将第九物理块和 M放入到 相应的物理块区间内; 如果所述使用物理块第二区间为空, 则判断所述空闲 物理块第二区间是否为空, 如果不为空, 则从所述空闲物理块第二区间取出 的第十四物理块, 将所述逻辑块重新映射到第十四物理块, 同时将第九物理 块放入到空闲物理块第一区间, 居使用频率和擦除次数, 将第十四物理块 放入到使用物理块的相应区间内; 如果所述空闲物理块第二区间为空, 则不 进行重新映射, 直接擦写第九物理块, 并根据使用频率和擦除次数, 将第九 物理块放入到使用相应的物理块区间内。 进一步, 在将所述逻辑块映射到相应物理块区间内的物理块上之后, 进 行写操作时, 包括以下步骤: 判断需要写的逻辑块是否映射有物理块, 如果否, 则根据该逻辑块的使 用频率, 以及所述第一使用频率阈值和第二使用频率阈值, 对该逻辑块进行 映射; 如果是, 则进一步判断该物理块要写入的页是否已经被写入, 如果是, 则 居该逻辑块的使用频率, 以及所述第一使用频率阈值和第二使用频率阈 值, 对该逻辑块进行重新映射, 如果否, 则对该物理块进行写操作。 进一步, 当完成写操作后, 当所述第一使用频率阈值、 第二使用频率阈 值、 第一擦除次数阈值和第二擦除次数阈值中的任何一个发生改变, 则重新 遍历 Nand Flash的所有物理块, 将物理块重新划入不同的物理块区间内。 进一步, 在判断需要写的逻辑块是否映射有物理块之前, 还包括: 当被识别的文件系统释放有物理块时, 断开所述被释放物理块的映射关 系。 进一步, 在进行写操作之前, 还包括以下步骤: 对所述物理块的每一页 设置标志位, 其中该标志位用于表示该页是否已经被写入。 另一方面, 本发明还提供一种 Nand Flash擦除均衡的装置, 所述装置包 括: 擦除次数阈值设置单元, 用于设置第一擦除次数阈值, 以及小于或等于 所述第一擦除次数阈值的第二擦除次数阈值; 使用频率阈值设置单元, 用于设置第一使用频率阈值, 以及大于或等于 第一使用频率阈值的第二使用频率阈值; 物理块区间划分单元, 用于根据所述第一擦除次数阈值、 第二擦除次数 阈值、 第一使用频率阈值和第二使用频率阈值, 将 Nand Flash的物理块划入 不同的物理块区间内; 地址映射单元, 用于根据 Nand Flash的逻辑块的使用频率和原有映射关 系, 将逻辑块分别映射到相应物理块区间内的物理块上。 进一步, 所述装置还包括: 映射关系判断单元, 用于判断需要写的逻辑块是否映射有物理块; 页写入判断单元, 用于判断物理块要写入的页是否已经被写入; 当所述映射关系判断单元判定需要写的逻辑块没有映射有物理块时, 则 根据该逻辑块的使用频率 ,以及所述第一使用频率阈值和第二使用频率阈值, 通过所述地址映射单元对该逻辑块进行重新映射; 当映射关系判断单元判定需要写的逻辑块映射有物理块时, 则页写入判 断单元进一步判断该物理块要写入的页是否已经被写入, 如果是, 则 居该 逻辑块的使用频率, 以及所述第一使用频率阈值和第二使用频率阈值, 通过 所述地址映射单元对该逻辑块进行重新映射; 如果否, 则对该物理块进行写 操作。 进一步, 所述装置还包括: 映射关系调整单元, 用于当被识别的文件系 统释放有物理块时, 断开所述被释放物理块的映射关系。 进一步, 所述装置还包括: 标志位设置单元, 用于对所述物理块的每一 页设置用于表示该页是否已经被写入的标志位。 本发明有益效果如下: 通过将擦除次数较高的物理块映射到使用频率较低的逻辑块上, 限制擦 除次数较高的物理块增加的擦除次数, 将使用频率高的逻辑块映射到擦除次 数低的物理块上, 增加擦除次数低的物理块的擦除次数, 对 Nand Flash的各 个物理块的擦除次数进行均衡,避免了因为部分物理块的擦除次数超过 Nand Flash物理块的设置 (额定 )擦除次数, 而造成 Nand Flash的存储空间减少, 最终达到提高 Nand Flash寿命的目的。 另外, 通过对物理块的每一页设置标 志位, 对没有写的页直接进行写入, 大大提高了 Nand Flash写的速度。 附图说明 图 1 是本发明实施例 1一种 Nand Flash擦除均衡的方法的流程图; 图 2 是本发明实施例 2—种 Nand Flash擦除均衡的方法的流程图; 图 3 是本发明实施例 2中一种逻辑块与物理块映射关系的对应图; 图 4 是本发明实施例 3—种 Nand Flash擦除均衡的装置的结构示意图; 图 5 是本发明实施例 4一种 Nand Flash擦除均衡的装置的结构示意图。 具体实施方式 为了解决现有技术由于部分物理块擦除次数过多影响 Nand Flash寿命的 问题, 本发明提供了一种 Nand Flash擦除均衡的方法及装置, 以下结合附图 以及实施例, 对本发明进行进一步详细说明。 应当理解, 此处所描述的具体 实施例仅仅用以解释本发明, 并不限定本发明。
Nand Flash的擦写, 要求各个物理块的擦除次数均衡, 因此, 物理块的 擦除次数, 对于提高 Nand Flash的寿命, 是非常重要的参考依据。 同时, 由 于文件系统的性质, 使得逻辑块的使用频率各不相同, 如果只考虑物理块的 擦除次数, 而不考虑逻辑块得使用频率, 就得不到好的均衡效果。 本发明针 对上述特点, 提出了一种按块地址映射来实现 Nand Flash擦除均衡的方法, 即才艮据逻辑块使用频率和物理块擦除次数来确定映射关系。 为了实现上述目 的, 需要将文件系统的操作地址和 Nand Flash的实际地址分开, 这里将文件 系统操作的地址称为逻辑地址, Nand Flash的实际地址称为物理地址。 如图 1所示, 本发明实施例 1涉及一种 Nand Flash的擦除方法, 包括以 下步骤:
S 101 , 设置第一擦除次数阈值, 以及小于或等于所述第一擦除次数阈值 的第二擦除次数阈值; 设置第一使用频率阈值, 以及大于或等于第一使用频 率阈值的第二使用频率阈值; 第一擦除次数阈值, 主要是用于筛选擦除次数较高、 且如果继续频繁进 行擦除会超过设定 (额定)擦除次数、 影响 Nand Flash寿命的物理块。 第一 擦除次数阈值可以根据经验进行设置, 例如, 取所有物理块的平均擦除次数 (各个物理块的擦除次数求和后再除以物理块的个数)为第一擦除次数阈值。 也可以根据设定 (额定)擦除次数进行设置, 例如, 第一擦除次数阈值为设 定 (额定)擦除次数的百分之八十或百分之六十, 具体比例可以自由确定。 例如, 才艮据 Nand Flash所有物理块的平均擦除次数确定, 如果 Nand Flash所 有物理块的平均擦除次数较低, 则该比例也较低, 设置第一擦除次数阈值为 设定 (额定 )擦除次数的百分之六十; 如果 Nand Flash所有物理块的平均擦 除次数较高, 则该比例也较高, 设置第一擦除次数阈值为设定 (额定)擦除 次数的百分之八十。 另外, 第一擦除次数阈值也可以为动态变化的数值, 例 如, 将第一擦除次数阈值与 Nand Flash所有物理块的平均擦除次数的进行关 联, 比如, 设置第一擦除次数阈值为 Nand Flash所有物理块的平均擦除次数 的 1.2倍, 具体倍数, 可以根据具体的情况进行设置。 当 Nand Flash所有物 理块的平均擦除次数变化时, 第一擦除次数阈值也会动态变化, 进而调整第 一物理块区间内包括不同的物理块。 第二擦除次数阈值主要是用于筛选擦除 次数较低的物理块。 第二擦除次数阈值的设置与第一擦除次数阈值的设置相 似, 可以根据经验进行设置, 也可以根据所有物理块的平均擦除次数进行设 置, 或者根据设定 (额定)擦除次数进行设置。 由于物理块的擦除次数与映射的逻辑块的使用频率有关,为了达到 Nand Flash内各个物理块擦除次数的均衡, 需要对物理块的擦除次数进行限制。 因 此, 不能将使用频率高的逻辑块映射到擦除次数高的物理块上, 而需要将使 用频率较氏的逻辑块映射到擦除次数高的物理块上。 由上述分析可知, 需要 设置判断逻辑块使用频率的阈值, 即设置第一使用频率阈值和第二使用频率 阈值。 第一使用频率阈值主要是用于筛选使用频率较低的逻辑块, 第一使用 频率阈值的设置, 可以 居经 -睑设置, 也可以 居所有逻辑块的平均使用频 率 (各个逻辑块的使用频率求和后除以逻辑块的个数) 进行设置。 例如, 设 置第一使用频率阈值为 Nand Flash所有逻辑块的平均使用频率的百分之二十 或百分之三十。 第二使用频率阈值主要是用于筛选使用频率较高的逻辑块, 第二使用频率阈值的设置与第一使用频率阈值的设置也相似, 可以根据经验 设置, 也可以根据所有逻辑块的平均使用频率 (各个逻辑块的使用频率求和 后除以逻辑块的个数) 进行设置。
S 102 , 根据所述第一擦除次数阈值、 第二擦除次数阈值、 第一使用频率 阈值和第二使用频率阈值,将 Nand Flash的物理块划入不同的物理块区间内; 具体包括以下步骤: 将擦除次数高于所述第一擦除次数阈值的空闲物理块划入空闲物理块第 一区间内; 将擦除次数低于所述第二擦除次数阈值的空闲物理块划入空闲物理块第 二区间内; 当使用物理块映射有逻辑块时, 该使用物理块的擦除次数高于第一擦除 次数阈值、 且被映射逻辑块的使用频率低于所述第一使用频率阈值, 将该使 用物理块划入到使用物理块第一区间; 当使用物理块映射有逻辑块时, 该使用物理块的擦除次数氏于第二擦除 次数阀值、 且被映射逻辑块的使用频率氏于所述第一使用频率阀值, 将该使 用物理块划入到使用物理块第二区间; 当使用物理块映射有逻辑块时, 该使用物理块的擦除次数氏于第二擦除 次数阈值、 且被映射逻辑块的使用频率高于所述第二使用频率阈值, 将该使 用物理块划入到使用物理块第三区间内; 当使用物理块映射有逻辑块时, 该使用物理块的擦除次数高于第一擦除 次数阀值、 且被映射逻辑块的使用频率高于所述第二使用频率阀值, 将该使 用物理块划入到使用物理块第四区间。 其中, 擦除次数是指物理块被擦除的次数; 使用频率是指在设定的时间 内逻辑块被写的次数。 使用频率可以通过计数器记录在设定时间内逻辑块被 写的次数得到。 另外, 才艮据物理块的映射关系, 物理块分为空闲物理块和使 用物理块, 空闲物理块为没有被逻辑块映射的物理块; 使用物理块为被逻辑 块映射的物理块。 S 103 , 根据 Nand Flash的逻辑块的使用频率和原有映射关系, 将逻辑块 分别映射到相应物理块区间内的物理块上。 逻辑块的原有映射关系包括逻辑 块是否映射有物理块, 以及当逻辑块映射有物理块时, 被映射的物理块所属 的物理块的区间。 本步骤是对没有映射关系的逻辑块进行映射, 对已有映射 关系的逻辑块进行重新映射。 将逻辑块分别映射到相应物理块区间内的物理块上,具体包括以下步骤: 当所述逻辑块没有映射物理块、 且所述逻辑块的使用频率高于所述第二 使用频率时: 判断所述空闲物理块第二区间是否为空, 不为空, 则该逻辑块映射空闲 物理块第二区间内的第一物理块, 并将第一物理块放入到所述使用物理块的 第三区间; 如果为空, 则判断所述使用物理块第二区间是否为空, 如果否, 则从所述使用物理块第二区间内取出其中的一个第二物理块, 同时取出所述 空闲物理块第一区间的第三物理块, 将该逻辑块映射到第二物理块, 同时将 第二物理块放入到使用物理块的第三区间, 将第二物理块原来映射的逻辑块 映射到第三物理块上, 并将第三物理块放入到所述使用物理块第一区间; 如 果所述使用物理块的第二区间为空, 则将该逻辑块映射到所述空闲物理块第 一区间内的第四物理块上, 并将第四物理块放入到所述使用物理块第四区间 内。 当所述逻辑块没有映射物理块、 且所述逻辑块的使用频率氏于第一使用 频率时: 判断所述空闲物理块第一区间是否为空, 如果不为空, 则该逻辑块映射 到所述空闲物理块第一区间的第五物理块, 并将第五物理块放入到所述使用 物理块第一区间内; 如果为空, 则判断所述使用物理块第四区间是否为空, 如果不为空, 则从所述使用物理块第四区间内取出第六物理块, 并从所述空 闲物理块第二区间的取出第七物理块, 将该逻辑块映射到第六物理块, 将第 六物理块放入到所述使用物理块第一区间, 将第六物理块原先被映射的逻辑 块映射到第七物理块, 并将第七物理块放入到使用物理块第三区间; 如果所 述使用物理块第四区间为空, 则将该逻辑块映射到空闲物理块第二区间的第 八物理块, 并将第八物理块放入到使用物理块的第二区间。 当所述逻辑块映射有物理块、 且被映射的物理块在使用物理块第一区间 或第三区间内, 则不进行重新映射, 直接擦写被映射的物理块, 再 居逻辑 块的使用频率与被映射的物理块的擦除次数, 将该物理块划分到使用物理块 的相应物理块区间内。 当所述逻辑块映射有物理块、 且被映射的第十物理块在使用物理块第二 区间内, 则对所述逻辑块进行重新映射, 包括以下步骤: 判断所述使用物理块第四区间是否为空, 如果不为空, 则取出该区间的 第十一物理块,将所述第十物理块和第十一物理块的映射关系互换, 完成后, 再才艮据使用频率和擦除次数, 将所述第十物理块和第十一物理块放入到相应 的物理块区间内; 如果所述使用物理块第四区间为空, 则判断所述空闲物理 块第一区间是否为空, 如果不为空, 则从所述空闲物理块第一区间取出第十 二物理块, 将所述逻辑块映射到第十二物理块上, 同时将第十物理块放入到 空闲物理块第二区间, 再 居第十二物理块的使用频率和擦除次数, 放入到 相应的物理块区间内; 如果所述空闲物理块第一区间为空, 则不进行重新映 射, 直接擦写原来第十物理块。 当所述逻辑块映射有物理块、 且被映射的第九物理块在使用物理块第四 区间, 则对所述逻辑块进行重新映射, 包括以下步 4聚: 判断所述使用物理块第二区间是否为空, 如果不为空, 则从所述使用物 理块第二区间中取出第十三物理块, 将第九物理块和第十三物理块的映射关 系进行互换, 完成后再根据使用频率和擦除次数, 将第九物理块和 M放入到 相应的物理块区间内; 如果所述使用物理块第二区间为空, 则判断所述空闲 物理块第二区间是否为空, 如果不为空, 则从所述空闲物理块第二区间取出 的第十四物理块, 将所述逻辑块重新映射到第十四物理块, 同时将第九物理 块放入到空闲物理块第一区间, 居使用频率和擦除次数, 将第十四物理块 放入到使用物理块的相应区间内; 如果所述空闲物理块第二区间为空, 则不 进行重新映射, 直接擦写第九物理块, 并根据使用频率和擦除次数, 将第九 物理块放入到使用相应的物理块区间内。 上述步骤中, 在逻辑块重新映射物理块时, 如果新的物理块原先被映射 有逻辑块, 则需要保存该物理块上所记录的信息。 另外, 当完成逻辑地址写操作时, 判断使用频率阀值或者擦除次数阀值 是否已经改变, 如果其中任何一个阀值改变, 则需要重新遍历所有物理块, 居上述方法 ,将物理块重新划入到空闲物理块或使用物理块的相应区间内。 对于擦除次数介于第一擦除次数阈值和第二擦除次数阈值之间的物理 块,以及使用频率介于第一使用频率阈值和第二使用频率阈值之间的逻辑块, 由于这些物理块的擦除次数,及逻辑块的使用频率,相对于 Nand Flash来说, 就相对均衡, 因此, 这部分物理块与逻辑块的映射关系可以为任意一种逻辑 块与物理块的映射方法, 例如随机映射, 或将使用频率由高到氏的逻辑块依 次映射到擦除次数由氐到高的物理块上。 无论釆取哪种映射方式, 由于这些 逻辑块的使用频率都相对于与使用频率低于第一使用频率阈值的逻辑块较 高, 而相对于使用频率高于第二使用频率阈值的逻辑块较低, 因此, 与这些 逻辑块有映射关系的物理块的擦除次数的较多, 相对于其它物理块, 都相对 均衡。 这样, 就达到了均衡擦除的目的, 也避免了因对擦除次数相对较高的 物理块频繁进行擦除, 造成影响 Nand Flash寿命的问题。 需要说明的是, 如果为了获得更好的均衡结果, 还可以设置介于第一擦 除次数阈值和第二擦除次数阈值之间由低到高的第三擦除次数阈值、 第四擦 除次数阈值 第 M擦除次数阈值, 其中, M为大于等于 3 的整数。 设置 介于第一使用频率阈值和第二使用频率阈值之间由高到低的第三使用频率阈 值、 第四使用频率阈值 第 N使用频率阈值, 其中, N为大于等于 3的整 数。 然后根据上述擦除次数阈值和使用频率阈值, 将 Nand Flash的物理块划 入不同的物理块区间, 按照将使用频率高的逻辑块映射到擦除次数低的物理 块, 将使用频率氏的逻辑块映射到擦除次数高的物理块的规则, 进行地址映 射。 设置的擦除次数阈值和使用频率阈值越多, 也就能更好的达到物理块擦 除次数的均衡, 不过, 实现的步骤也就越复杂。 如图 2所示, 本发明实施例 2涉及一种 Nand Flash擦除均衡的方法, 包 括以下步 4聚: 步骤 S201 , 设置第一擦除次数阈值, 以及小于或等于所述第一擦除次数 阈值的第二擦除次数阈值; 设置第一使用频率阈值, 以及大于或等于第一使 用频率阈值的第二使用频率阈值; 步骤 S202, 根据所述第一擦除次数阈值、 第二擦除次数阈值、 第一使用 频率阈值和第二使用频率阈值, 将 Nand Flash的物理块划入不同的物理块区 间内; 步骤 S203 , 居逻辑块的使用频率和映射关系, 将所述逻辑块映射到相 应物理块区间内的物理块上。 步骤 S201、 S202、 S203与实施例 1相同, 本实施例不再详细叙述。 由于 Nand Flash具有按页写, 按块擦除的特点, 因此, 在对 Nand Flash 进行写操作时, 还存在地址重新映射的可能。 地址重新映射的条件是: 需要 写的逻辑地址空间已经对应有物理地址, 且所对应物理块的相应空间已经被 写过(相当于映射关系改写操作); 或, 需要写的逻辑地址空间没有和物理地 址进行映射(相当于映射关系追加操作)。在逻辑地址和物理地址重新映射时, 根据低使用频率映射高擦除次数, 高使用频率映射低擦除次数的原则进行映 射。 在逻辑地址的重新映射过程中, 当要被重新映射的物理块本身有逻辑块 进行映射时, 会涉及到两个物理块之间的替换, 这样会大大降低效率。 而文 件系统的文件删除操作, 只是更新目录和块分配表, 没有真正的去删除文件, 这样就会出现这样的情况, 当所有逻辑地址都被操作一次过后, 所有的物理 地址都会有对应的逻辑地址进行映射, 进行任何一次的重新映射都需要两块 物理块间进行替换, 极大减慢了写速度。 为了解决这种情况, 本发明还包括 以下步 4聚: 步骤 S204 , 当被识别的文件系统释放有物理块时, 断开被释放物理块的 映射关系。 以 FAT文件系统为例, FAT文件系统以簇为单位进行存储空间的 分配, 它使用了 FAT表来分配所需要的存储空间, 当删除文件时, 就会更新 FAT表(置标志位), 将删除文件所对应的簇空间释放。 通过检测 FAT表的 更新, 当发现有物理块被释放时, 就将与该物理块有映射关系的逻辑块和该 物理块间的映射关系断开。 通过上述操作, 可以极大提高 Nand Flash的写效 率。 当有不被识别的文件系统时, 该步骤则不起作用, 直接进行下述的写操 作, 虽然可能会降低 Nand Flash的访问效率, 但不影响 Nand Flash进行正常 操作。 在对 Nand Flash进行写操作时, 还包括以下步骤: 步骤 S205 , 对物理块的每一页设置标志位, 用于表示该页是否已经被写 入。 即, 已经写入的页标志位置 0, 未写入的页标志位置 1。 步骤 S206, 判断需要写的逻辑块是否映射有物理块, 如果否, 则需要对 该逻辑块进行追加映射操作,将需要写的数据拷贝到写緩冲区的相应緩存内, 转步骤 S209; 如果是, 则转步骤 S207。 步骤 S207, 由于 Nand Flash是按页写, 按块擦除, 因此, 在写入时, 需 要进一步判断该物理块要写入的页是否已经被写入, 即判断该页的标志位是 否为 1 , 如果是, 则无法在该页进行写操作, 因此, 需要对映射关系进行改 写操作, 则将所映射物理块内的有效数据读出緩存, 将要写的数据拷贝到该 緩存的相应地址内, 转骤 S209; 如果否, 则将要写的数据写入緩存中, 转步 骤 S208。 步骤 S208 , 从緩存中, 将要写的数据写入到物理块相应的页中。 步骤 S209, 居该逻辑块的使用频率, 以及所述第一使用频率阈值和第 二使用频率阈值, 对该逻辑块进行映射。 映射的方法为步骤 S201-S204 , 然 后转步骤 S206, 直至所有写操作结束。 重新映射时, 将需要写的逻辑块的使 用次数加 1 , 重新求平均使用频率, 如果平均使用频率改变, 则更新物理块 的各个链表。 根据高使用频率逻辑块映射低擦除次数物理块, 低使用频率逻 辑块映射高擦除次数物理块的原则找到需要映射的物理块。 在本实施例中, 当第一擦除次数阈值等于第二擦除次数阈值, 第一使用 频率阈值等于第二使用频率阈值时, 即为最简单的二分区地址映射法, 将逻 辑块使用频率分为高、 低两种状态, 使用频率大于平均使用频率的逻辑块为 高使用频率逻辑块, 小于或等于平均使用频率的逻辑地址为低使用频率逻辑 块; 物理块也分为高低两种状态, 高于平均擦除次数的物理块划分为高擦除 次数物理块, 小于或等于平均擦除次数的物理块划为氏擦除次数物理块。 这 样逻辑块和使用物理块的映射关系就可以分为四种情况: 氏使用频率氏擦除 次数; 低使用频率高擦除次数; 高使用频率低擦除次数; 高使用频率低擦除 次数。 如图 3所示, 图中的黑点表示逻辑块和物理块的一对映射关系, 坐标 分别为逻辑块的使用频率和使用物理块的擦除次数, 中间的虚线分别表示平 均擦除次数和平均使用频率。 要获得好的均衡效果, 映射对要能尽可能的落 入高使用频率低擦除次数、 低使用频率高擦除次数的空间内。 为了实现上述操作, 可以为物理块实现一个简单的数据结构: struct
{ 映射的逻辑块号; /*物理块所对应的逻辑块 */ 块内可用 page标识; /*指示块内哪些 page是可用的(没有被写过 )*/ 擦除次数; /*物理块被擦除的次数 */ Pre指 4十; /*指向下一个物理块 */ Next指 4十; /*指向上一个物理块 */
}; 逻辑块的数据结构定义如下: struct { 映射的物理块号; /*逻辑块所对应的物理块 */ 使用频率; /*逻辑块的写次数 */ }; 使用该方法, 不用实现非常复杂的数据结构, 就能获得非常好的均衡效 果。 然后 居物理块的状态建立下面六个双向链表, 即: 氏使用频率氏擦除 次数链表; 低使用频率高擦除次数链表; 高使用频率低擦除次数链表; 高使 用频率高擦除次数链表; 低擦除次数空闲链表; 高擦除次数空闲链表。 只有 当平均使用频率或平均擦写次数改变时, 才重新遍历物理块重新构建链表, 重新构建链表的概率为: (l* 100/(block 总数) )%~(3* 100/(block 总数) )%, 以
128MB的 Nand Flash为例, Block总数为 128* 1024 /(16) =8192, 重新构建链 表的概率 0.01%~0.04%, 因此对整体性能不会有影响。 使用上述数据结构, 所占用的内存空间为: (4*5 + 4*2)*8192 /1024= 224 KB, 使用的内存空间非 初始化时根据各个物理块的参数分别将它们加入到不同的链表中。 初始 化流程如下: 步骤 1、 初始化物理参数, 逻辑块参数; 置物理块链表为空; 开辟一块
Block大小的写緩冲区。 步骤 2、 判断 Nand Flash中是否设置过物理块参数(擦除次数, 映射的 逻辑块号, 页使用标志位)和逻辑块参数(映射的物理块号, 使用频率), 如 果没有设置上述参数, 则表明该 Nand Flash是初次使用本实施例的方法, 则 转步骤 3 , 如果设置过上述参数, 则转步骤 4。 步骤 3、 将 Nand Flash物理块全部擦除, 更新物理块的擦除次数为 1 , 映射关系为空, 页的标志位为未被使用; 更新逻辑块的映射关系为空, 使用 次数为 0; 更新各个物理块的相应 Spare区域, 将擦除次数置为 1。 转步骤 5。 步骤 4、 读取物理块的参数, 更新物理块参数; 居物理块与逻辑块的 映射关系, 更新逻辑块参数中的映射物理块号; 计算平均擦除次数, 遍历物 理块, 根据物理块擦除次数, 更新被映射的逻辑块的使用次数。 步骤 5、 判断文件系统是否能识别, 如果是, 则检测文件分配表, 转步 骤 6 , 否则转步骤 7。 步骤 6、 根据分配表中的空闲物理块(断开映射关系的物理块:), 重新更 新物理块和逻辑块参数。 步骤 7、 创建物理块链表: 遍历物理块, 根据映射关系、 擦除次数、 映 射的逻辑块的使用频率, 将物理块加入到不同的链表中。 步骤 8、 初始^ ^完成。 物理块的参数 (擦除次数, 映射的逻辑块号, 页使用标识) 非常重要, 必须要进行保存; 对于逻辑块的参数(映射的物理块号, 使用频率)、 映射关 系可以由物理块获得。 使用频率在每次掉电重新启动后被重新设置, 设置原 则是: 空闲逻辑块的初始使用次数为 1 , 映射到高擦除次数的物理块的逻辑 块的初始使用次数为 0, 映射到氏擦除次数物理块的逻辑块的初始使用次数 为 1。 这样的初始化依据是: 使用均衡擦除方法, 物理块基本都集中在低使 用频率高擦除次数和高使用频率氏擦除次数的空间, 在初始化时将物理块映 射到这两个空间与实际情况接近; 空闲逻辑块的使用频率相对来说使用频率 也较氏。 本发明将物理块的参数保存在每一个物理块的最后一个页的 Spare 区域中, 在每次将物理块重新分配后都需要更新该 Spare 区域, 由于 Spare 区域很小,与写数据区相比操作时机可以忽略。使用该方式可以在 Nand Flash 访问的过程中动态更新这些重要的参数, 也不会影响访问效率。 经过上述步骤后的 Nand Flash, 进行读的流程包括以下步骤: S1 , 将读地址按页进行划分, 以页为单位进行读操作; 有多个也则反复 调用步 4聚 S2-S5。
S2、 判断需要读的页所对应的逻辑块是否映射有物理块, 没有则转 S3; 如果有映射关系, 转 S4。
S3、 将緩冲区所有字节置为 0XFF, 转 S5。 S4、 将逻辑块地址转换为物理块地址, 再在该物理地址上加上访问页地 址在块内的偏移, 调用 Nand Flash的读函数进行读操作。 完成后转 S5.
S5、 读完成。 如图 4所示, 本发明实施例 3涉及一种 Nand Flash擦除均衡的装置, 包 括: 擦除次数阈值设置单元 401 , 用于设置第一擦除次数阈值, 以及小于或 等于所述第一擦除次数阈值的第二擦除次数阈值; 使用频率阈值设置单元 402 , 用于设置第一使用频率阈值, 以及大于或 等于第一使用频率阈值的第二使用频率阈值; 物理块区间划分单元 403 , 分别与所述擦除次数阈值设置单元 401和使 用频率阈值设置单元 402连接, 用于 居所述第一擦除次数阈值、 第二擦除 次数阈值、 第一使用频率阈值和第二使用频率阈值, 将 Nand Flash的物理块 划入不同的物理块区间内; 地址映射单元 404 , 分别与所述擦除次数阈值设置单元 401、 使用频率 阈值设置单元 402和物理块区间划分单元 403连接, 用于 居 Nand Flash的 逻辑块的使用频率和原有映射关系, 将逻辑块分别映射到相应物理块区间内 的物理块上。 如图 5所示, 本发明实施例 4涉及一种 Nand Flash擦除均衡的装置, 包 括: 擦除次数阈值设置单元 501 , 用于设置第一擦除次数阈值, 以及小于或 等于所述第一擦除次数阈值的第二擦除次数阈值; 使用频率阈值设置单元 502 , 用于设置第一使用频率阈值, 以及大于或 等于第一使用频率阈值的第二使用频率阈值; 物理块区间划分单元 503 , 分别与所述擦除次数阈值设置单元 501和使 用频率阈值设置单元 502连接, 用于根据所述第一擦除次数阈值、 第二擦除 次数阈值、 第一使用频率阈值和第二使用频率阈值, 将 Nand Flash的物理块 划入不同的物理块区间内; 地址映射单元 504 , 分别与所述擦除次数阈值设置单元 501、 使用频率 阈值设置单元 502和物理块区间划分单元 503连接, 用于根据逻辑块的使用 频率和原有映射关系, 将逻辑块分别映射到相应物理块区间内的物理块上。 映射关系调整单元 505 , 与地址映射单元 504连接, 用于当被识别的文 件系统释放有物理块时, 断开被释放物理块的映射关系。 映射关系判断单元 506, 与映射关系调整单元 505连接, 用于判断需要 写的逻辑块是否映射有物理块; 页写入判断单元 507 , 与映射关系判断单元 506连接, 用于判断物理块 要写入的页是否已经被写入; 当映射关系判断单元 506判定需要写的逻辑块没有映射有物理块时, 则 根据该逻辑块的使用频率, 以及第一使用频率阈值和第二使用频率阈值, 通 过地址映射单元 504对该逻辑块进行映射; 当映射关系判断单元 506判定需要写的逻辑块映射有物理块时, 则页写 入判断单元 507进一步判断该物理块要写入的页是否已经被写入, 如果是, 则根据该逻辑块的使用频率, 以及第一使用频率阈值和第二使用频率阈值, 通过地址映射单元 504对该逻辑块进行映射; 如果否, 则对该物理块进行写 操作。 标志位设置单元 508, 与页写入判断单元 507连接, 用于对物理块的每 一页设置用于表示该页是否已经被写入的标志位。 由上述实施例可以看出, 通过将擦除次数较高的物理块映射到使用频率 较氐的逻辑块上, 限制擦除次数较高的物理块增加的擦除次数, 将擦除次数 氐的物理块映射到使用频率高的逻辑块上, 增加擦除次数氏的物理块的擦除 次数, 对 Nand Flash的各个物理块的擦除次数进行均衡, 避免了因为部分物 理块的擦除次数超过 Nand Flash 物理块的设置 (额定)擦除次数, 而造成 Nand Flash的存储空间减少, 最终达到提高 Nand Flash寿命的目的。 另外, 通过对物理块的每一页设置标志位, 对没有写的页直接进行写入, 大大提高 了 Nand Flash写的速度。 尽管为示例目的, 已经公开了本发明的优选实施例, 本领域的技术人员 将意识到各种改进、 增加和取代也是可能的, 因此, 本发明的范围应当不限 于上述实施例。

Claims

权 利 要 求 书
1. 一种 Nand Flash擦除均衡的方法, 其特征在于, 所述方法包括以下步 4聚: 至少设置第一擦除次数阈值, 以及小于或等于所述第一擦除次数阈 值的第二擦除次数阈值; 至少设置第一使用频率阈值, 以及大于或等于 所述第一使用频率阈值的第二使用频率阈值;
根据所述第一擦除次数阈值、 第二擦除次数阈值、 第一使用频率阈 值和第二使用频率阈值, 将 Nand Flash的物理块划入不同的物理块区间 内;
根据所述 Nand Flash的逻辑块的使用频率和原有的映射关系, 将所 述逻辑块分别映射到相应物理块区间内的物理块上。
2. 如权利要求 1所述的 Nand Flash擦除均衡的方法, 其特征在于, 将 Nand Flash的物理块划入不同的物理块区间内包括以下之一:
将擦除次数高于所述第一擦除次数阈值的所述物理块中的空闲物理 块划入所述物理块区间中的空闲物理块第一区间内;
将擦除次数氐于所述第二擦除次数阈值的空闲物理块划入空闲物理 块第二区间内。
3. 如权利要求 1所述的 Nand Flash擦除均衡的方法, 其特征在于, 将 Nand Flash的物理块划入不同的物理块区间内包括以下之一:
将擦除次数高于所述第一擦除次数阈值、 且被映射逻辑块的使用频 率氐于所述第一使用频率阈值的所述物理块中的使用物理块划入到所述 物理块区间中的使用物理块第一区间;
将擦除次数氏于所述第二擦除次数阀值、 且被映射逻辑块的使用频 率氐于所述第一使用频率阀值的使用物理块划入到使用物理块第二区 间;
将擦除次数低于所述第二擦除次数阈值、 且被映射逻辑块的使用频 率高于所述第二使用频率阈值的使用物理块划入到使用物理块第三区间 内;
将擦除次数高于所述第一擦除次数阀值、 且被映射逻辑块的使用频 率高于所述第二使用频率阀值的使用物理块划入到使用物理块第四区 间。 如权利要求 3所述的 Nand Flash擦除均衡的方法, 其特征在于, 将逻辑 块分别映射到相应物理块区间内的物理块上包括:
当所述逻辑块没有映射物理块、 且所述逻辑块的使用频率高于所述 第二使用频率时:
判断所述空闲物理块第二区间是否为空;
如果不为空,则该逻辑块映射空闲物理块第二区间内的第一物理块, 并将所述第一物理块放入到所述使用物理块的第三区间;
如果为空, 则判断所述使用物理块第二区间是否为空;
如果不为空, 则取出所述使用物理块第二区间的第二物理块, 同时取出所述空闲物理块第一区间的第三物理块, 将该逻辑块映射到所 述第二物理块, 同时将所述第二物理块放入到使用物理块的第三区间, 将所述第二物理块原来映射的逻辑块映射到所述第三物理块上, 并将所 述第三物理块放入到所述使用物理块第一区间;
如果为空, 则将该逻辑块映射到所述空闲物理块第一区间内的 第四物理块上,并将所述第四物理块放入到所述使用物理块第四区间内。 如权利要求 3所述的 Nand Flash擦除均衡的方法, 其特征在于, 将逻辑 块分别映射到相应物理块区间内的物理块上包括:
当所述逻辑块没有映射物理块、 且所述逻辑块的使用频率氏于第一 使用频率时:
判断所述空闲物理块第一区间是否为空;
如果不为空, 则该逻辑块映射到所述空闲物理块第一区间的第五物 理块, 并将所述第五物理块放入到所述使用物理块第一区间内;
如果为空, 则判断所述使用物理块第四区间是否为空;
如果不为空,则从所述使用物理块第四区间内取出第六物理块 , 并从所述空闲物理块第二区间的取出第七物理块, 将该逻辑块映射到所 述第六物理块, 将所述第六物理块放入到所述使用物理块第一区间, 将 所述第六物理块原先被映射的逻辑块映射到所述第七物理块, 并将所述 第七物理块 G放入到使用物理块第三区间; 如果为空, 则将该逻辑块映射到空闲物理块第二区间的第八物 理块, 并将所述第八物理块放入到使用物理块的第二区间。
6. 如权利要求 3所述的 Nand Flash擦除均衡的方法, 其特征在于, 将逻辑 块分别映射到相应物理块区间内的物理块上包括:
当所述逻辑块映射有物理块、 且被映射的物理块在使用物理块第一 区间或第三区间内, 则不进行重新映射, 直接擦写被映射的物理块, 再 才艮据逻辑块的使用频率与被映射的物理块的擦除次数, 将该物理块划分 到使用物理块的相应物理块区间内。
7. 如权利要求 3所述的 Nand Flash擦除均衡的方法, 其特征在于, 将逻辑 块分别映射到相应物理块区间内的物理块上包括:
当所述逻辑块映射有物理块、 且被映射的第十物理块在使用物理块 第二区间内, 则对所述逻辑块进行重新映射, 包括以下步骤:
判断所述使用物理块第四区间是否为空;
如果不为空, 则取出该区间的第十一物理块, 将所述第十物理块和 所述第十一物理块的映射关系互换, 再 居使用频率和擦除次数, 将所 述第十物理块和所述第十一物理块放入到相应的物理块区间内;
如果所述使用物理块第四区间为空, 则判断所述空闲物理块第一区 间是否为空;
如果不为空,则从所述空闲物理块第一区间取出第十二物理块, 将所述逻辑块映射到所述第十二物理块上, 同时将所述第十物理块放入 到空闲物理块第二区间, 再 居所述第十二物理块的使用频率和擦除次 数, 放入到相应的物理块区间内;
如果为空, 则不进行重新映射, 直接擦写所述第十物理块。
8. 如权利要求 3所述的 Nand Flash擦除均衡的方法, 其特征在于, 将逻辑 块分别映射到相应物理块区间内的物理块上包括:
当所述逻辑块映射有物理块、 且被映射的第九物理块在使用物理块 第四区间, 则对所述逻辑块进行重新映射, 包括以下步 4聚:
判断所述使用物理块第二区间是否为空;
如果不为空, 则从所述使用物理块第二区间中取出第十三物理块, 将所述第九物理块和所述第十三物理块的映射关系进行互换, 再根据使 用频率和擦除次数, 将所述第九物理块和所述第十三物理块放入到相应 的物理块区间内;
如果所述使用物理块第二区间为空, 则判断所述空闲物理块第二区 间是否为空;
如果不为空,则从所述空闲物理块第二区间取出第十四物理块 , 将所述逻辑块重新映射到所述第十四物理块, 同时将所述第九物理块放 入到空闲物理块第一区间, 居使用频率和擦除次数, 将所述第十四物 理块放入到使用物理块的相应区间内;
如果为空, 则不进行重新映射, 直接擦写所述第九物理块, 并 才艮据使用频率和擦除次数, 将所述第九物理块放入到使用相应的物理块 区间内。
9. 如权利要求 1至 8中任一项所述的 Nand Flash擦除均衡的方法, 其特征 在于, 在将所述逻辑块映射到相应物理块区间内的物理块上之后, 进行 写操作时, 包括以下步骤:
判断需要写的逻辑块是否映射有物理块, 如果否, 则 居该逻辑块 的使用频率, 以及所述第一使用频率阈值和第二使用频率阈值, 对该逻 辑块进行映射; 如果是, 则进一步判断该物理块要写入的页是否已经被 写入, 如果是, 则根据该逻辑块的使用频率, 以及所述第一使用频率阈 值和第二使用频率阈值, 对该逻辑块进行重新映射, 如果否, 则对该物 理块进行写操作。
10. 如权利要求 9所述的 Nand Flash擦除均衡的方法, 其特征在于, 当完成 写操作后, 当所述第一使用频率阈值、 所述第二使用频率阈值、 所述第 一擦除次数阈值和所述第二擦除次数阈值中的任何一个发生改变, 则重 新遍历 Nand Flash的所有物理块, 将物理块重新划入不同的物理块区间 内。
11. 如权利要求 9所述的 Nand Flash擦除均衡的方法, 其特征在于, 在判断 需要写的逻辑块是否映射有物理块之前, 还包括:
当被识别的文件系统释放有物理块时, 断开被释放物理块的映射关 系。
12. 如权利要求 9所述的 Nand Flash擦除均衡的方法, 其特征在于, 在进行 写操作之前, 还包括以下步骤:
对所述物理块的每一页设置标志位, 其中所述标志位用于表示该页 是否已经被写入。
13. 一种 Nand Flash擦除均衡的装置, 其特征在于, 所述装置包括:
擦除次数阈值设置单元, 用于设置第一擦除次数阈值, 以及小于或 等于所述第一擦除次数阈值的第二擦除次数阈值;
使用频率阈值设置单元, 用于设置第一使用频率阈值, 以及大于或 等于所述第一使用频率阈值的第二使用频率阈值;
物理块区间划分单元, 用于根据所述第一擦除次数阈值、 第二擦除 次数阈值、 第一使用频率阈值和第二使用频率阈值, 将 Nand Flash的物 理块划入不同的物理块区间内;
地址映射单元, 用于 居所述 Nand Flash的逻辑块的使用频率和原 有映射关系, 将所述逻辑块分别映射到相应物理块区间内的物理块上。
14. 如权利要求 13所述的 Nand Flash擦除均衡的装置, 其特征在于, 所述装 置还包括:
映射关系判断单元, 用于判断需要写的逻辑块是否映射有物理块; 页写入判断单元, 用于判断物理块要写入的页是否已经被写入; 当所述映射关系判断单元判定需要写的逻辑块没有映射有物理块 时, 则根据该逻辑块的使用频率, 以及所述第一使用频率阈值和第二使 用频率阈值, 通过所述地址映射单元对该逻辑块进行重新映射;
当所述映射关系判断单元判定需要写的逻辑块映射有物理块时, 则 所述页写入判断单元进一步判断该物理块要写入的页是否已经被写入, 如果是, 则根据该逻辑块的使用频率, 以及所述第一使用频率阈值和第 二使用频率阈值, 通过所述地址映射单元对该逻辑块进行重新映射; 如 果否, 则对该物理块进行写操作。
15. 如权利要求 14所述的 Nand Flash擦除均衡的装置, 其特征在于, 所述装 置还包括:
映射关系调整单元, 用于当被识别的文件系统释放有物理块时, 断 开所述被释放物理块的映射关系。
16. 如权利要求 14所述的 Nand Flash擦除均衡的装置, 其特征在于, 所述装 置还包括:
标志位设置单元, 用于对所述物理块的每一页设置用于表示该页是 否已经被写入的标志位。
PCT/CN2010/076681 2009-12-17 2010-09-07 Nandflash擦除均衡的方法及装置 WO2011072538A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN 200910260369 CN101740110B (zh) 2009-12-17 2009-12-17 一种Nand Flash擦除均衡的方法及装置
CN200910260369.5 2009-12-17

Publications (1)

Publication Number Publication Date
WO2011072538A1 true WO2011072538A1 (zh) 2011-06-23

Family

ID=42463444

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2010/076681 WO2011072538A1 (zh) 2009-12-17 2010-09-07 Nandflash擦除均衡的方法及装置

Country Status (2)

Country Link
CN (1) CN101740110B (zh)
WO (1) WO2011072538A1 (zh)

Cited By (1)

* 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

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101740110B (zh) * 2009-12-17 2013-06-12 中兴通讯股份有限公司 一种Nand Flash擦除均衡的方法及装置
WO2012167642A1 (en) * 2011-06-09 2012-12-13 Tsinghua University Wear leveling method and apparatus
CN103218177A (zh) * 2013-04-19 2013-07-24 杭州电子科技大学 具有数据均衡处理功能的NAND Flash存储系统
CN103678150B (zh) 2013-12-23 2017-06-09 华为技术有限公司 固态硬盘使用方法及装置
CN104156317A (zh) * 2014-08-08 2014-11-19 浪潮(北京)电子信息产业有限公司 一种非易失性闪存的擦写管理方法及系统
CN106294202A (zh) * 2015-06-12 2017-01-04 联想(北京)有限公司 一种数据存储方法和装置
CN106354718B (zh) * 2015-07-13 2021-05-25 中国移动通信集团公司 用户识别模块的文件管理方法及装置
CN107506135B (zh) 2016-06-14 2022-05-06 杭州海康威视数字技术股份有限公司 一种数据处理方法、装置及系统
CN107291625B (zh) * 2017-06-19 2020-06-09 济南浪潮高新科技投资发展有限公司 一种用于Nand Flash的指针式逻辑地址映射表实现方法
CN109119108A (zh) * 2018-08-15 2019-01-01 杭州阿姆科技有限公司 一种提高Nand寿命的方法
CN109164990B (zh) * 2018-09-13 2022-03-29 东信和平科技股份有限公司 一种存储器数据更新方法、装置、设备及存储介质
CN110799935A (zh) * 2018-12-04 2020-02-14 深圳市大疆创新科技有限公司 数据存储方法、闪存设备、智能电池、可移动平台
CN111949569A (zh) * 2019-05-17 2020-11-17 北京兆易创新科技股份有限公司 一种存储设备及其控制方法和控制装置
CN110175385B (zh) * 2019-05-20 2021-01-15 山东大学 一种基于性能磨损均衡的非易失fpga布局优化方法和系统
CN112068769B (zh) * 2020-07-28 2023-11-14 深圳市宏旺微电子有限公司 闪存设备双向链表管理方法和闪存存储设备

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1698036A (zh) * 2002-10-28 2005-11-16 桑迪士克股份有限公司 跟踪非易失性存储器系统中最不频繁擦除区块
CN101740110A (zh) * 2009-12-17 2010-06-16 中兴通讯股份有限公司 一种Nand Flash擦除均衡的方法及装置

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100565477C (zh) * 2007-12-06 2009-12-02 浙江科技学院 一种NAND Flash存储器的动态管理方法
CN101369252A (zh) * 2008-09-16 2009-02-18 浙江大学 基于nand闪存文件系统中静态数据损耗均衡的方法

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1698036A (zh) * 2002-10-28 2005-11-16 桑迪士克股份有限公司 跟踪非易失性存储器系统中最不频繁擦除区块
CN101740110A (zh) * 2009-12-17 2010-06-16 中兴通讯股份有限公司 一种Nand Flash擦除均衡的方法及装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
LI-PIN CHANG.: "On Efficient Wear Leveling for Large-Scale Flash-Memory Storage Systems.", PROCEEDINGS OF THE ACM SYMPOSIUM ON APPLIED COMPUTING, 2007, NEW YORK, pages 1126 - 1130 *

Cited By (1)

* 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

Also Published As

Publication number Publication date
CN101740110B (zh) 2013-06-12
CN101740110A (zh) 2010-06-16

Similar Documents

Publication Publication Date Title
WO2011072538A1 (zh) Nandflash擦除均衡的方法及装置
US10657047B2 (en) Data storage device and method of performing partial garbage collection
CN108038026B (zh) 一种基于闪存的数据快速恢复方法与系统
TWI474324B (zh) 平均讀寫記憶元件的方法及記憶體系統
CN102841851B (zh) 闪存管理方法和闪存设备
US20110099323A1 (en) Non-volatile semiconductor memory segregating sequential, random, and system data to reduce garbage collection for page based mapping
TWI585770B (zh) 記憶體管理方法、記憶體控制電路單元及記憶體儲存裝置
TWI537728B (zh) 緩衝記憶體管理方法、記憶體控制電路單元及記憶體儲存裝置
WO2017088185A1 (zh) 一种存储设备存储数据的方法及存储设备
TWI473100B (zh) Flash memory system and its operation method
KR101086876B1 (ko) 예비 영역을 유동적으로 관리하는 반도체 스토리지 시스템 및 그 제어 방법
CN106557432B (zh) 缓冲存储器管理方法、存储器控制电路单元及存储装置
US10990325B2 (en) Write control method, associated data storage device and controller thereof
WO2014074449A2 (en) Wear leveling in flash memory devices with trim commands
US20080082727A1 (en) Header blocks for flash memory writes
JP4632180B2 (ja) メモリコントローラ、メモリコントローラを備えるフラッシュメモリシステム、並びにフラッシュメモリの制御方法
TW201413451A (zh) 非揮發性記憶體的資料收集方法
KR20140025574A (ko) 하이브리드 slc/mlc 메모리 내의 블록 관리 방식들
TWI476590B (zh) 記憶體管理方法、記憶體控制器與記憶體儲存裝置
US11645006B2 (en) Read performance of memory devices
CN106775436B (zh) 数据存取方法、存储器控制电路单元与存储器
US11036429B2 (en) Memory control method, memory storage device and memory control circuit unit to determine a source block using interleaving information
US20190012260A1 (en) Flash memory package and storage system including flash memory package
TWI696916B (zh) 資料儲存裝置以及非揮發式記憶體控制方法
JP2007334413A (ja) 記憶装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 10836975

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 10836975

Country of ref document: EP

Kind code of ref document: A1