Method for writing data to a solid state disk, apparatus, and solid state disk
View Patent ↗Provided is a method for writing data to a Solid State Disk (SSD), an apparatus and the SSD. According to the method, a Logical Block Address (LBA) of each of a plurality of pieces of written data stored into a target cache module is acquired to obtain a plurality of Logical Block Addresses (LBAs); the plurality of pieces of written data in the buffer is stored into a solid-state storage unit of the SSD; whether the plurality of LBAs are consecutive is determined to obtain a determination result. In a case where the determination result indicates that the plurality of LBAs are consecutive, a Physics Block Address (PBA) of each of the plurality of pieces of written data in the solid-state storage unit is acquired to obtain a plurality of PBAs and a target mapping table according to the plurality of LBAs and the plurality of PBAs is generated.
1 . A method for writing data to a Solid State Disk (SSD), comprising:
acquiring a Logical Block Address (LBA) of each of a plurality of pieces of written data stored into a target cache module to obtain a plurality of Logical Block Addresses (LBAs), wherein the target cache module is located in a buffer of the SSD;
storing the plurality of pieces of written data in the buffer into a solid-state storage unit of the SSD;
determining whether the plurality of LBAs are consecutive to obtain a determination result;
in a case where the determination result indicates that the plurality of LBAs are consecutive, acquiring a Physics Block Address (PBA) of each of the plurality of pieces of written data in the solid-state storage unit to obtain a plurality of Physics Block Addresses (PBAs); and
generating a target mapping table according to the plurality of LBAs and the plurality of PBAs, wherein the target mapping table is configured to map the plurality of LBAs to the plurality of PBAs.
2 . The method according to claim 1 , wherein the acquiring a LBA of each of a plurality of pieces of written data stored into a target cache module to obtain a plurality of LBAs, wherein the target cache module is located in a buffer of the SSD, comprises:
acquiring, from a host, a data packet carried by a target command, and a LBA of each of a plurality of pieces of data in the data packet;
storing the data packet and the LBA of each of the plurality of pieces of data in the data packet into at least one cache module in the buffer, wherein the at least one cache module comprises the target cache module; and
acquiring a LBA of each of a plurality of pieces of data stored into the target cache module to obtain the plurality of LBAs.
3 . The method according to claim 2 , further comprising:
splitting the plurality of pieces of data in the data packet one by one to obtain a plurality of pieces of unpacked data;
determining, according to a splitting order of the plurality of pieces of unpacked data, whether a LBA of a target piece of unpacked data among the plurality of pieces of unpacked data and a LBA of a previous piece of unpacked data are consecutive to obtain the determination result; and
generating a target marking parameter of the target cache module according to the determination result, wherein the target marking parameter is configured to indicate whether the LBA of the target piece of unpacked data and the LBA of the previous piece of unpacked data are consecutive.
4 . The method according to claim 3 , wherein the determining, according to a splitting order of the plurality of pieces of unpacked data, whether a LBA of a target piece of unpacked data among the plurality of pieces of unpacked data and a LBA of a previous piece of unpacked data are consecutive to obtain the determination result comprises:
determining, according to the splitting order of the plurality of pieces of unpacked data, whether a LBA of the Nth piece of unpacked data among the plurality of pieces of unpacked data and a LBA of the (N−1)th piece of unpacked data among the plurality of pieces of unpacked data are consecutive to obtain the determination result.
5 . The method according to claim 4 , wherein the generating a target marking parameter of the target cache module according to the determination result comprises:
updating, according to the determination result, a previous marking parameter of the target cache module to the target marking parameter, wherein the previous marking parameter is configured to indicate whether the LBA of the (N−1)th piece of unpacked data among the plurality of pieces of unpacked data and a LBA of the (N−2)th piece of unpacked data among the plurality of pieces of unpacked data are consecutive.
6 . The method according to claim 5 , wherein the updating, according to the determination result, a previous marking parameter of the target cache module to the target marking parameter comprises:
in a case where a first determination result is obtained, generating a first marking parameter according to the first determination result, and updating the previous marking parameter to the first marking parameter, wherein the first determination result is the determination result obtained in a case where the LBA of the Nth piece of unpacked data and the LBA of the (N−1)th piece of unpacked data are consecutive; and
in a case where a second determination result is obtained, generating a second marking parameter according to the second determination result, and updating the previous marking parameter to the second marking parameter, wherein the second determination result is the determination result obtained in a case where the LBA of the Nth piece of unpacked data and the LBA of the (N−1)th piece of unpacked data are not consecutive.
7 . The method according to claim 3 , wherein the splitting the plurality of pieces of data in the data packet one by one to obtain a plurality of pieces of unpacked data comprises:
splitting the plurality of pieces of data in the data packet one by one to obtain the plurality of pieces of unpacked data of the same size.
8 . The method according to claim 3 , wherein the storing the data packet and the LBA of each of the plurality of pieces of data in the data packet into at least one cache module in the buffer comprises:
storing, according to the splitting order of the plurality of pieces of unpacked data, a preset quantity of pieces of unpacked data among the plurality of pieces of unpacked data and a LBA of each of the preset quantity of pieces of unpacked data one by one into the target cache module, wherein the plurality of pieces of written data comprise the stored preset quantity of pieces of unpacked data and the stored LBA of each of the preset quantity of pieces of unpacked data.
9 . The method according to claim 8 , wherein the storing, according to the splitting order of the plurality of pieces of unpacked data, a preset quantity of pieces of unpacked data among the plurality of pieces of unpacked data and a LBA of each of the preset quantity of pieces of unpacked data one by one into the target cache module to obtain the plurality of pieces of written data comprises:
storing the target piece of unpacked data and the LBA of the target piece of unpacked data into the target cache module;
determining whether a quantity of unpacked data currently stored into the target cache module reaches the preset quantity;
in a case where the quantity of unpacked data currently stored into the target cache module does not reach the preset quantity, storing, according to the splitting order of the plurality of pieces of unpacked data, a next piece of unpacked data of the target piece of unpacked data and a LBA of the next piece of unpacked data into the target cache module; and
in a case where the quantity of unpacked data currently stored into the target cache module reaches the preset quantity, stopping a storage operation of the target cache module, the target cache module storing the plurality of pieces of written data.
10 . The method according to claim 8 , wherein the storing the data packet and the LBA of each of the plurality of pieces of data in the data packet into at least one cache module in the buffer further comprises:
determining the present quantity according to a storage capacity of the target cache module and a size of each of the plurality of pieces of unpacked data.
11 . The method according to claim 8 , wherein the storing, according to the splitting order of the plurality of pieces of unpacked data, a preset quantity of pieces of unpacked data among the plurality of pieces of unpacked data and a LBA of each of the preset quantity of pieces of unpacked data one by one into the target cache module, wherein the plurality of pieces of written data comprise the stored preset quantity of pieces of unpacked data and the stored LBA of each of the preset quantity of pieces of unpacked data, comprises:
determining, after a piece of unpacked data is split out from the plurality of pieces of data in the data packet each time, whether an available cache module exists in the at least one cache module, wherein the available cache module is a cache module having available storage space;
in a case where the available cache module exists in the at least one cache module, determining that the available cache module is the target cache module; and
storing the piece of unpacked data split out from the plurality of pieces of data in the data packet and a LBA of the piece of unpacked data into the target cache module, wherein the plurality of pieces of written data comprise the stored the piece of unpacked data and the stored LBA of the piece of unpacked data.
12 . The method according to claim 11 , wherein the storing, according to the splitting order of the plurality of pieces of unpacked data, a preset quantity of pieces of unpacked data among the plurality of pieces of unpacked data and a LBA of each of the preset quantity of pieces of unpacked data one by one into the target cache module to obtain the plurality of pieces of written data further comprises:
in a case where the available cache module does not exist in the at least one cache module, generating an application request;
generating, according to the application request, a new cache module in the buffer to obtain the target cache module; and
storing the unpacked data split out from the plurality of pieces of data in the data packet into the new cache module to obtain written data stored in the target cache module.
13 . The method according to claim 12 , wherein the storing, according to the splitting order of the plurality of pieces of unpacked data, a preset quantity of pieces of unpacked data among the plurality of pieces of unpacked data and a LBA of each of the preset quantity of pieces of unpacked data one by one into the target cache module to obtain the plurality of pieces of written data further comprises:
after generating the new cache module, initializing the new cache module to obtain the target cache module, wherein the target cache module has a first marking parameter, and the first marking parameter is configured to indicate that the plurality of LBAs are consecutive.
14 . The method according to claim 3 , wherein the determining, according to a splitting order of the plurality of pieces of unpacked data, whether a LBA of a target piece of unpacked data among the plurality of pieces of unpacked data and a LBA of a previous piece of unpacked data are consecutive to obtain the determination result comprises:
after storing the target piece of unpacked data split out from the plurality of pieces of data in the data packet and the LBA of the target piece of unpacked data into the target cache module, recording a relative offset parameter of the target piece of unpacked data in the target cache module, wherein the relative offset parameter indicates the quantity of pieces of unpacked data stored in the target cache module before the target piece of unpacked data in a storing order;
calculating a difference between the LBA of the target piece of unpacked data and a LBA of the first piece of unpacked data stored in the target cache module; and
determining whether the relative offset parameter is equal to the difference to obtain the determination result.
15 . The method according to claim 14 , wherein the generating a target marking parameter of the target cache module according to the determination result comprises:
generating a first marking parameter in a case where the relative offset parameter is equal to the difference, wherein the first marking parameter is configured to indicate that the plurality of LBAs are consecutive; and
generating a second marking parameter in a case where the relative offset parameter is not equal to the difference, wherein the second marking parameter is configured to indicate that a LBA of a first piece of written data among the plurality of pieces of written data and a LBA of a second piece of written data among the plurality of pieces of written data are not consecutive, and the first write data and the second write data are two pieces of unpacked data adjacent in the splitting order.
16 . The method according to claim 15 , wherein the determining whether the plurality of LBAs are consecutive comprises:
determining whether the target marking parameter indicates that the plurality of LBAs are consecutive.
17 . The method according to claim 16 , wherein the determining whether the target marking parameter indicates that the plurality of LBAs are consecutive comprises:
determining whether the target marking parameter meets a preset condition, wherein the preset condition comprises one of the following:
the target marking parameter is the first marking parameter, wherein the first marking parameter is configured to indicate that the plurality of LBAs are consecutive;
the target marking parameter is the second marking parameter, wherein the second marking parameter is configured to indicate that the plurality of LBAs are not consecutive.
18 . The method according to claim 1 , further comprising:
acquiring a PBA of each of the plurality of pieces of written data in the buffer to obtain a plurality of PBAs which comprise the PBA of each of the plurality of pieces of written data in the buffer; and
generating a first mapping table according to the plurality of LBAs and the plurality of PBAs which comprise the PBA of each of the plurality of pieces of written data in the buffer, wherein the first mapping table is configured to map the plurality of LBAs to the plurality of PBAs which comprise the PBA of each of the plurality of pieces of written data in the buffer.
19 . A non-volatile readable storage medium, wherein a computer program is stored in the non-volatile readable storage medium, wherein the computer program is executed by a processor to implement the steps of the method according to claim 1 .
20 . A Solid State Disk (SSD), comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the method according to claim 1 .