Data reading and writing method, memory storage device and memory controller
By building virtual blocks in memory modules and establishing virtual block mapping tables, and reusing physical bad blocks, the problems of reduced storage capacity and shortened service life in memory storage devices are solved, and the long-term use of memory storage devices is achieved.
Patent Information
- Application Number
- CN202210044915.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-14
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2042-01-14
AI Technical Summary
When the existing memory storage device detects that the block of storing data is damaged, it is necessary to select a previously damaged block from the substituted block, resulting in a reduced effective storage capacity of the storage device and a corresponding shortening of the service life.
By building a virtual block in a memory module, the virtual block is constructed from a good page of the entity in several entity bad blocks in multiple entity blocks, and a virtual block mapping table is established to realize data read and write operations to the virtual blocks, thereby reusing the entity bad blocks.
Without changing the effective storage capacity of the memory storage device, the service life of the memory storage device is greatly extended, and the reliability and use efficiency of the memory device are improved.
Smart Images

Figure CN114398010B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a memory management technology, and in particular to a data reading and writing method, a memory storage device and a memory controller. Background Art
[0002] With the development of technology, the application of storage devices is becoming more and more extensive. During use, when the storage device detects that a block storing data is damaged, it selects a replacement block to replace the damaged block, so as to ensure the effective storage of the storage device and extend the service life of the storage device. Only when all replacement blocks are exhausted, the service life of the entire storage device is considered to have expired. Obviously, the more replacement blocks are retained, the longer the service life of the storage device, but the corresponding number of blocks used to effectively store data is also smaller, resulting in a smaller effective capacity of the storage device. Summary of the invention
[0003] The present invention provides a data reading and writing method, a memory storage device and a memory controller, which can greatly extend the service life of the memory storage device without changing the effective storage capacity of the memory storage device.
[0004] An embodiment of the present invention provides a data reading and writing method for a memory storage device, wherein the memory storage device includes a memory module, the memory module includes multiple physical blocks and multiple virtual blocks, the physical block includes multiple physical pages, and the virtual block is constructed by physical good pages in several physical bad blocks in the multiple physical blocks. The data reading and writing method includes: when reading data from the virtual block, according to a preset virtual block mapping table, finding the address of the physical bad block corresponding to the physical good page currently storing data, so as to read the data in the physical good page storing data; when writing data to the virtual block, according to the preset virtual block mapping table, finding the address of the physical bad block corresponding to the current blank physical good page, so as to write the data into the blank physical good page.
[0005] An embodiment of the present invention further provides a memory storage device, comprising: a connection interface for connecting to a host system; a memory module, comprising a plurality of physical blocks and a plurality of virtual blocks, the physical block comprising a plurality of physical pages, the virtual block being constructed by physical good pages in a number of physical bad blocks in the plurality of physical blocks; a memory controller, connected to the connection interface and the memory module, wherein the memory controller is used to execute the above-mentioned data reading and writing method.
[0006] The embodiment of the present invention further provides a memory controller for controlling a memory module, wherein the memory module includes a plurality of physical blocks and a plurality of virtual blocks, the physical block includes a plurality of physical pages, the virtual block is constructed by physical good pages in a plurality of physical bad blocks in the plurality of physical blocks, and the memory controller includes: a host interface for connecting to a host system; a memory interface for connecting to the memory module; and a memory control circuit connected to the host interface and the memory interface. The memory control circuit is also used to execute the above-mentioned data reading and writing method.
[0007] Based on the above, in addition to multiple physical blocks, the memory module also includes multiple virtual blocks, and the virtual block is constructed by physical good pages in several physical bad blocks in the multiple physical blocks. When reading data from the virtual block, according to the preset virtual block mapping table, the address of the physical bad block corresponding to the physical good page currently storing data is found to read the data in the physical good page storing data. When writing data to the virtual block, according to the preset virtual block mapping table, the address of the physical bad block corresponding to the current blank physical good page is found to write the data into the blank physical good page. In this way, the present application reuses the generated physical bad blocks by block mapping, constructs virtual blocks and corresponding virtual block mapping tables, so that the original physical bad blocks can be reused, that is, the established virtual blocks can be used as replacement blocks for normal use (including data reading and data writing). At the same time, the virtual blocks are constructed by the original physical bad blocks, which do not change the proportion and number of the replacement blocks initially set, and thus will not change the effective storage capacity of the storage device. In this way, the service life of the memory storage device can be greatly extended without changing the effective storage capacity of the memory storage device. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 FIG. 4 is a schematic diagram of a memory storage device according to an embodiment of the present invention.
[0009] Figure 2 is a schematic diagram of a memory controller according to an embodiment of the present invention.
[0010] Figure 3 FIG. 4 is a schematic diagram of a structure of a memory module according to an embodiment of the present invention.
[0011] Figure 4 is another structural schematic diagram of a memory module according to an embodiment of the present invention.
[0012] Figure 5 is a schematic diagram of a physical block mapping table of a memory module according to an embodiment of the present invention.
[0013] Figure 6 FIG. 4 is a flowchart of establishing a virtual block according to an embodiment of the present invention.
[0014] Figure 7 is a schematic diagram of a virtual block mapping table of a memory module according to an embodiment of the present invention.
[0015] Figure 8 is a flow chart of a data reading and writing method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0016] Reference will now be made in detail to exemplary embodiments of the present invention, examples of which are illustrated in the accompanying drawings. Whenever possible, the same reference numerals are used in the drawings and the description to refer to the same or like parts.
[0017] Figure 1 is a schematic diagram of a memory storage device according to an embodiment of the present invention. Figure 1 , the memory storage system 10 includes a host system 11 and a memory storage device 12. The host system 11 can be any type of computer system. For example. The host system 11 can be various electronic systems such as a laptop computer, a desktop computer, a smart phone, a tablet computer, an industrial computer, a game console, a digital camera, etc. The memory storage device 12 is used to store data from the host system 11. For example, the memory storage device 12 may include a solid state drive, a USB flash drive, a memory card, or other types of non-volatile storage devices. The host system 11 can be electrically connected to the memory storage device 12 via a Serial Advanced Technology Attachment (SATA) interface, a high-speed peripheral component connection interface (PCI Express), a Universal Serial Bus (USB), or other types of connection interfaces. Therefore, the host system 11 can store data in the memory storage device 12 and / or read data from the memory storage device 12.
[0018] The memory storage device 12 may include a connection interface 121, a memory module 122, and a memory controller 123. The connection interface 121 is used to connect the memory storage device 12 to the host system 11. For example, the connection interface 121 may support connection interface standards such as SATA, PCI Express, or USB. The memory storage device 12 may communicate with the host system 11 via the connection interface 121.
[0019] The memory module 122 is used to store data. The memory module 122 may include a rewritable non-volatile memory module. The memory module 122 includes a memory cell array. The memory cells in the memory module 122 store data in the form of voltage. For example, the memory module 122 may include a single level cell (SLC) NAND flash memory module, a multi level cell (MLC) NAND flash memory module, a triple level cell (TLC) NAND flash memory module, a quad level cell (QLC) NAND flash memory module, or other memory modules with similar characteristics.
[0020] The memory controller 123 is connected to the connection interface 121 and the memory module 122. The memory controller 123 can be used to control the memory storage device 12. For example, the memory controller 123 can control the connection interface 121 and the memory module 122 to perform data access and data management. For example, the memory controller 123 may include a central processing unit (CPU), or other programmable general-purpose or special-purpose microprocessors, digital signal processors (Digital Signal Processor, DSP), programmable controllers, application specific integrated circuits (Application Specific Integrated Circuits, ASIC), programmable logic devices (Programmable Logic Device, PLD) or other similar devices or combinations of these devices.
[0021] In one embodiment, the memory controller 123 is also called a flash memory controller. In one embodiment, the memory module 122 is also called a flash memory module. The memory module 122 can receive a command sequence from the memory controller 123 and access the storage unit according to the command sequence.
[0022] Figure 2 FIG. 1 is a schematic diagram of a memory controller according to an embodiment of the present invention. Figure 1 and Figure 2 The memory controller 123 includes a host interface 21, a memory interface 22 and a memory control circuit 23. The host interface 21 is used to connect to the host system 11 via the connection interface 121 to communicate with the host system 11. The memory interface 22 is used to connect to the memory module 122.
[0023] The memory control circuit 23 is connected to the host interface 21 and the memory interface 22. The memory control circuit 23 is responsible for the overall or partial operation of the memory storage device 12. The memory control circuit 23 can communicate with the host system 11 via the host interface 21 and access the memory module 122 via the memory interface 22. In one embodiment, the memory control circuit 23 can also be regarded as the control core of the memory controller 123. In the following embodiments, the description of the memory control circuit 23 is equivalent to the description of the memory controller 123.
[0024] Figure 3 is a schematic diagram of a memory module according to an embodiment of the present invention. Figures 1 to 3 The memory module 122 includes a plurality of physical blocks 30, and each physical block 30 may specifically include a plurality of physical pages 31. A plurality of physical pages 31 in a physical block 30 may be programmed simultaneously to store data. In addition, the stored data of all physical pages 31 in a physical block 30 may be erased simultaneously. That is, the basic read and write unit of the memory module 122 is a page, and the erase operation is performed in blocks. Before writing data to a physical page 31, it must be ensured that the physical block 30 in which it is located has been erased, and each time the physical page 31 needs to rewrite data, the physical block 30 to which it belongs must also be erased. Therefore, the memory module 122 uses blocks as the basic unit to manage data storage.
[0025] After a certain erasing and writing operation, the physical unit of the memory module 122 becomes unstable in the state of 1 or 0. At this time, it is considered that these physical units are damaged, and the overall manifestation is that the stored data is wrong. Although most memory modules 122 have a certain degree of error correction mechanism, once the scope of the error is expanded beyond the error correction capability, the correctness of the data can no longer be guaranteed. At this time, it is considered that the service life of the storage device has expired. However, if the entire memory module 122 cannot be used due to errors in a small number of physical units, it is obviously very wasteful. In view of this situation, the general memory module 122 has a certain bad block management mechanism, and its basic principle is: the memory module 122 is divided into a part of the physical blocks 30 as replacement blocks based on blocks, and the remaining part of the physical blocks 30 are used as effective capacity to store data. During use, when it is detected that the physical block 30 storing data is damaged, one is selected from the replacement block to replace the previously damaged physical block 30, so that the effective storage of the storage device can be guaranteed, thereby extending the service life of the storage device. Only when all the replacement blocks are exhausted, the service life of the entire storage device is considered to have expired. Obviously, the more replacement blocks are retained, the longer the service life of the storage device is, but the corresponding number of blocks used to effectively store data is also smaller, resulting in a smaller effective capacity of the storage device. Therefore, a certain balance needs to be maintained between the two.
[0026] Assume a memory module 122, which has a total of 1024 physical blocks, each physical block contains 128 physical pages, and the size of each physical page is 8K bytes. At this time, the size of each physical block is 1M bytes, and the total physical capacity of the memory module 122 is 1024M bytes. Generally, the memory module 122 can retain about 4% of the physical blocks as replacement blocks, that is, about 40 physical blocks are used for bad block replacement. In this way, all physical blocks are divided into two parts: data area (984 physical blocks) and replacement area (40 physical blocks). The capacity of the data area is 984M, which is the actual effective capacity of the storage device. Among them, the initial state of the mapping relationship table between the logical address and the physical address of the data area is shown in Table 1 below:
[0027]
[0028] It can be seen that when the memory module 122 is initially arranged, it is preferred to divide the continuous physical blocks 301 (1) to physical blocks 301 (984) in the front into the data area, and the remaining physical blocks 301 (985) to physical blocks 301 (1024) are classified as the replacement area. At this time, in its data area, the order of logical addresses, the order of physical blocks, and the order of physical addresses are all continuous. When the physical block in the data area is damaged, it is replaced with the physical block in the replacement area to ensure that the data corresponding to the logical address can still be effectively stored. Taking the damage of physical block 301 (3) as an example, at this time, it needs to be replaced with physical block 301 (985) in the replacement area to ensure that the data corresponding to logical address 3 can still be effectively stored. The mapping relationship table between the logical address and the physical address of the adjusted data area is shown in Table 2 below:
[0029]
[0030] At this time, in the data area, except for the order of logical addresses, the order of physical blocks and physical addresses are not continuous. After the 40 replacement blocks in the replacement area are replaced, the memory module 122 should usually enter the write protection state, that is, only data can be read from it, and data cannot be changed or written, so as to prevent the generation of new physical bad blocks, which will cause data storage errors. In other words, the storage life of the memory module 122 has also expired, and the user can only use it as a read-only device and save the data backup in the memory module 122 to other memory modules as soon as possible. For the memory module 122, if a physical block is defined as a bad block, it is usually not that all physical units in the entire physical block are damaged. In fact, it is often only one or several physical pages, or even a part of the physical units in a physical page, are damaged. Therefore, there are actually many physical pages in the physical block that can be used normally. If the intact physical pages marked as physical bad blocks can be used, such as reorganizing them into replacement blocks, it is equivalent to increasing the number of replacement blocks, thereby extending the service life of the storage device.
[0031] In one embodiment, if Figure 4 As shown, the memory module 122 includes, in addition to a plurality of physical blocks 301(1) to 301(X), a plurality of virtual blocks 302(1) to 302(Y), wherein each virtual block is constructed by a plurality of physical good pages in a plurality of physical bad blocks in the plurality of physical blocks 301(1) to 301(X). Wherein, X and Y both represent positive integers greater than 1, and X should be much greater than Y. Specifically, for the plurality of physical blocks 301(1) to 301(X), since they are all "real", as Figure 5As shown, each physical block is mapped to a specific physical address, such as physical block 1 is mapped to physical address 1, physical block 2 is mapped to physical address 2, and so on. As for multiple virtual blocks 302 (1) to 302 (Y), since they are actually constructed by several physical good pages in several physical bad blocks in multiple physical blocks 301 (1) to 301 (X), they themselves "do not really exist". It should be noted that the above "really exist" and "do not really exist" are relatively colloquial expressions. In addition, because the characteristics of the memory module 122 are block erase and page write. Therefore, both block mapping and page mapping can realize the writing of data in the host system 11 into the pages of the memory module 122. Furthermore, the purpose of block mapping and page mapping is to establish a logical mapping table that maps logical addresses to physical addresses. The memory controller 123 uses the logical mapping table to realize the writing of data from the host system 11 to the memory module 122 or the storage of data from the memory module 122 to the host system 11. Therefore, the mapping method of the memory storage device 12 in the embodiment of the present application is block mapping. In addition to the multiple physical blocks 301 (1) to 301 (X) being block mapping, the multiple virtual blocks 302 (1) to 302 (Y) are also block mapping. In block mapping, the logical address of a logical block can be mapped to the physical address of any physical block, and before and after the mapping, the offset of each physical page in the corresponding physical block remains unchanged. Since the block mapping table only needs to store the mapping of the block, the SRAM space required to store the mapping table is small, which is particularly suitable for the case where the memory storage device 12 is a USB flash drive. This is because the price of a USB flash drive is generally relatively cheap, and the choice of its main control is to choose a cheap one, and the cost of the main control is related to the SRAM. The larger the SRAM capacity, the higher the cost of the main control, so the mapping method of the USB flash drive is all block mapping. At the same time, in order to control costs, the USB flash drive generally also selects a memory module 122 that includes bad blocks or that is prone to bad blocks during use. In this way, the service life of the USB flash drive cannot be guaranteed. In order to further improve the service life of these USB flash drives, the present application needs to rebuild a new virtual block mapping table to find out the physical blocks that constitute the corresponding virtual blocks, and then find out their corresponding physical addresses, so as to reuse the physical bad blocks containing the physical good pages.
[0032] Based on the above, it can be known that, taking the case where all physical blocks are divided into two parts, data area (984 physical blocks) and replacement area (40 physical blocks), when a physical bad block appears in the original data area, it is replaced by a physical block in the replacement area. Since different physical blocks have different degrees of damage, the number of physical bad pages in the physical bad blocks replaced in the original data area is different. In the related art, when the memory storage device 12 is manufactured and formatted for the first time (also known as card opening), the memory control circuit 23 will write, read and erase all physical blocks 30 in the memory module 122, and establish a bad block table, which records the status of all physical blocks in the memory module 122, such as the number of error bits of each physical block 30. In actual situations, due to the existence of ECC (abbreviation of "Error Correcting Code", the Chinese name is "error checking and correction"), and different memory control circuits 23 may have different ECC correction capabilities. The ECC correction capability of the memory control circuit 23 refers to the maximum threshold that can be corrected when the number of error bits in the physical block controlled by it occurs. For the current memory control circuit 23, when the number of error bits of a physical block 30 is greater than the threshold of its ECC correction capability, it means that the physical block 30 is unusable and is a physical bad block.
[0033] The bad block table of the memory module 122 records the physical block status of the memory module 122, such as the number of error bits of each physical block 30. Specifically, which physical blocks 30 can pass the test because they do not have a bit error number, and which physical blocks 30 can pass the test because of ECC correction, and the details are recorded. Taking the current memory control circuit 23 with an ECC correction capability of 16 bits as an example, the physical blocks with an error bit number of no more than 16 bits can be considered to have passed the test and can be used, as shown in the following Table 3:
[0034]
[0035] Table 3 is only a schematic table made for the convenience of explaining the working principle of the bad block table of the present application, and is not the actual form of the bad block table. The ECC correction capability mentioned above depends on the memory control circuit 23, which is set in the memory control circuit 23 in the form of an error checking and correction circuit, and the different encoding and decoding methods also correspond to the ECC correction capability, such as BCH and LDPC, the correction methods of the two are different, the latter is a probability check, in simple terms, after exceeding the threshold, the error is likely to be unable to be corrected, this embodiment does not make specific limitations, but is just an example.
[0036] The bad block table mentioned above is established when the memory storage device 12 is turned on, and is updated during use. In the above Table 3, the physical blocks 30 with physical addresses PBA(1) to PBA(a) have 0 error bits, the physical blocks 30 with physical addresses PBB(1) to PBB(b) have 1 error bit, the physical blocks 30 with physical addresses PBC(1) to PBC(c) have 2 error bits, ..., the physical blocks 30 with physical addresses PBQ(1) to PBQ(q) have 16 error bits, and the physical blocks 30 with physical addresses PBR(1) to PBR(r) are physical bad blocks (indicates that the error bits of these physical blocks 30 are greater than 16). These physical bad blocks are available at the factory or generated during use. The letters a to r in Table 1 all represent positive integers greater than 1, and the positive integers represented by two different letters may be equal or unequal.
[0037] In one example, the memory control circuit 23 is used to obtain all physical bad blocks in multiple physical blocks 301 (1) to 301 (X), and establish a first bad block record table according to the good or bad conditions of all physical pages in each physical bad block. Specifically, taking r as 10 in the above Table 3 as an example, the physical blocks 30 with physical addresses PBR (1) to PBR (10) in the multiple physical blocks 301 (1) to 301 (X) are physical bad blocks, which correspond to physical blocks 301 (5), physical blocks 301 (12), physical blocks 301 (15), physical blocks 301 (17), physical blocks 301 (21), physical blocks 301 (23), physical blocks 301 (40), physical blocks 301 (50), physical blocks 301 (61) and physical blocks 301 (71) in sequence. At this time, the physical bad blocks are respectively erased and tested for data writing, and a first bad block record table can be established, which records the good and bad conditions of all physical pages in each physical bad block. Taking the physical bad block as physical block 301 (5) as an example, it includes a total of 128 physical pages. The first bad block record table can record which physical pages are physical good pages (specifically, the corresponding physical pages can be marked as 0) and which physical pages are physical bad pages (specifically, the corresponding physical pages can be marked as 1) among the 128 physical pages of the physical block 301 (5). For example, the first bad block record table can be specifically shown in Table 4 below:
[0038]
[0039] At this time, in one example, Figure 6As shown, the process of the memory control circuit 23 for constructing a virtual block through the physical good pages in several physical bad blocks in multiple physical blocks 301 (1) to 301 (B) is specifically as follows: In step S11, a first bad block record table is obtained, and the first bad block record table records the physical page good and bad information of all physical bad blocks in multiple physical blocks. In step S12, all physical bad blocks in the first bad block record table are sorted by the number of good and bad pages according to the physical page good and bad information to obtain a second bad block record table. In step S13, a bad block group is obtained based on the second bad block record table, and the sum of the number of all physical good pages in the bad block group is greater than or equal to a first preset page number threshold. In step S14, a virtual block is established based on the bad block group, and a virtual block mapping table is established according to the mapping relationship between the address of the virtual block and the address of the corresponding physical bad block. Figure 6 The steps will be described in detail below and will not be repeated here.
[0040] In one example, the memory control circuit 23 is used to obtain a first bad block record table, which records the physical page good or bad information of all physical bad blocks in multiple physical blocks. The first bad block record table can be specifically as shown in Table 4 above, which records the physical page good or bad information of all physical bad blocks in multiple physical blocks 301 (1) to 301 (X). According to the order of the physical pages in the corresponding physical bad blocks, the physical page good or bad information can be reflected in the form of a string in Table 4, that is, the column corresponding to the physical page good or bad information in Table 4 can be specifically a string with a word length of 128 bits, and each bit corresponds to marking the good or bad information of a physical page. The column of the number of physical good pages in Table 4 is mainly used to reflect the number of physical pages marked as physical good pages in the physical page good or bad information, that is, the number of "0" in the corresponding string. This item may not be listed separately in the actual first bad block record table.
[0041] In one example, the memory control circuit 23 is used to sort the number of good and bad pages of all physical bad blocks in the first bad block record table according to the physical page good and bad information to obtain the second bad block record table. The specific process can be as follows: all physical bad blocks in the first bad block record table are re-sorted in the order of the number of physical good pages from most to least to obtain the second bad block record table. That is, the number of physical good pages of each physical bad block, that is, the number of "0" in the corresponding character string, can be obtained by counting the physical page good and bad information corresponding to each physical bad block, and then all physical bad blocks in the first bad block record table are re-sorted in the order of the number of physical good pages from most to least to obtain the second bad block record table. Specifically, the first bad block record table in Table 4 is taken as an example, and the second bad block record table obtained after re-sorting is shown in Table 5 below:
[0042]
[0043] For those skilled in the art, the above reordering can also be adjusted according to actual needs, that is, all physical bad blocks in the first bad block record table are reordered in order from small to large in the number of physical good pages to obtain the above second bad block record table. The sorting effect of the newly obtained second bad block record table is the same as the sorting effect of the original second bad block record table.
[0044] In one example, the memory control circuit 23 is used to obtain a bad block group based on the second bad block record table, and the sum of the number of all physical good pages in the bad block group is greater than or equal to the first preset page number threshold. The specific process may be: at least two physical bad blocks are obtained from the second bad block record table in order from both ends to the middle to form a bad block group, and the sum of the number of all physical good pages in the bad block group is greater than or equal to the first preset page number threshold. In principle, the number of physical bad blocks that constitute a bad block group can be any value greater than 1, but since the purpose of obtaining a bad block group is to subsequently establish a corresponding virtual block based on the bad block group, the more physical bad blocks used to construct the same virtual block, the more it will affect the mapping management of the constructed virtual block. Because it spans too many physical blocks, the data reading and writing speed based on this mapping management method will be relatively slow. Therefore, it is preferred to obtain two or three physical bad blocks to form the above-mentioned bad block group. A virtual block can be formed by two or three physical bad blocks, which makes the subsequent mapping management very convenient, and the data reading and writing speed can also be not much different from the speed of physical blocks 301 (1) ~ 301 (X). It is especially suitable for adjusting physical bad blocks with a large number of physical bad pages, because by establishing the first bad block record table and optimizing the first bad block record table to obtain the second bad block record table, the maximum number and the minimum number of physical good pages in the physical bad block are very intuitively presented. In the subsequent algorithm operation process, it is only necessary to perform an addition operation according to the second bad block record table, and then construct the virtual block. The speed of constructing the virtual block will be very fast when the program runs, which makes the subsequent mapping management very convenient, and the bad block management can be completed quickly. The subsequent virtual block construction process is dynamically adjusted.
[0045] When two physical bad blocks are obtained from the second bad block record table in the order from both ends to the middle to form a bad block group, a physical bad block can be obtained from the head of the current second bad block record table and a physical bad block can be obtained from the tail of the current second bad block record table to form a bad block group through these two physical bad blocks. Taking the second bad block record table in Table 3 as an example, a bad block group is formed by physical block 301 (71) and physical block 301 (23). When three physical bad blocks are obtained from the second bad block record table in the order from both ends to the middle to form a bad block group, a physical bad block can be obtained from the head of the current second bad block record table and two physical bad blocks can be obtained from the tail of the current second bad block record table to form a bad block group through these three physical bad blocks. Taking the second bad block record table in Table 3 as an example, a bad block group is formed by physical block 301 (71), physical block 301 (61) and physical block 301 (23).
[0046] Based on the above, since the purpose of obtaining the bad block group is to subsequently establish the corresponding virtual block based on the physical good pages in the bad block group, the sum of the number of all physical good pages in the bad block group should be greater than or equal to the total number of pages of the virtual block to be constructed, that is, the first preset page number threshold. There are two types of settings for virtual blocks, one is that the number of its pages is the same as the number of physical pages of the existing physical bad blocks, that is, the first preset page number threshold is the number of all physical pages in a physical block, such as 128; the other is a dynamic value, the size of which is related to the number of physical good pages in the second bad block record table. For example, if the number of all physical good pages in two or three physical bad blocks in the second bad block record table is less than 128, then the value of the first preset page number threshold is adjusted and set.
[0047] In one example, the memory control circuit 23 is used to establish a virtual block based on a bad block group. Taking the bad block group including two physical bad blocks as an example, the specific process is as follows: if the bad block group includes two physical bad blocks, the physical bad block with a larger number of physical good pages is the first physical bad block, and the physical bad block with a smaller number of physical good pages is the second physical bad block; all physical good pages of the first physical bad block and some physical good pages of the second physical bad block are respectively obtained to establish a virtual block, and the sum of the number of all physical good pages and the number of some physical good pages is equal to the first preset page number threshold. Taking the second bad block record table of Table 5 as an example, when a bad block group is formed by physical block 301 (71) and physical block 301 (23), all physical good pages (specifically 113) in physical block 301 (71) and some physical good pages (specifically 15) in physical block 301 (23) are obtained to establish a corresponding virtual block. In this way, it can be ensured that most of the physical pages contained in the created virtual block are located in the same physical bad block, so as to facilitate subsequent mapping management and improve the corresponding reading and writing speed.
[0048] The establishment of a virtual block is generally established through two physical bad blocks, which has the best effect. However, there may be the following situation: the number of all physical pages in the two physical bad blocks cannot meet the requirements for establishing a virtual block, that is, the number of all physical pages in the two physical bad blocks is less than the first preset page number threshold. In this case, a suboptimal solution can be selected, that is, the virtual block is proposed through three physical bad blocks. In an example, the memory control circuit 23 is used to establish a virtual block based on a bad block group. Taking the bad block group including three physical bad blocks as an example, the specific process can be as follows: if the bad block group includes three physical bad blocks, the three physical bad blocks are arranged in descending order according to the number of physical good pages, namely, the first physical bad block, the second physical bad block, and the third physical bad block; all physical good pages of the first physical bad block and the second physical bad block and some physical good pages of the third physical bad block are obtained respectively to establish a virtual block, and the sum of the number of all physical good pages and the number of some physical good pages is equal to the first preset page number threshold. In this way, it can be ensured that most of the physical pages contained in the created virtual block are located in the first two physical bad blocks, so as to facilitate subsequent mapping management and improve the corresponding reading and writing rates.
[0049] Since the distribution of good and bad pages in different physical bad blocks may not be the same, it is possible that the physical good pages in the physical bad blocks with a larger number of physical good pages are more evenly distributed, or it is possible that the physical good pages in the physical bad blocks with a smaller number of physical good pages are more evenly distributed. At this time, simply establishing a virtual block in the above manner does not mean that the mapping management is optimal. Therefore, in one example, the memory control circuit 23 is used to establish a virtual block based on the bad block group, and the specific process can also be as follows: divide all physical bad blocks in the bad block group into multiple first segments; obtain multiple first target segments whose number of physical good pages is greater than or equal to the second preset page number threshold from the multiple first segments; obtain multiple target physical good pages from the multiple first target segments to establish a virtual block, and the number of multiple target physical good pages is equal to the first preset page number threshold. The above-mentioned second preset page number threshold is preferably half of the number of all physical pages in a first segment. Similarly, taking the second bad block record table in Table 5 as an example, when physical block 301 (71) and physical block 301 (23) form a bad block group, physical block 301 (71) and physical block 301 (23) can be specifically divided into 8 first segments. At this time, each first segment contains 32 consecutive physical pages. When selecting the first target segment, only the first segment whose number of physical good pages is greater than or equal to the second preset page number threshold (i.e., 16) is selected as the first target segment. Furthermore, for some first segments to be abandoned, a setting is made in the second bad block record table, so that when the mapping management pointer jumps, it is skipped; jump to the next first segment that meets the needs. For example, if the number of physical bad pages in a first segment is 8, mapping management can perform mapping management on 24 physical good pages among 32 physical pages; if the number of physical bad pages in a first segment is 24, mapping management can only perform mapping management on 8 physical good pages among 32 physical pages, which will affect the speed, so it is abandoned; when mapping management starts, it is skipped and other suitable first segments are found. After obtaining multiple suitable first target segments, multiple target physical good pages can be obtained from multiple first target segments to establish a virtual block, and the number of multiple target physical good pages is equal to the first preset page number threshold. Compared with the original management of the entire block, the current management is more refined. Through the setting of the second preset page number threshold, some first segments of the physical bad block are directly abandoned, which will not affect the difficulty of mapping management and thus affect the data reading and writing speed.
[0050] In one example, the memory control circuit 23 is used to establish a virtual block based on a bad block group, and the specific process can also be as follows: divide all physical bad blocks in the bad block group into multiple second segments; obtain multiple second target segments whose number of continuous physical good pages is greater than or equal to a third preset page number threshold from the multiple second segments; obtain multiple target physical good pages from the multiple second target segments to establish a virtual block, and the number of the multiple target physical good pages is equal to the first preset page number threshold. The above-mentioned third preset page number threshold is preferably half of the number of all physical pages in a second segment. Similarly, taking the second bad block record table of Table 5 as an example, that is, when a bad block group is formed by physical block 301 (71) and physical block 301 (23), physical block 301 (71) and physical block 301 (23) can be specifically divided into 4 second segments. At this time, each segment contains 64 continuous physical pages. When selecting the second target segment, only the segment whose number of physical good pages is greater than or equal to the third preset page number threshold (i.e., 32) is selected as the second target segment. Furthermore, for some second segments that are to be abandoned, a setting is made in the second bad block record table, and when the mapping management pointer jumps, it is skipped; jump to the next second segment that meets the needs. For example, if the number of consecutive physical good pages in a certain second segment is 50, the mapping management can perform continuous mapping management on 50 consecutive physical good pages among 64 physical pages, which can effectively improve the mapping management speed. After obtaining multiple suitable second target segments, multiple target physical good pages can be obtained from the multiple second target segments to establish a virtual block, and the number of multiple target physical good pages is equal to the first preset page number threshold. Compared with the original management of the entire block, the current management is more refined. Through the setting of the third preset page number threshold, some second segments of the physical bad block are directly abandoned, which will not affect the difficulty of mapping management, and thus affect the data reading and writing speed.
[0051] In one example, the memory control circuit 23 is used to establish a virtual block based on the bad block group in the above manner, and to establish a virtual block mapping table according to the mapping relationship between the address of the virtual block and the physical address of the corresponding physical bad block. The virtual block is established as a column in the second bad block record table shown in Table 5. The simple mapping method can be finally as follows: Figure 7 shown.
[0052] That is, through the above Figure 7 The virtual block mapping table shown can find the physical address of the physical bad block corresponding to each virtual block, and can find the address of the physical bad block corresponding to each physical good page in the virtual block, so as to perform corresponding data read and write operations on the virtual block. Taking virtual block 302 (1) as an example, through Figure 7The virtual block mapping table shown can specifically find out that it is constructed by the physical good pages of the physical bad blocks (including physical block 301 (71) and physical block 301 (23)). Therefore, the physical address 71 (specifically PBR (10)) corresponding to the physical block 301 (71) and the physical address 23 (specifically PBR (6)) corresponding to the physical block 301 (23) can be found, and the address of the physical bad block corresponding to each physical good page in the virtual block 302 (1) can be found to perform corresponding data reading and writing operations on the virtual block 302 (1). The constructed virtual block can be placed in the replacement area for standby use. Similarly, taking the damage of the physical block 301 (3) in the data area in Table 1 as an example, at this time, the virtual block 302 (1) in the replacement area can be replaced to ensure that the data corresponding to the logical address 3 can still be effectively stored. The mapping relationship table between the logical address and the physical address of the adjusted data area is shown in Table 6 below:
[0053]
[0054] In one example, when the memory control circuit 23 is used to read data from a virtual block, the address of the physical bad block corresponding to the physical good page currently storing data is found according to the preset virtual block mapping table to read the data in the physical good page storing data. The preset virtual block mapping table is the virtual block mapping table synchronously established in the above virtual block establishment process, such as Figure 6 As shown in the virtual block mapping table, when data is read from the virtual block 302(1), assuming that a physical good page in the physical block 301(71) stores data to be read, the physical address 71 (specifically PBR(10)) of the physical block 301(71) corresponding to the virtual block 302(1) can be found according to the virtual block mapping table to perform the corresponding data reading operation on the physical good page.
[0055] In one example, when the memory control circuit 23 is used to write data to the virtual block, the address of the physical bad block corresponding to the current blank physical good page is found according to the preset virtual block mapping table, so as to write the data to the blank physical good page. The preset virtual block mapping table is the virtual block mapping table synchronously established in the above virtual block establishment process, as described above. Figure 6 As shown in the virtual block mapping table, when data is written to the virtual block 302(1), assuming that a physical good page in the physical block 301(23) is blank, the physical address 23 (specifically PBR(6)) of the physical block 301(23) corresponding to the virtual block 302(1) can be found according to the above virtual block mapping table to perform the corresponding data writing operation on the blank physical good page.
[0056] Figure 8 is a flow chart of a data reading and writing method according to an embodiment of the present invention. Figure 4 In step S401, when reading data from a virtual block, the address of a physical bad block corresponding to a physical good page currently storing data is found according to a preset virtual block mapping table, so as to read the data in the physical good page storing data. In step S402, when writing data to a virtual block, the address of a physical bad block corresponding to a current blank physical good page is found according to a preset virtual block mapping table, so as to write the data into the blank physical good page.
[0057] However, Figure 8 The steps in the above are described in detail, so I will not repeat them here. It is worth noting that Figure 8 Each step in the above process can be implemented as multiple program codes or circuits, and the present invention is not limited thereto. Figure 8 The method can be used in conjunction with the above exemplary embodiments or can be used alone, and the present invention is not limited thereto.
[0058] In summary, the present application reuses the generated physical bad blocks by means of block mapping, constructs virtual blocks and corresponding virtual block mapping tables, so that the original physical bad blocks can be reused, that is, the established virtual blocks can be used as replacement blocks for normal use (including data reading and data writing). At the same time, the virtual blocks are constructed from the original physical bad blocks, which does not change the proportion and number of the replacement blocks initially set, and thus does not change the effective storage capacity of the storage device. In this way, the service life of the memory storage device can be greatly extended without changing the effective storage capacity of the memory storage device.
[0059] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A data reading and writing method, characterized in that: Used for a memory storage device, wherein the memory storage device includes a memory module, the memory module includes a plurality of physical blocks and a plurality of virtual blocks, the physical block includes a plurality of physical pages, the virtual block is constructed by physical good pages in a plurality of physical bad blocks in the plurality of physical blocks, the construction process includes obtaining a first bad block record table, the first bad block record table records physical page good or bad information of all physical bad blocks in the plurality of physical blocks, sorting all physical bad blocks in the first bad block record table based on the number of good pages according to the physical page good or bad information, obtaining a second bad block record table, and sorting the physical bad blocks in the second bad block record table according to the physical page good or bad information. At least two of the physical bad blocks are respectively obtained from both ends to the middle to form a bad block group, and the sum of the numbers of all physical good pages in the bad block group is greater than or equal to a first preset page number threshold, the virtual block is established based on all physical good pages in the bad block with a larger number of good pages in the bad block group, and some physical good pages in the bad block with a smaller number of good pages, and the virtual block mapping table is established, wherein the sum of the number of all physical good pages and the number of some physical good pages is equal to the first preset page number threshold, and the first preset page number threshold is the number of all physical pages in one of the physical blocks, and the data reading and writing method includes: When reading data from the virtual block, the physical address of the physical bad block corresponding to the physical good page currently storing the data is found out by block mapping according to the preset virtual block mapping table, so as to read the data in the physical good page storing the data; When data is written to the virtual block, the physical address of the physical bad block corresponding to the current blank physical good page is found out by block mapping according to the preset virtual block mapping table, so as to write the data into the blank physical good page.
2. The data reading and writing method according to claim 1, characterized in that: Before the operation of obtaining a first bad block record table in which the physical page good or bad information of all physical bad blocks in the multiple physical blocks is recorded, the method further includes: All physical bad blocks are obtained from the multiple physical blocks, and the first bad block record table is established according to the good or bad conditions of all physical pages in each of the physical bad blocks.
3. The data reading and writing method according to claim 1, characterized in that: The operation of sorting the good and bad pages of all physical bad blocks in the first bad block record table according to the physical page good and bad information to obtain the second bad block record table includes: All physical bad blocks in the first bad block record table are reordered in descending order of the number of physical good pages to obtain the second bad block record table.
4. The data reading and writing method according to claim 1, characterized in that: The operation of establishing the virtual block based on the bad block group includes: If the bad block group includes two physical bad blocks, the physical bad block with more physical good pages is the first physical bad block, and the physical bad block with less physical good pages is the second physical bad block; All physical good pages of the first physical bad block and some physical good pages of the second physical bad block are respectively obtained to establish the virtual block, and the sum of the number of all physical good pages and the number of some physical good pages is equal to the first preset page number threshold.
5. The data reading and writing method according to claim 4, characterized in that: The operation of establishing the virtual block based on the bad block group further includes: If the bad block group includes three physical bad blocks, the three physical bad blocks are arranged in descending order of the number of physical good pages and are the first physical bad block, the second physical bad block and the third physical bad block; The virtual block is established by respectively acquiring all physical good pages of the first physical bad block and the second physical bad block and some physical good pages of the third physical bad block, wherein the sum of the number of all physical good pages and the number of some physical good pages is equal to the first preset page number threshold.
6. The data reading and writing method according to claim 1, characterized in that: The operation of establishing the virtual block based on the bad block group includes: Dividing all physical bad blocks in the bad block group into a plurality of first sections; Acquire, from the plurality of first segments, a plurality of first target segments in which the number of physical good pages is greater than or equal to a second preset page number threshold; A plurality of target physical good pages are acquired from the plurality of first target sections to establish the virtual block, wherein the number of the plurality of target physical good pages is equal to the first preset page number threshold.
7. The data reading and writing method according to claim 6, characterized in that: The second preset page number threshold is half of the number of all physical pages in one of the first sections.
8. The data reading and writing method according to claim 1, characterized in that: The operation of establishing the virtual block based on the bad block group includes: Dividing all physical bad blocks in the bad block group into a plurality of second sections; Acquire, from the plurality of second segments, a plurality of second target segments in which the number of continuous physical good pages is greater than or equal to a third preset page number threshold; A plurality of target physical good pages are acquired from the plurality of second target sections to establish the virtual block, wherein the number of the plurality of target physical good pages is equal to the first preset page number threshold.
9. The data reading and writing method according to claim 8, characterized in that: The third preset page number threshold is half of the number of all physical pages in one second section.
10. A memory storage device, characterized in that: include: A connection interface for connecting to a host system; A memory module, comprising a plurality of physical blocks and a plurality of virtual blocks, wherein the physical blocks include a plurality of physical pages, and the virtual blocks are constructed by physical good pages in a plurality of physical bad blocks in the plurality of physical blocks; a memory controller connected to the connection interface and the memory module, The memory controller is used to execute the data reading and writing method as described in any one of claims 1-9.
11. A memory controller, characterized in that: The memory module is used to control a memory module, wherein the memory module includes a plurality of physical blocks and a plurality of virtual blocks, the physical block includes a plurality of physical pages, the virtual block is constructed by physical good pages in a plurality of physical bad blocks in the plurality of physical blocks, and the memory controller includes: A host interface for connecting to a host system; a memory interface for connecting to the memory module; and A memory control circuit connected to the host interface and the memory interface, The memory control circuit is used to execute the data reading and writing method as described in any one of claims 1-9.
Citation Information
Patent Citations
Method for writing in and reading out data based on virtual block flash memory address mapping
CN101727295A
Bad block management method for storage device
CN102622306A