The present disclosure relates to the field of information technologies, and in particular, to a method for storing data by a storage device and a storage device.
A solid state disk (SSD), as shown in
The garbage space recycling causes write amplification, and a ratio of a sum of a size V of the valid data moved in the garbage space recycling in the SSD and a size W of the newly written data to the size W of the newly written data, that is, (V+W)/W, is referred to as write amplification.
According to a first aspect, an embodiment of the present disclosure provides a solution for storing data by a storage device, where the storage device includes a first storage area and a second storage area, where the first storage area includes data space and reserved space, and the second storage area includes data space and reserved space, the storage device receives a write request, where the write request carries a logical address and data, and the storage device determines a feature of the write request.
When the feature of the write request meets a first condition, the storage device writes the data carried in the write request to a first storage address of the reserved space of the first storage area, and establishes a mapping relationship between the logical address and the first storage address, or when the feature of the write request meets a second condition, the storage device writes the data carried in the write request to a second storage address of the reserved space of the second storage area, and establishes a mapping relationship between the logical address and the second storage address. In this embodiment of the present disclosure, the data carried in the write request is written to reserved space of different storage areas according to the feature of the write request, which reduces movements of valid data in a garbage space recycling process and reduces write amplification.
Optionally, the storage device may independently perform garbage space recycling for the first storage area and the second storage area. That the storage device may independently perform garbage space recycling for the first storage area and the second storage area means that the storage device performs garbage space recycling for one of the first storage area and the second storage area, and does not affect the other storage area, or may concurrently perform garbage space recycling for both the first storage area and the second storage area. For write requests having different features, data is written to different storage areas, and garbage space recycling is independently performed for the storage areas based on different reserved space configured in the different storage areas. Therefore, movements of valid data in a garbage space recycling process can be reduced, write amplification can be reduced, and a quantity of times of triggering the garbage space recycling process can also be reduced by configuring different reserved space, so that a quantity of times of erasing a physical block in the storage device is reduced, and a service life of the storage device is increased.
Optionally, a size of the reserved space of the first storage area is different from a size of the reserved space of the second storage area.
Optionally, the reserved space of the first storage area is smaller than the reserved space of the second storage area, or a ratio of the reserved space of the first storage area to the data space of the first storage area is less than a ratio of the reserved space of the second storage area to the data space of the second storage area. Because the second storage area has more reserved space, a quantity of times of garbage space recycling in the second storage area can be reduced.
Optionally, when data is written to a corresponding storage area, for example, the foregoing first or second storage area, if reserved space of the corresponding storage area is insufficient, dynamic adjustment may be performed. For example, under the precondition that a maximum redundant quota is not used up, extra reserved space may be applied for, and then the data in the write request is written to the reserved space that is newly applied for.
Optionally, the determining, by the storage device, a feature of the write request includes:
determining, by the storage device, whether the write request is a sequential write request or a random write request, where the first condition is the sequential write request, and the second condition is the random write request, and respectively storing the sequential write request and the random write request in different storage areas, which reduces movements of valid data in a garbage space recycling process and reduces write amplification. In addition, when both the sequential write request and the random write request exist, random write performance of the storage device is improved without affecting performance of the sequential write request. Optionally, it is determined whether data is written to a reference logical address, where an absolute value of an address difference between the reference logical address and the logical address is not greater than L, and L may be set according to a requirement for the sequential write request. In one implementation, when data is written to the reference logical address, the write request is a sequential write request; when no data is written to the reference logical address, the write request is a random write request. In another implementation, when no data is written to the reference logical address, the write request is a random write request. When data is written to the reference logical address, further, the storage device determines whether an interval between a time at which the write request carrying a reference address is received for the last time and a time at which the write request carrying the logical address is received for the last time is greater than a threshold T, and if when the interval is greater than the threshold T, the write request is still a random write request; when the interval is not greater than the threshold T, the write request is a sequential write request. T may be set according to a specific implementation.
Optionally, the determining, by the storage device, a feature of the write request includes:
determining, by the storage device, a sequence level of the write request, where the first condition is a first sequence level range, the second condition is a second sequence level range, and a minimum value of the first sequence level range is greater than a maximum value of the second sequence level range. Optionally, the sequence level is a ratio S (a sequence level) of a sequential write request count Cs of a current logical address to (a sum of the sequential write request count Cs of the current logical address and a random write request count Cr of the current logical address), that is, Cs/(Cs+Cr)=S. According to the sequence level, data carried in write requests having different sequence levels may be respectively stored in different storage areas having different reserved space, which reduces movements of valid data in a garbage space recycling process and reduces write amplification.
Optionally, the determining, by the storage device, a feature of the write request includes:
determining, by the storage device, a randomness level of the write request, where
the first condition is a first randomness level range, the second condition is a second randomness level range, and a maximum value of the first randomness level range is less than a minimum value of the second randomness level range. Optionally, the randomness level is a ratio R of a random write request count Cr of a current logical address to (a sum of a sequential write request count Cs of the current logical address and the random write request count Cr of the current logical address), that is, Cr/(Cr+Cs)=R. According to the randomness level, data carried in write requests having different randomness levels may be separately stored, which reduces movements of valid data in a garbage space recycling process and reduces write amplification.
Optionally, the determining, by the storage device, a feature of the write request includes:
determining, by the storage device, a size of the data carried in the write request, where
the first condition is a first data range stored in the first storage area, the second condition is a second data range stored in the second storage area, and a minimum value of the first data range is greater than a maximum value of the second data range. The storage device includes different storage areas, each storage area stores a corresponding data range, which may reduce movements of valid data in a garbage space recycling process and reduce write amplification. Optionally, a data range refers to an interval of a size of data carried in a write request stored in a storage area.
Optionally, in a case in which multiple write requests are concurrently sent, the storage device preferentially processes a write request meeting the first condition, to improve write performance of the storage device.
Optionally, the storage device is an SSD, or a shingled magnetic recording (Shingled Magnetic Recording, SMR) disk, or a storage array having a garbage space recycling function and based on a ROW mechanism.
Corresponding to the solution implemented in the first aspect, according to a second aspect, an embodiment of the present disclosure further provides a solution for dividing a storage area by a storage device. The storage device divides storage space into a first storage area and a second storage area, where the first storage area includes data space and reserved space, and the second storage area includes data space and reserved space, where the reserved space of the first storage area is configured to store data carried in a first write request, the reserved space of the second storage area is configured to store data carried in a second write request, a feature of the first write request meets a first condition, and a feature of the second write request meets a second condition.
Optionally, a corresponding quantity of storage areas may be divided according to a class number of a sequence level or a randomness level of a write request, and corresponding reserved space is configured according to a value of each class of the sequence level or the randomness level. Division of the storage areas and configuration of the corresponding reserved space may be performed in advance, or dynamic division and configuration may be performed during use.
According to a third aspect, corresponding to the first aspect and the second aspect, an embodiment of the present disclosure further provides a storage device, separately used as the storage device in the embodiments of the first aspect and the second aspect, to implement the solutions of the embodiments provided in the first aspect and the second aspect of the embodiments of the present disclosure. The storage device includes a structural unit implementing the solutions of the embodiments of the present disclosure in the first aspect and the second aspect, or the storage device includes a storage controller to implement the solutions of the embodiments in the first aspect and the second aspect.
Correspondingly, an embodiment of the present disclosure further provides a non-volatile computer readable storage medium and a computer program product. When a computer instruction included in the non-volatile computer readable storage medium and the computer program product is loaded in a memory of the storage controller of the storage device provided in the embodiments of the present disclosure, and a CPU of the storage controller executes the computer instruction, the storage device performs functions of the storage device in the embodiments of the first aspect and the second aspect, to implement the solutions provided in the first aspect and the second aspect of the embodiments of the present disclosure.
An SSD is used as an example in an embodiment of the present disclosure. In this embodiment of the present disclosure, the SSD includes a first storage area Vd1 and a second storage area Vd2. Vd1 includes data space and reserved space, Vd2 includes data space and reserved space, and a size of the reserved space of Vd1 is different from a size of the reserved space of Vd2. In this embodiment of the present disclosure, the SSD may independently perform garbage space recycling for Vd1 and Vd2. That the SSD may independently perform garbage space recycling for Vd1 and Vd2 means that the SSD performs garbage space recycling for one of Vd1 and Vd2, and does not affect the other storage area, or may concurrently perform garbage space recycling for both Vd1 and Vd2. For write requests having different features, data is written to different storage areas, and garbage space recycling is independently performed for the storage areas based on different reserved space configured in the different storage areas. Therefore, movements of valid data in a garbage space recycling process can be reduced, write amplification can be reduced, and a quantity of times of triggering the garbage space recycling process can also be reduced by configuring different reserved space, so that a quantity of times of erasing a physical block in the SSD is reduced, and a service life of the SSD is increased.
The foregoing characteristics of the SSD in this embodiment of the present disclosure may further be applied to another storage device in the embodiments of the present disclosure, and details are not described herein again.
As shown in
Step 201: Receive a write request.
An SSD receives a write request, where the write request carries an LBA and data.
Step 202: Determine a feature of the write request.
An implementation manner of determining a feature of the write request includes:
Specifically, when receiving the write request, the SSD determines whether the write request is a sequential write request or a random write request. In this embodiment of the present disclosure, the SSD records a time at which each write request is received and an LBA address carried in the write request. In a specific implementation manner, a method for determining whether the write request is a sequential write request (a first condition shown in
The SSD records the LBA carried in the received write request, and a time at which the write request is received for the last time. According to an LBA m carried in the write request, the SSD queries whether data is written to an LBA n (referred to as a reference logical address), where an absolute value of a difference between the LBA m and the LBA n is not greater than L, and L may be set according to a requirement for the sequential write request. If no data is written to the LBA n, the write request carrying the LBA m is a random write request. In one implementation manner, if data is written to the LBA n, the write request carrying the LBA m is a sequential write request. In another implementation manner, when data is written to the LBA n, the SSD further determines whether an interval between a time at which the write request carrying the LBA n is received for the last time and a time at which the write request carrying the LBA m is received for the last time is greater than a threshold T. If the interval is greater than T, the write request carrying the LBA m is a random write request. If the interval is not greater than T, the write request carrying the LBA m is a sequential write request. T may be set according to a specific implementation, which is not limited in this embodiment of the present disclosure. The sequential write request is generally a write request from a same file or application, and the random write request is a write request from a different file or application.
In this embodiment of the present disclosure, the SSD includes a first storage area (Vd1) shown in
As shown in
Because the reserved space in Vd1 shown in
As shown in
As shown in
As shown in
In this embodiment of the present disclosure, Vd1 is configured to store data carried in a sequential write request, Vd2 is configured to store data carried in a random write request, and the data carried in the sequential write request and the data carried in the random write request are respectively stored in different storage areas according to a feature of a write request, which reduces movements of valid data in a garbage space recycling process and reduces write amplification.
In this embodiment of the present disclosure, more reserved space is allocated to Vd2, that is, the reserved space of Vd2 is larger than the reserved space of Vd1, which may reduce a quantity of times of garbage space recycling, so that a quantity of times of erasing a physical block in Vd2 is reduced, and a service life of an SSD is increased. In another implementation, a ratio of the reserved space of Vd2 to the data space of Vd2 is greater than a ratio of the reserved space of Vd1 to the data space of Vd1, which may also achieve an effect of reducing a quantity of times of garbage space recycling in this embodiment of the present disclosure.
In this embodiment of the present disclosure, the SSD includes Vd1 and Vd2, where Vd1 is configured to store data carried in a sequential write request, and Vd2 is configured to store data carried in a random write request. In a case in which both the random write request and the sequential write request exist, performance of the sequential write request is not affected, and random write performance of the SSD is improved.
Optionally, when data is written to a corresponding storage area, for example, the foregoing first or second storage area, if reserved space of the corresponding storage area is insufficient, dynamic adjustment may be performed. For example, under the precondition that a maximum redundant quota is not used up, extra reserved space may be applied for, and then the data in the write request is written to the reserved space that is newly applied for.
Optionally, in a case in which multiple write requests are concurrently sent, when write requests received by the SSD include both a sequential write request and a random write request, data carried in the sequential write request may be preferentially written to the first storage area, to improve write performance.
An embodiment of the present disclosure provides another implementation solution of step 2 of determining a feature of the write request: collecting, by the SSD, statistics about a sequential write request count and a random write request count in an LBA carried in the write request. In this embodiment of the present disclosure, the sequential write request count in the LBA carried in the write request is also referred to as a sequential write request count of the write request, and the random write request count in the LBA carried in the write request is also referred to as a random write request count of the write request.
For example, when the SSD determines that a write request carrying an LBA m is a sequential write request, a sequential write request count Cs of the LBA m is increased by 1, or when the SSD determines that a write request carrying an LBA m is a random write request, a random write request count Cr of the LBA m is increased by 1. A value S (a sequence level) of a current sequential write request count Cs of the LBA m divided by (a sum of the current sequential write request count Cs of the LBA m and a current random write request count Cr of the LBA m) is calculated. If S meets the first condition (a first sequence level range) shown in
The sequence level of the write request corresponding to the data stored in Vd1 is greater than the sequence level of the write request corresponding to the data stored in Vd2, and reserved space allocated by the SSD to Vd1 is smaller than reserved space of Vd2, or a ratio of the reserved space of Vd1 to data space of Vd1 is less than a ratio of the reserved space of Vd2 to data space of Vd2. In this implementation manner, a quantity of times of garbage space recycling in Vd2 is reduced, thereby reducing a quantity of times of erasing a physical block in Vd2, and increasing a service life of the SSD. Further, write requests are respectively written to different areas according to different sequence levels; therefore, a write request having a higher sequence level is not affected, and random write performance of the SSD is improved.
Optionally, in a case in which multiple write requests are concurrently sent, when write requests received by an SSD have different sequence levels, a write request having a higher sequence level may be preferentially processed, or when write requests received by an SSD have different randomness levels, a write request having a lower randomness level may be preferentially processed, to improve write performance.
Another implementation manner may also be based on a randomness level R. When the SSD determines that a write request carrying an LBA m is a sequential write request, a sequential write request count Cs of the LBA m is increased by 1, or when the SSD determines that a write request carrying an LBA m is a random write request, a random write request count Cr of the LBA m is increased by 1. A value R (a randomness level) of a current random write request count Cr of the LBA m divided by (a sum of a current sequential write request count Cs of the LBA m and the current random write request count Cr of the LBA m) is calculated. If R meets the first condition (a first randomness level range) shown in
The randomness level of the write request corresponding to the data stored in Vd1 is less than the randomness level of the write request corresponding to the data stored in Vd2, and reserved space allocated by the SSD to Vd1 is smaller than reserved space of Vd2, or a ratio of the reserved space of Vd1 to data space of Vd1 is less than a ratio of the reserved space of Vd2 to data space of Vd2. In this implementation manner, a quantity of times of garbage space recycling in Vd2 is reduced, thereby reducing a quantity of times of erasing a physical block in Vd2, and increasing a service life of the SSD. Further, write requests are respectively written to different areas according to different randomness levels; therefore, a write request having a lower randomness level is not affected, and random write performance of the SSD is improved.
Optionally, a corresponding quantity of storage areas may be divided according to a class number of a sequence level or a randomness level of a write request, and corresponding reserved space is configured according to a value of each class of the sequence level or the randomness level. Division of the storage areas and configuration of the corresponding reserved space may be performed in advance, or dynamic division and configuration may be performed during use.
An embodiment of the present disclosure provides another implementation solution of step 2 of determining a feature of the write request: determining a size of data carried in the write request, and determining a storage area according to the size of the data carried in the write request.
As shown in
Optionally, in a case in which multiple write requests are concurrently sent, when receiving write requests carrying different sizes of data, an SSD may preferentially process a write request carrying a relatively big size of data, to improve write performance.
In this embodiment of the present disclosure, reserved space allocated by the SSD to Vd1 is smaller than reserved space of Vd2, or a ratio of the reserved space of Vd1 to data space of Vd1 is less than a ratio of the reserved space of Vd2 to data space of Vd2. In a specific implementation, weights of different reserved space quotas may be determined according to corresponding features of write requests in Vd1 and Vd2. The reserved space allocated to Vd1 is smaller than the reserved space of Vd2, or the ratio of the reserved space of Vd1 to the data space of Vd1 is less than the ratio of the reserved space of Vd2 to the data space of Vd2, which is not limited in this embodiment of the present disclosure.
In this embodiment of the present disclosure, after data carried in a write request is written to a page, a mapping relationship between an LBA and the page is established, and according to the specific implementation of the SSD, a mapping from the LBA to a physical block in which the page to which the data is written is located may be first established. For a specific implementation, refer to a mapping mechanism of the SSD, which is not limited in the present disclosure, and details are not described herein again.
The present disclosure may further be applied to a shingled magnetic recording (SMR) disk. Because of a special structure of the SMR disk, when data is written to a track A, data on L tracks after the track A is overwritten, and data on a track before the track A is not overwritten. Therefore, M (M>=L) tracks are generally used to form a zone in the SMR disk, data in physical space in the zone is sequentially written, and valid data in the zone is first moved before the writing. The SMR disk generally uses a ROW mechanism, divides physical storage space into a data zone (a zone in which data is already stored) and a reserved zone (a free zone), and records a mapping from a logical address to the physical storage space. When data is being written, the data is sequentially written to space of the reserved zone, the logical address is then mapped to a physical address to which the data is newly written, and data stored in a physical address to which the logical address is previously mapped is marked as garbage data. After a quantity of reserved zones is less than a threshold, garbage space recycling is started, a zone having the most garbage data is found, valid data in the zone is moved, and the zone becomes a reserved zone to which data may continue to be written. The zone in the SMR disk has a characteristic similar to that of a physical block in an SSD. Therefore, a solution in which movements of valid data are reduced during garbage space recycling in the SSD in the embodiments of the present disclosure may also be applied to the SMR disk. The SMR disk is divided into different storage areas, where each storage area includes multiple zones (including a data zone and a reserved zone), reserved zones having different sizes are allocated to the different storage areas, and a feature of a write request is determined. For example, whether the write request is a random write request or a sequential write request is determined, or a sequence level of the write request is determined, or a randomness level of the write request is determined, or a size of data carried in the write request is determined. The data carried in the write request is stored in a reserved zone of a specific storage area, so that movements of valid data in an SMR disk during garbage space recycling are reduced, and write amplification is reduced. For a specific implementation, reference may be made to an implementation solution of the SSD, and details are not described herein again in this embodiment of the present disclosure. For a manner in which reserved zones may be allocated to different storage areas in an SMR disk, refer to a manner described above in which reserved space is allocated to different storage areas in an SSD.
In addition, in a storage array having a garbage space recycling function and based on a ROW mechanism, for example, in an all-SSD storage array and a hard disk drive (HDD) storage array, a storage array controller divides a logical block address of each hard disk into blocks according to a unit (for example, 1 MB). One block is taken from each disk of N disks to form a segment (segment) meeting a condition (for example, a segment of a redundant array of independent disks (RAID), for example, to form a RAID 6 (including 3 data blocks+2 check blocks). A sequential write manner is used in the segment to improve write performance. Data in the segment cannot be overwritten, and valid data in the segment needs to be first moved before writing. The storage array controller divides storage space into a data segment (a segment to which data is already written) and a reserved segment (a free segment), and records a mapping from a logical address to physical storage space. When data is being written, the storage array controller sequentially writes the data to a reserved segment, then maps a logical address to a physical address to which the data is newly written, and marks data stored in a physical address to which the logical address is previously mapped as garbage data. After a quantity of reserved segments is less than a threshold, garbage space recycling is started, a segment having the most garbage data is found, a valid data in the segment is moved, and the segment becomes a reserved segment to which data may continue to be written.
In the foregoing storage array, the segment has a characteristic similar to that of a physical block in an SSD. Therefore, a solution in which movements of valid data are reduced during garbage data recycling in the SSD in the embodiments of the present disclosure may also be applied to the foregoing storage array. The storage array is divided into different storage areas, where each storage area includes multiple segments (including a data segment and a reserved segment), and a feature of a write request is determined. For example, whether the write request is a random write request or a sequential write request is determined, or a sequence level of the write request is determined, or a randomness level of the write request is determined, or a size of data carried in the write request is determined. The data carried in the write request is stored in a reserved segment of a specific storage area, so that movements of valid data in a storage array during garbage space recycling are reduced, and write amplification is reduced. For a specific implementation, reference may be made to an implementation solution of the SSD, and details are not described herein again in this embodiment of the present disclosure. For a manner in which reserved segments may be allocated to different storage areas in a storage array, refer to a manner described above in which reserved space is allocated to different storage areas in an SSD.
This embodiment of the present disclosure may further be applied to another product formed by using a flash memory medium and a storage medium having a similar characteristic.
Optionally, in an embodiment of the present disclosure, using an SSD as an example, the SSD may include more than two storage areas. Further, the SSD may determine a feature of a write request in multiple manners. For example, the SSD includes a first storage area and a second storage area, and determines whether a write request is a sequential write request or a random write request. When the write request is a sequential write request, the SSD writes data carried in the write request to the first storage area, or when the write request is a random write request, the SSD writes data carried in the write request to the second storage area. The SSD further includes a third storage area and a fourth storage area, determines a sequence level or a randomness level of a write request, and writes data carried in the write request to the third storage area or the fourth storage area according to the sequence level or the randomness level of the write request. Optionally, the SSD further includes a fifth storage area and a sixth storage area, determines a size of data carried in a write request, and writes data carried in the write request to the fifth storage area or the sixth storage area according to the size of the data carried in the write request. A combination of specific implementation manners is not limited in the present disclosure.
An embodiment of the present disclosure provides a storage device, as shown in
The storage device in this embodiment of the present disclosure may further be another product formed by using a flash memory medium and a storage medium having a similar characteristic.
An embodiment of the present disclosure provides another storage device, as shown in
The storage device shown in
According to the storage device shown in
An embodiment of the present disclosure further provides a non-volatile computer readable storage medium and a computer program product. When a computer instruction included in the non-volatile computer readable storage medium and the computer program product is loaded in the memory of the storage controller of the storage device shown in
According to the foregoing embodiments, an embodiment of the present disclosure provides a method for dividing a storage area by a storage device. The storage device divides storage space into a first storage area and a second storage area, where the first storage area includes data space and reserved space, and the second storage area includes data space and reserved space, where the reserved space of the first storage area is configured to store data carried in a first write request, the reserved space of the second storage area is configured to store data carried in a second write request, a feature of the first write request meets a first condition, and a feature of the second write request meets a second condition. Specifically, for the first condition, the second condition, the feature of the first write request, and the feature of the second write request, refer to the descriptions in the embodiment shown in
In the several embodiments provided in the present disclosure, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the unit division in the described apparatus embodiment is merely logical function division and may be other division in an actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be implemented by using some interfaces. The indirect couplings or communication connections between the apparatuses or units may be implemented in electronic, mechanical, or other forms.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.
This application is a continuation of International Application No. PCT/CN2015/095846, filed on Nov. 27, 2015, which is hereby incorporated by reference in its entirety.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2015/095846 | Nov 2015 | US |
Child | 15909670 | US |