Data replication method and device, computer equipment and storage medium
By obtaining and utilizing the mapping relationship table of data sectors, data erasing is realized in page units, and by recycling and adjusting the number of sectors, the problems of low data erasing efficiency and unbalanced memory wear in the prior art are solved. , realizes efficient data erasing and balanced memory usage.
Patent Information
- Application Number
- CN202411178330.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2024-11-29
AI Technical Summary
The prior art cannot realize data erasing in page units, resulting in low data erasing efficiency and unbalanced memory wear.
By obtaining the mapping relationship table of the logical identification and physical identification of the data sector, divide the data groups according to the logical start address and the preset page size and copy the data in the target data sector except the page to be erased to the exchange data In sectors, data erasing is implemented in page units, and the wear of memory is balanced by recycling the mapping sectors and adjusting the number of sectors.
The data erasing operation in page units is realized, which reduces the number of data erasing times and the number of changes in the exchange data sectors, reduces the loss of data sectors, ensures the wear balance of the mapping sectors, and avoids data loss.
Smart Images

Figure CN119045741A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technology, and in particular to a data replication method, device, computer equipment and storage medium. Background Art
[0002] In the field of storage technology, the memory can be divided into blocks, sectors and pages. That is, the memory is divided into multiple blocks, each block is divided into multiple sectors, and each sector is divided into multiple pages.
[0003] When erasing data in a memory, the minimum erasing unit specified by the memory is a sector, and the related art cannot achieve data erasing in units of pages. Summary of the invention
[0004] In view of this, the present invention provides a data replication method, apparatus, computer equipment, storage medium and program product to solve the problem that the related art cannot realize data erasure in units of pages.
[0005] In a first aspect, the present invention provides a data replication method, the method comprising:
[0006] When receiving a data erasure instruction, obtaining a first mapping relationship table of logical identifiers and physical identifiers of data sectors, wherein the data erasure instruction includes at least one logical start address;
[0007] According to the preset mark, obtaining a first physical identifier of the exchange data sector from the first mapping relationship table;
[0008] Determine a logical identifier corresponding to each of the logical start addresses according to each of the logical start addresses and a preset sector size;
[0009] Determine a page identifier corresponding to each of the logical start addresses according to each of the logical start addresses, a preset number of pages, and a preset page size;
[0010] Divide the logical start addresses with the same logical identifier into the same data group to obtain at least one data group;
[0011] According to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, the data in other pages of the target data sector except the page corresponding to the page identifier corresponding to each logical start address in the target data group is copied to the exchange data sector, wherein the target data group is any one of at least one of the data groups, and the target data sector is the sector indicated by the target physical identifier corresponding to the target logical identifier in the first mapping relationship table.
[0012] The data replication method provided by the present invention has the following advantages:
[0013] After receiving the data erase instruction, the storage controller can obtain the first mapping relationship table. For the target logical starting address, the storage controller can determine the target logical identifier corresponding to the target logical starting address according to the target logical starting address, and then determine the corresponding target physical identifier according to the target logical identifier and the first mapping relationship table. In addition, the storage controller can obtain the first physical identifier as the exchange data sector, and further, according to the target physical identifier, the data of other pages except the page to be deleted can be copied from the target data sector to the exchange data sector, so that the data in the exchange data sector is the data corresponding to the target logical identifier. In this way, for the data stored in the exchange data sector, it can be considered that the erase operation has been completed, that is, this scheme can realize the data erase operation in units of pages.
[0014] In an optional implementation, the step of copying data in other pages of the target data sector except for a page corresponding to a page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size, and the first physical identifier, includes:
[0015] According to the target logical identifier corresponding to the target data group, determining the target physical identifier corresponding to the target logical identifier in the first mapping relationship table;
[0016] Determining a starting physical position of the target data sector according to the target physical identifier and the preset sector size;
[0017] According to the starting physical position of the target data sector, traverse each page included in the target data sector;
[0018] Each time a page is traversed, the ID of the target page is obtained;
[0019] Determining, according to the identifier of the target page, whether the identifier of the target page is a page identifier corresponding to a logical start address in the target data group;
[0020] When it is determined that the identifier of the target page is a page identifier corresponding to a logical start address in the target data group, continue to traverse the next page in the target data sector;
[0021] or,
[0022] When it is determined that the identifier of the target page is not a page identifier corresponding to any logical start address in the target data group, determining the starting physical position of the exchange data sector according to the first physical identifier and the preset sector size;
[0023] Copying data in a target page of the target data sector to a target page of the exchange data sector according to a starting physical position of the exchange data sector, an identifier of the target page and the preset page size;
[0024] Continue to traverse the next page in the target data sector until all pages in the target data sector are traversed and then stop traversing.
[0025] Specifically, since each data group corresponds to the same data sector, each data group is processed separately, and the data that need to be erased in the same data sector can be processed at the same time, that is, by traversing each page in the target data sector, the data that does not need to be erased is copied, and the data that needs to be erased is retained, which can reduce the number of data erasures and the number of changes in the exchange data sector, and further reduce the degree of loss of the data sector.
[0026] In an optional implementation, when receiving the data erasure instruction, obtaining a first mapping relationship table of logical identifiers and physical identifiers of data sectors includes:
[0027] Obtain physical identifiers corresponding to multiple mapping sectors respectively;
[0028] According to the physical identifier corresponding to each of the mapping sectors, traverse each of the mapping sectors;
[0029] Each time when a mapping sector is traversed, determining whether the first mapping relationship table is stored in the traversed first mapping sector;
[0030] When it is determined that the first mapping relationship table is stored in the first mapping sector, reading the first mapping relationship table from the first mapping sector;
[0031] or,
[0032] When it is determined that the first mapping relationship table is not stored in the traversed mapping sector, the next mapping sector is traversed until a mapping sector storing the first mapping relationship table is determined, the first mapping relationship table is read, and the traversal operation is stopped.
[0033] Specifically, if only one mapping sector is retained to store the mapping relationship, the mapping sector may have a large number of data writes and erases, which may lead to a large loss of the mapping sector and make it impossible to continue to store data. In addition, if a power outage occurs during the process of modifying the mapping relationship, it may make it impossible to read the data in the memory, that is, cause data loss. This solution can solve these problems. First, each time the mapping relationship table is modified, a mapping sector is replaced for storage, so that multiple mapping sectors can be recycled and the wear of the mapping sectors is guaranteed. Secondly, according to the actual needs of the memory, the number of mapping sectors can be adjusted. When the number of mapping sectors is large, the number of data writes and erases for each mapping sector can be reduced to reduce losses.
[0034] In an optional implementation, after copying data in other pages of the target data sector except for the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, the method further includes:
[0035] According to the first physical identifier, determining in the first mapping relationship table a first logical identifier corresponding to the first physical identifier;
[0036] The physical identifier corresponding to the target logical identifier in the first mapping relationship table is modified to the first physical identifier, and the physical identifier corresponding to the first logical identifier in the first mapping relationship table is modified to the target physical identifier to obtain a second mapping relationship table.
[0037] Specifically, after completing the update of the mapping relationship table, the second mapping relationship table can indicate the latest data status in the current memory. The first physical identifier can be determined through the target logical identifier and the second mapping relationship table. The actual data after erasing can be read in the data sector corresponding to the first physical identifier. That is, this solution can meet the needs of erasing data in pages.
[0038] In an optional implementation, when it is determined that the first mapping relationship table is stored in the first mapping sector, the method further includes:
[0039] According to the physical identifier of each of the mapping sectors, obtaining a ranking corresponding to each of the mapping sectors;
[0040] Determining, according to the order corresponding to each of the mapping sectors, a second mapping sector that is ordered after the first mapping sector;
[0041] storing the second mapping relationship table in the second mapping sector;
[0042] The first mapping relationship table is deleted from the first mapping sector.
[0043] Specifically, since the old mapping relationship table is deleted only when the new mapping relationship table is completed, even if power failure occurs during the process of modifying the mapping relationship, data can be read through the old mapping relationship table, thus avoiding data loss caused by power failure.
[0044] In an optional implementation, after copying data in other pages of the target data sector except for the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, the method further includes:
[0045] The target data sector is marked as a new exchange data sector.
[0046] Specifically, since the data in the current target data sector is already in the old data state, the target data sector can be used as a new exchange data sector. When erasing the data in other data sectors, the data in other data sectors can be copied to the new exchange data sector, and the other data sectors can become new exchange data sectors. In this way, each data sector can be recycled and wear leveling of each data sector in the storage area can be achieved.
[0047] In an optional implementation, after copying data in other pages of the target data sector except for a page corresponding to a page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size and the preset page size, the method further includes:
[0048] When receiving a data write instruction for the target data sector, erasing the data in the target data sector;
[0049] According to the write data instruction, a write data operation is performed in the target data sector.
[0050] Specifically, during the process of copying data from the target data sector to the exchange data sector, a power outage may occur. At this time, the mapping relationship table is not updated, the data is not completely copied, and the storage controller can still find the data according to the old mapping relationship. However, if a power outage occurs after the data copy process is completed and before the mapping relationship table is updated, the data cannot be found through the old mapping relationship table. Therefore, this solution performs a data erase operation before writing data to the target data sector, which can avoid the problem of data loss caused by power outage.
[0051] In a second aspect, the present invention provides a data replication device, the device comprising:
[0052] an acquisition module, configured to acquire a first mapping relationship table of logical identifiers and physical identifiers of data sectors when receiving a data erasure instruction, wherein the data erasure instruction includes at least one logical start address; and acquire a first physical identifier of the exchange data sector from the first mapping relationship table according to a preset mark;
[0053] A determination module, configured to determine a logical identifier corresponding to each of the logical start addresses according to each of the logical start addresses and a preset sector size; and to determine a page identifier corresponding to each of the logical start addresses according to each of the logical start addresses, a preset number of pages and a preset page size;
[0054] A grouping module, used for grouping logical start addresses with the same logical identifier into the same data group to obtain at least one data group;
[0055] A copy module, used for copying data in other pages of the target data sector except the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, wherein the target data group is any one of at least one of the data groups, and the target data sector is the sector corresponding to the target physical identifier corresponding to the target logical identifier in the first mapping relationship table.
[0056] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the data copying method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0057] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the data replication method of the first aspect or any corresponding embodiment thereof.
[0058] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the data replication method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the related technologies, the drawings required for use in the specific embodiments or the related technical descriptions will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0060] Figure 1 is a schematic diagram of the architecture of a storage system according to an embodiment of the present invention;
[0061] Figure 2 is a flow chart of a data replication method according to an embodiment of the present invention;
[0062] Figure 3 is a schematic diagram of a processing flow of a data erasing instruction 1 according to an embodiment of the present invention;
[0063] Figure 4 is a schematic diagram of a processing flow of a data erasing instruction 2 according to an embodiment of the present invention;
[0064] Figure 5 is a schematic diagram of a processing flow of a data erasing instruction 3 according to an embodiment of the present invention;
[0065] Figure 6 is a structural block diagram of a data replication device according to an embodiment of the present invention;
[0066] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0068] An embodiment of the present invention provides a storage system, such as Figure 1 As shown, the storage system includes a storage controller and a memory. The memory can be a Flash memory or the like. The memory can be divided into multiple data blocks (Block) according to a preset block size, each data block can be divided into multiple sectors (Sector) according to a preset sector size, and each sector can be divided into multiple pages (Page) according to a preset page size. The multiple sectors of the memory may include multiple data sectors and multiple mapping sectors. The storage controller is used to perform write operations, read operations, erase operations, etc. on the data sectors. The data sector is used to store data received from other components, and the mapping sector is specifically used to store a mapping relationship table of the logical identifier and the physical identifier of the data sector. For example, the mapping relationship table can be as follows:
[0069] map[0] = 0
[0070] map[1]=1
[0071] …
[0072] map[swap]=63, swap=63
[0073] The data in [] are used to represent logical identifiers, and the data on the right side of the equal sign are used to represent physical identifiers.
[0074] When developing secure storage related products, key storage and destruction operations are often involved, for example, erasing data in the flash memory chip of the encrypted USB shield. When receiving a data erase instruction, the storage controller of the encrypted USB shield can erase the corresponding data according to the logical starting address of the data erase instruction.
[0075] The embodiment of the present invention provides a data copying method, which does not require hardware improvement of the memory. When erasing data, other data except the data to be erased in the corresponding sector can be copied to other sectors, and data erasure in units of pages can be realized.
[0076] According to an embodiment of the present invention, a data replication method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0077] In this embodiment, a data replication method is provided, which can be executed by the above storage controller. Figure 2 is a flow chart of a data replication method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0078] Step S201: when a data erasing instruction is received, a first mapping relationship table between a logical identifier and a physical identifier of a data sector is obtained.
[0079] The data erasing instruction may include at least one logical start address.
[0080] Specifically, after the user performs a data deletion operation on the terminal, a corresponding data erasure instruction is generated and sent to the storage controller. After receiving the data erasure instruction, the storage controller can extract one or more logical start addresses from the data erasure instruction.
[0081] Since the operation on data requires the physical location information of the data, the storage controller can first obtain the first mapping relationship table, and determine the data sector where the data to be erased is located based on the logical start address and the first mapping relationship table. In addition, since there are multiple mapping sectors, the mapping sector where the mapping relationship table is located will change every time it is updated. The storage controller does not know in which mapping sector the latest mapping relationship table is stored. Therefore, the storage controller can obtain the first mapping relationship table according to the following steps:
[0082] Step 1: Obtain physical identifiers corresponding to multiple mapping sectors.
[0083] Step 2: traverse each mapped sector according to the physical identifier corresponding to each mapped sector.
[0084] Step three: each time a mapping sector is traversed, it is determined whether the first mapping relationship table is stored in the traversed first mapping sector.
[0085] Step 4: when it is determined that the first mapping relationship table is stored in the first mapping sector, read the first mapping relationship table from the first mapping sector.
[0086] Step 5: when it is determined that the first mapping relationship table is not stored in the traversed mapping sector, traverse the next mapping sector until a mapping sector storing the first mapping relationship table is determined, read the first mapping relationship table, and stop the traversal operation.
[0087] Specifically, the size of the mapping relationship table can be fixed, for example, it can be 64 bytes. The storage controller can determine the starting physical position of the mapping sector according to the physical identifier of the mapping sector and the preset sector size. Further, the starting physical position of the mapping sector can be used as the starting point to start the data reading operation according to the preset unit (i.e., the size of the mapping relationship table). Each time the target data of the preset unit size is read, it is determined whether the value included in the target data meets the preset rule. The preset rule is used to indicate that the current storage position does not store valid data (for example, the values included in the target data are all 1). If yes, it is considered that the storage space of the preset unit before the storage position corresponding to the target data is the latest first mapping relationship table, and the first mapping relationship table can be read for subsequent use. If not, the target data of the next preset unit can be read, and so on. If the first mapping relationship table is still not read after all the data of the current mapping sector is read, the next mapping sector can be traversed until the traversal operation is stopped when the first mapping relationship table is read.
[0088] Step S202: acquiring a first physical identifier of the exchange data sector from a first mapping relationship table according to a preset mark.
[0089] Among them, the preset mark can be a special mark. For example, in the mapping relationship table in the above example, "map[swap]=63, swap=63", the special mark is "swap", and the corresponding first physical identifier is "63", which is used to indicate the 63rd data sector of the memory. Alternatively, the preset mark can also be a pre-specified fixed logical identifier, for example, the logical identifier "63" in the mapping relationship table of the above cluster. The storage controller can directly determine the physical identifier corresponding to the fixed logical identifier in the first mapping relationship table as the first physical identifier based on this fixed logical identifier.
[0090] Step S203: determining a logical identifier corresponding to each logical start address according to each logical start address and a preset sector size.
[0091] The logical start address and the preset sector size may both be hexadecimal values, and the logical identifier may be a decimal value.
[0092] Specifically, the storage controller may calculate a ratio of a logical start address to a preset sector size, and round down the ratio to obtain a logical identifier.
[0093] For example, the logical start address is "0x00001200", the preset sector size is "0x1000",
[0094] Step S204: determining a page identifier corresponding to each logical start address according to each logical start address, a preset number of pages and a preset page size.
[0095] The page identifier may be a numerical value, used to indicate the page number of the current page in the current sector. The preset page number is used to indicate the number of pages included in a sector.
[0096] Specifically, the storage controller may first calculate the ratio of the logical start address to the preset page size, and round down the ratio to obtain a first value, and then obtain the remainder of the quotient of the first value and the preset number of pages, and the remainder is the page identifier.
[0097] For example, the logical start address is "0x00001200", the preset number of pages is "16", the preset page size is "0x100", The remainder of 18 / 16 is 2, and the page ID is 2.
[0098] Step S205 , dividing the logical start addresses with the same logical identifier into the same data group to obtain at least one data group.
[0099] Specifically, in order to speed up the data copy operation, the storage controller can group the logical addresses in the data erase instruction according to the logical identifier corresponding to each logical start address, that is, divide the logical start addresses with the same logical identifier into the same data group. In this way, the subsequent storage controller can perform data copy operations on each data group separately.
[0100] Step S206, according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, the data in other pages in the target data sector except the page corresponding to the page identifier corresponding to each logical start address in the target data group is copied to the exchange data sector.
[0101] The target data group may be any one of the at least one data group. The target data sector is the sector indicated by the target physical identifier corresponding to the target logical identifier in the first mapping relationship table.
[0102] Specifically, step S206 may include the following steps:
[0103] Step 1: According to the target logical identifier corresponding to the target data group, determine the target physical identifier corresponding to the target logical identifier in the first mapping relationship table.
[0104] Step 2: Determine the starting physical position of the target data sector according to the target physical identifier and the preset sector size.
[0105] Step three: traverse each page included in the target data sector according to the starting physical position of the target data sector.
[0106] Step 4: Each time a page is traversed, the identifier of the target page is obtained.
[0107] Step 5: According to the identifier of the target page, determine whether the identifier of the target page is a page identifier corresponding to a logical start address in the target data group.
[0108] Step six: when it is determined that the identifier of the target page is a page identifier corresponding to a logical start address in the target data group, continue to traverse the next page in the target data sector.
[0109] Step seven: when it is determined that the identifier of the target page is not the page identifier corresponding to any logical start address in the target data group, determine the starting physical position of the exchange data sector according to the first physical identifier and the preset sector size.
[0110] Step eight, according to the starting physical position of the exchange data sector, the identifier of the target page and the preset page size, copy the data in the target page of the target data sector to the target page of the exchange data sector.
[0111] Step nine, continue traversing the next page in the target data sector until all pages in the target data sector are traversed and then stop traversing.
[0112] Specifically, the storage controller can determine the target physical identifier corresponding to the target logical identifier in the first mapping relationship table according to the target logical identifier, and then determine the product of the target physical identifier and the preset sector size as the starting physical position of the target data sector. Further, the storage controller can traverse each page included in the target data sector according to the starting physical position of the target data sector. When traversing to the first page, the identifier of the page can be obtained to determine whether the identifier 0 of the page is the page identifier of the target data sector in which data needs to be erased, that is, to determine whether the identifier of the page is the page identifier corresponding to a certain logical starting address in the target data group. If yes, the page can be skipped and the next page can be processed. If not, the data of the page can be copied, which can be specifically: the storage controller first determines the starting physical position of the exchange data sector according to the first physical identifier and the preset sector size, and takes the starting physical position of the exchange data sector as the starting point to copy the data of the page to the first page in the exchange data sector.
[0113] After processing the first page, the storage controller can process the second page, that is, determine whether the page identifier 1 of the second page is the page identifier of the target data sector in which data needs to be erased. If yes, the page can be skipped and the next page can be processed. If not, the data of the page can be copied, which can be: the storage controller first calculates the product of the page identifier of the second page and the preset page size, and then calculates the starting physical position of the exchange data sector and the sum of the product, and uses the sum as a new starting point to write the data in the second page of the target data sector into the second page of the exchange data sector. By analogy, the data copy operation from the target data sector to the exchange data sector can be completed.
[0114] In some optional implementations, after step S206, the first mapping relationship table may also be modified:
[0115] Step 1: According to the first physical identifier, determine in a first mapping relationship table a first logical identifier corresponding to the first physical identifier.
[0116] Step 2: modify the physical identifier corresponding to the target logical identifier in the first mapping relationship table to the first physical identifier, and modify the physical identifier corresponding to the first logical identifier in the first mapping relationship table to the target physical identifier, to obtain a second mapping relationship table.
[0117] When the mapping sector can store multiple mapping relationship tables, the storage controller can store the mapping relationship tables according to the following steps: obtaining first storage location information of the first mapping relationship table. According to the first storage location information, storing the second mapping relationship table after the first mapping relationship table.
[0118] In some optional embodiments, after completing the storage of the second mapping relationship table, the storage controller can determine whether the first mapping sector is full of data based on the first storage location information, the physical identifier of the first mapping sector and the preset sector size. After determining that the first mapping sector stores data, the storage controller can erase all data in the first mapping sector (that is, all mapping relationship tables) for subsequent use.
[0119] When a mapping sector can store a mapping relationship table, the storage controller can store the mapping relationship table according to the following steps: according to the physical identifier of each mapping sector, obtain the order corresponding to each mapping sector. According to the order corresponding to each mapping sector, determine the second mapping sector that is ordered after the first mapping sector. Store the second mapping relationship table in the second mapping sector. Delete the first mapping relationship table from the first mapping sector.
[0120] In this way, when the data in the memory is subsequently operated, the latest second mapping sector can be used to read and write data, which can ensure that the data corresponding to the target logical identifier can be read from the exchange data sector through the second mapping relationship table.
[0121] If only one mapping sector is reserved for storing mapping relationships, the mapping sector may have a large number of data writes and erases, which may lead to a large loss of the mapping sector and make it impossible to continue storing data. In addition, if a power outage occurs during the process of modifying the mapping relationship, the data in the memory may not be read, which leads to data loss. This solution can solve these problems. First, each time the mapping relationship table is modified, a mapping sector is replaced for storage, which can achieve the recycling of multiple mapping sectors and ensure the wear balance of the mapping sectors. Secondly, according to the actual needs of the memory, the number of mapping sectors can be adjusted. When the number of mapping sectors is large, the number of data writes and erases for each mapping sector can be reduced to reduce the loss. Finally, the old mapping relationship table is deleted only when the new mapping relationship table is completed. Therefore, even if a power outage occurs during the process of modifying the mapping relationship, the data can be read through the old mapping relationship table to avoid the problem of data loss caused by power outage.
[0122] In some optional embodiments, when the preset mark is a special mark, after step S206, the storage controller may also mark the target data sector as a new exchange data sector, which may be specifically: canceling the preset mark for the old exchange data sector, and marking the target logical identifier as the preset mark.
[0123] When the preset mark is a fixed logical mark, the new exchange data sector can be determined by the physical mark corresponding to the fixed logical mark in the second mapping relationship table, without the need for further marking operation.
[0124] Specifically, by updating the mark, when the subsequent storage controller receives a data erasure instruction for a certain page in other data sectors, or when processing data copy operations corresponding to other data groups other than the target data group in the at least one data group, the data to be retained can be copied to the target data sector in a similar processing manner to the above step S206, and the data sector of the erased data can be selected as the new exchange data sector. In this way, the data sectors can be recycled and the wear leveling of the data sectors in the storage area can be achieved.
[0125] In some optional embodiments, in order to reduce the number of times data sectors are erased, after copying data and modifying the mapping relationship, the storage controller may not erase the data in the target data sector, but instead erase the data in the target data sector upon receiving a write data instruction for the target data sector.
[0126] Finally, according to the write data instruction, a write data operation is performed in the target data sector.
[0127] The write data instruction may be a new data erase instruction received by the storage controller, or may be an instruction generated when processing the next data group after the target data group when there are multiple data groups.
[0128] In the process of copying data from the target data sector to the exchange data sector, a power outage may occur. At this time, the mapping relationship table is not updated, the data is not completely copied, and the storage controller can still find the data according to the old mapping relationship. However, if a power outage occurs after the data copy process is completed and before the mapping relationship table is updated, the data cannot be found through the old mapping relationship table. Therefore, this solution performs a data erase operation before writing data to the target data sector, which can avoid the problem of data being unable to be found due to power outage.
[0129] In some optional implementations, the erasure of the mapping relationship table may be before writing a new mapping relationship table. The storage controller may generate a second serial number by adding one to the first serial number of the old mapping relationship table after completing each update operation on the mapping relationship table, and determine the second serial number as the serial number of the new mapping relationship table. Accordingly, the specific operation of obtaining the first mapping relationship table may be: obtaining the serial number of the mapping relationship table stored in each mapping sector, selecting the target mapping sector where the mapping relationship table corresponding to the largest serial number is located, and reading the first mapping relationship table from the target mapping sector. In this way, the number of erasures of each mapping sector can be reduced.
[0130] In this way, each data group can be processed in the above manner to complete the corresponding data copy operation.
[0131] In the data copying method provided by the present embodiment, after receiving the data erasure instruction, the storage controller can obtain the first mapping relationship table. For the target logical starting address, the storage controller can determine the target logical identifier corresponding to the target logical starting address according to the target logical starting address, and then determine the corresponding target physical identifier according to the target logical identifier and the first mapping relationship table. In addition, the storage controller can obtain the first physical identifier as the exchange data sector, and further, according to the target physical identifier, the data of other pages except the page to be deleted can be copied from the target data sector to the exchange data sector corresponding to the first physical identifier, so that the data in the exchange data sector is the data corresponding to the target logical identifier. In this way, for the data stored in the exchange data sector, it can be considered that the erasure operation has been completed, that is, this scheme can realize the data erasure operation in units of pages.
[0132] The following is a specific explanation using the example of performing multiple consecutive data copy operations. The prerequisites include: each data erase instruction includes only one logical start address. The fixed logical identifier can be "63", that is, in different mapping tables, the data sector corresponding to the physical identifier corresponding to the logical identifier "63" is the exchange data sector. The preset sector size is "0x1000", the preset page size is "0x100", and the preset number of pages is 16.
[0133] First, the processing of the data erase instruction 1. The logical start address included in the data erase instruction 1 is "0x00000000".
[0134] like Figure 3 As shown, the left part represents the data status of the 0th data sector (sector[0]), and the right part represents the data status of the 63rd data sector (sector
[63] ) after the data copy operation is completed.
[0135] By using the above-given logical start address and preset sector size, the logical identifier can be calculated as "0". By using the above-given logical start address, preset page size and preset number of pages, the page identifier can be calculated as "0". Figure 3 From the mapping relationship in the upper middle part, we can know that the physical identifier corresponding to the logical identifier "0" is "0". In summary, the data that needs to be erased is on page 0 of the 0th data sector of the memory. The storage controller can move the data of other pages (page[1]-page
[15] ) on the 0th data sector except page 0 to the corresponding page of the 63rd data sector. The storage controller can also change the physical identifier corresponding to the logical identifier "0" from "0" to "63" to indicate that the data corresponding to the logical identifier "0" is currently stored on the 63rd data sector. And, the 0th data sector becomes the current new exchange data sector.
[0136] Second, the processing of the data erase instruction 2. The logical start address included in the data erase instruction 2 is "0x00001100".
[0137] like Figure 4 As shown, the left part represents the data status of the 1st data sector (sector[1]), and the right part represents the data status of the 0th data sector (sector[0]) after the data copy operation is completed.
[0138] By using the above-given logical start address and preset sector size, the logical identifier can be calculated to be “1”. By using the above-given logical start address, preset page size and preset number of pages, the page identifier can be calculated to be “1”.
[0139] pass Figure 4 From the mapping relationship in the upper middle part, we can know that the physical identifier corresponding to the logical identifier "1" is "1". In summary, the data that needs to be erased is on the first page of the first data sector of the memory. The storage controller can move the data of other pages (page[0] and page[2]-page
[15] ) on the first data sector except the first page to the corresponding page of the 0th data sector. The storage controller can also change the physical identifier corresponding to the logical identifier "1" from "1" to "0" to indicate that the data corresponding to the logical identifier "1" is currently stored on the 0th data sector. And, the 1st data sector becomes the current new exchange data sector.
[0140] Third, the processing of the data erase instruction 3. The logical start address included in the data erase instruction 2 is "0x00001200".
[0141] like Figure 5 As shown, the left part represents the data status of the 0th data sector (sector[0]), and the right part represents the data status of the 1st data sector (sector[1]) after the data copy operation is completed.
[0142] By using the above-given logical start address and preset sector size, the logical identifier can be calculated as "1". By using the above-given logical start address, preset page size and preset number of pages, the page identifier can be calculated as "2". Figure 5From the mapping relationship in the upper middle part, we can know that the physical identifier corresponding to the logical identifier "1" is "0". In summary, the data that needs to be erased is on the second page of the 0th data sector of the memory. The storage controller can move the data of other pages (page[0], page[1], and page[3]-page
[15] ) on the 0th data sector except the second page to the corresponding page of the 1st data sector. The storage controller can also change the physical identifier corresponding to the logical identifier "1" from "0" to "1" to indicate that the data corresponding to the logical identifier "1" is currently stored on the 1st data sector. And, the 0th data sector becomes the current new exchange data sector.
[0143] From the above three data copy operations, the exchange data sector changes from the 63rd data sector to the 0th data sector, then to the 1st data sector, and finally to the 0th data sector.
[0144] In this embodiment, a data replication device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made are not repeated here. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0145] This embodiment provides a data replication device, such as Figure 6 As shown, including:
[0146] The acquisition module 601 is used to acquire a first mapping relationship table of logical identifiers and physical identifiers of data sectors when receiving a data erasure instruction, wherein the data erasure instruction includes at least one logical start address; and acquire a first physical identifier of the exchange data sector from the first mapping relationship table according to a preset mark;
[0147] The determination module 602 is used to determine the logical identifier corresponding to each logical start address according to each logical start address and the preset sector size; determine the page identifier corresponding to each logical start address according to each logical start address, the preset number of pages and the preset page size;
[0148] A grouping module 603, configured to group logical start addresses with the same logical identifier into the same data group to obtain at least one data group;
[0149] The copy module 604 is used to copy the data in other pages of the target data sector except the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, wherein the target data group is any one of the at least one data group, and the target data sector is the sector indicated by the target physical identifier corresponding to the target logical identifier in the first mapping relationship table.
[0150] In an optional implementation, the copy module 604 is specifically configured to:
[0151] According to the target logical identifier corresponding to the target data group, determine the target physical identifier corresponding to the target logical identifier in the first mapping relationship table;
[0152] Determine the starting physical position of the target data sector according to the target physical identifier and the preset sector size;
[0153] According to the starting physical position of the target data sector, traverse each page included in the target data sector;
[0154] Each time a page is traversed, the ID of the target page is obtained;
[0155] According to the identifier of the target page, determining whether the identifier of the target page is a page identifier corresponding to a logical start address in the target data group;
[0156] When it is determined that the identifier of the target page is a page identifier corresponding to a logical start address in the target data group, continue to traverse the next page in the target data sector;
[0157] or,
[0158] When it is determined that the identifier of the target page is not a page identifier corresponding to any logical start address in the target data group, determining the starting physical position of the exchange data sector according to the first physical identifier and the preset sector size;
[0159] Copying data in a target page of the target data sector to a target page of the exchange data sector according to a starting physical position of the exchange data sector, an identifier of the target page and a preset page size;
[0160] Continue to traverse the next page in the target data sector until all pages in the target data sector are traversed and then stop traversing.
[0161] In an optional implementation, the acquisition module 601 is specifically configured to:
[0162] Obtain physical identifiers corresponding to multiple mapping sectors respectively;
[0163] According to the physical identifier corresponding to each mapped sector, traverse each mapped sector;
[0164] Each time a mapping sector is traversed, determining whether a first mapping relationship table is stored in the traversed first mapping sector;
[0165] When it is determined that the first mapping relationship table is stored in the first mapping sector, reading the first mapping relationship table from the first mapping sector;
[0166] or,
[0167] When it is determined that the first mapping relationship table is not stored in the traversed mapping sector, the next mapping sector is traversed until a mapping sector storing the first mapping relationship table is determined, the first mapping relationship table is read, and the traversal operation is stopped.
[0168] In an optional implementation, the copy module 604 is further configured to:
[0169] According to the first physical identifier, determine in the first mapping relationship table a first logical identifier corresponding to the first physical identifier;
[0170] The physical identifier corresponding to the target logical identifier in the first mapping relationship table is modified to the first physical identifier, and the physical identifier corresponding to the first logical identifier in the first mapping relationship table is modified to the target physical identifier, so as to obtain a second mapping relationship table.
[0171] In an optional implementation, the copy module 604 is further configured to:
[0172] When it is determined that the first mapping relationship table is stored in the first mapping sector, obtaining a sequence corresponding to each mapping sector according to a physical identifier of each mapping sector;
[0173] Determining, according to the order corresponding to each mapping sector, a second mapping sector that is ordered after the first mapping sector;
[0174] storing the second mapping relationship table in the second mapping sector;
[0175] The first mapping relationship table is deleted from the first mapping sector.
[0176] In an optional implementation, the copy module 604 is further configured to:
[0177] Mark the target data sector as the new swap data sector.
[0178] In an optional implementation, the copy module 604 is further configured to:
[0179] When receiving a data write instruction for a target data sector, erasing the data in the target data sector;
[0180] According to the write data instruction, a write data operation is performed in the target data sector.
[0181] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0182] The data replication device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0183] The embodiment of the present invention also provides a computer device having the above Figure 6 The data replication device shown.
[0184] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.
[0185] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware integrated circuit. The hardware integrated circuit may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable logic gate array, a general purpose array logic or any combination thereof.
[0186] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.
[0187] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0188] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0189] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0190] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0191] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0192] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A data replication method, characterized in that: The method comprises: When receiving a data erasure instruction, obtaining a first mapping relationship table of logical identifiers and physical identifiers of data sectors, wherein the data erasure instruction includes at least one logical start address; According to the preset mark, obtaining a first physical identifier of the exchange data sector from the first mapping relationship table; Determine a logical identifier corresponding to each of the logical start addresses according to each of the logical start addresses and a preset sector size; Determine a page identifier corresponding to each of the logical start addresses according to each of the logical start addresses, a preset number of pages, and a preset page size; Divide the logical start addresses with the same logical identifier into the same data group to obtain at least one data group; According to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, the data in other pages of the target data sector except the page corresponding to the page identifier corresponding to each logical start address in the target data group is copied to the exchange data sector, wherein the target data group is any one of at least one of the data groups, and the target data sector is the sector indicated by the target physical identifier corresponding to the target logical identifier in the first mapping relationship table.
2. The method according to claim 1, characterized in that The step of copying data in other pages of the target data sector except for a page corresponding to a page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, comprises: According to the target logical identifier corresponding to the target data group, determining the target physical identifier corresponding to the target logical identifier in the first mapping relationship table; Determining a starting physical position of the target data sector according to the target physical identifier and the preset sector size; According to the starting physical position of the target data sector, traverse each page included in the target data sector; Each time a page is traversed, the ID of the target page is obtained; Determining, according to the identifier of the target page, whether the identifier of the target page is a page identifier corresponding to a logical start address in the target data group; When it is determined that the identifier of the target page is a page identifier corresponding to a logical start address in the target data group, continue to traverse the next page in the target data sector; or, When it is determined that the identifier of the target page is not a page identifier corresponding to any logical start address in the target data group, determining the starting physical position of the exchange data sector according to the first physical identifier and the preset sector size; Copying data in a target page of the target data sector to a target page of the exchange data sector according to a starting physical position of the exchange data sector, an identifier of the target page and the preset page size; Continue to traverse the next page in the target data sector until all pages in the target data sector are traversed and then stop traversing.
3. The method according to claim 2, characterized in that When receiving a data erasure instruction, obtaining a first mapping relationship table between a logical identifier and a physical identifier of a data sector includes: Obtain physical identifiers corresponding to multiple mapping sectors respectively; According to the physical identifier corresponding to each of the mapping sectors, traverse each of the mapping sectors; Each time when a mapping sector is traversed, determining whether the first mapping relationship table is stored in the traversed first mapping sector; When it is determined that the first mapping relationship table is stored in the first mapping sector, reading the first mapping relationship table from the first mapping sector; or, When it is determined that the first mapping relationship table is not stored in the traversed mapping sector, the next mapping sector is traversed until a mapping sector storing the first mapping relationship table is determined, the first mapping relationship table is read, and the traversal operation is stopped.
4. The method according to claim 3, characterized in that After copying data in other pages of the target data sector except for the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, the method further comprises: According to the first physical identifier, determining in the first mapping relationship table a first logical identifier corresponding to the first physical identifier; The physical identifier corresponding to the target logical identifier in the first mapping relationship table is modified to the first physical identifier, and the physical identifier corresponding to the first logical identifier in the first mapping relationship table is modified to the target physical identifier to obtain a second mapping relationship table.
5. The method according to claim 4, characterized in that When it is determined that the first mapping relationship table is stored in the first mapping sector, the method further includes: According to the physical identifier of each of the mapping sectors, obtaining a ranking corresponding to each of the mapping sectors; Determining, according to the order corresponding to each of the mapping sectors, a second mapping sector that is ordered after the first mapping sector; storing the second mapping relationship table in the second mapping sector; The first mapping relationship table is deleted from the first mapping sector.
6. The method according to any one of claims 1 to 3, characterized in that: After copying data in other pages of the target data sector except for the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, the method further comprises: The target data sector is marked as a new exchange data sector.
7. The method according to any one of claims 1 to 5, characterized in that: After copying data in other pages of the target data sector except for the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size and the preset page size, the method further includes: When receiving a data write instruction for the target data sector, erasing the data in the target data sector; According to the write data instruction, a write data operation is performed in the target data sector.
8. A data replication device, characterized in that: The device comprises: an acquisition module, configured to acquire a first mapping relationship table of logical identifiers and physical identifiers of data sectors when receiving a data erasure instruction, wherein the data erasure instruction includes at least one logical start address; and acquire a first physical identifier of the exchange data sector from the first mapping relationship table according to a preset mark; A determination module, configured to determine a logical identifier corresponding to each of the logical start addresses according to each of the logical start addresses and a preset sector size; and to determine a page identifier corresponding to each of the logical start addresses according to each of the logical start addresses, a preset number of pages and a preset page size; A grouping module, used for grouping logical start addresses with the same logical identifier into the same data group to obtain at least one data group; A copy module, used for copying data in other pages of the target data sector except the page corresponding to the page identifier corresponding to each logical start address in the target data group to the exchange data sector according to the target logical identifier corresponding to the target data group, the first mapping relationship table, the preset sector size, the preset page size and the first physical identifier, wherein the target data group is any one of at least one of the data groups, and the target data sector is the sector corresponding to the target physical identifier corresponding to the target logical identifier in the first mapping relationship table.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the data replication method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the data replication method according to any one of claims 1 to 7.
