Wear leveling method, solid-state drive and storage medium
Provided are a solid-state drive and a wear leveling method. The solid-state drive includes a plurality of zones, a mapping relationship and an SSD controller. The SSD controller is configured to: determine, according to the mapping relationship, an identifier of a first target zone corresponding to an identifier of a to-be-written zone in response to receiving a data write command from a host drive unit, and write the to-be-written data to the first target zone. The data write command carries the identifier of the to-be-written zone determined by the host drive unit and to-be-written data, the mapping relationship includes an identifier of an alternate zone corresponding to an identifier of each of the plurality of zones, and the alternate zone of each zone is a zone, determined from the plurality of zones, with fewest programmed/erased cycles.
1 . A wear leveling method for a solid-state drive, comprising:
determining, according to a mapping relationship, an identifier of a first target zone corresponding to an identifier of a to-be-written zone in response to receiving a data write command issued by a host drive unit, wherein the data write command carries the identifier of the to-be-written zone determined by the host drive unit and to-be-written data, the mapping relationship comprises one or more entries, wherein each entry includes an identifier of an alternate zone corresponding to an identifier of a target zone, and the alternate zone of each target zone is a zone of the solid-state drive with fewest programmed/erased cycles, wherein each target zone in the mapping relationship has non-fewest programmed/erased cycles; and
writing the to-be-written data to the first target zone.
2 . The method according to claim 1 , wherein before the determining, according to a mapping relationship, an identifier of a first target zone corresponding to an identifier of a to-be-written zone, the method further comprises:
receiving a zone opening command from the host drive unit, wherein the zone opening command carries the identifier of the to-be-written zone;
determining, according to the zone opening command, the zone with the fewest programmed/erased cycles from the plurality of zones of the solid-state drive as the first target zone; and
recording the identifier of the to-be-written zone and the identifier of the first target zone into the mapping relationship.
3 . The method according to claim 1 , further comprising:
acquiring a second target zone with fewest programmed/erased cycles in the solid-state drive, wherein the second target zone is a valid zone; and
in response to a determination that a difference between an average number of programmed/erased cycles of all the plurality of zones of the solid-state drive and a number of programmed/erased cycles of the second target zone is larger than a threshold, migrating data in the second target zone to a third target zone with the fewest programmed/erased cycles, and labeling the second target zone as idle, wherein the third target zone is an idle zone.
4 . The method according to claim 3 , further comprising:
updating the identifier of the second zone to an identifier of the third target zone in the mapping relationship.
5 . The method according to claim 1 , further comprising:
determining, according to the mapping relationship, an identifier of a fourth target zone corresponding to an identifier of a to-be-erased zone in response to receiving a data erase command issued by the host drive unit; and
erasing data in the fourth target zone, and labeling the fourth target zone as idle.
6 . The method according to claim 5 , further comprising:
deleting a correspondence relationship between the identifier of the to-be-erased zone and the identifier of the fourth target zone from the mapping relationship.
7 . The method according to claim 1 , further comprising:
determining an identifier of a fifth target zone corresponding to an identifier of a to-be-read zone from the mapping relationship in response to receiving a data read command issued by the host drive unit, wherein the data read command carries the identifier of the to-be-read zone; and
reading data from the fifth target zone, and sending the data to the host drive unit.
8 . A solid-state drive (SSD), comprising:
a plurality of zones;
a mapping relationship; and
an SSD controller,
wherein the SSD controller is configured to:
determine, according to the mapping relationship, an identifier of a first target zone corresponding to an identifier of a to-be-written zone in response to receiving a data write command issued by a host drive unit, wherein the data write command carries the identifier of the to-be-written zone determined by the host drive unit and to-be-written data, the mapping relationship comprises one or more entries, wherein each entry includes an identifier of an alternate zone corresponding to an identifier of a target zone, and the alternate zone of each target zone is a zone of the solid-state drive with fewest programmed/erased cycles, wherein each target zone in the mapping relationship has non-fewest programmed/erased cycles; and
write the to-be-written data to the first target zone.
9 . The SSD according to claim 8 , wherein before determining, according to a mapping relationship, an identifier of a first target zone corresponding to an identifier of a to-be-written zone, the SSD controller is further configured to:
receive a zone opening command from the host drive unit, wherein the zone opening command carries the identifier of the to-be-written zone;
determine, according to the zone opening command, the zone with the fewest programmed/erased cycles from the plurality of zones of the solid-state drive as the first target zone; and
record the identifier of the to-be-written zone and the identifier of the first target zone into the mapping relationship.
10 . The SSD according to claim 8 , wherein the SSD controller is further configured to:
acquire a second target zone with fewest programmed/erased cycles in the solid-state drive, wherein the second target zone is a valid zone; and
in response to a determination that a difference between an average number of programmed/erased cycles of all the plurality of zones of the solid-state drive and a number of programmed/erased cycles of the second target zone is larger than a threshold, migrate data in the second target zone to a third target zone with the fewest programmed/erased cycles, and label the second target zone as idle, wherein the third target zone is an idle zone.
11 . The SSD according to claim 10 , wherein the SSD controller is further configured to:
update the identifier of the second zone to an identifier of the third target zone in the mapping relationship.
12 . The SSD according to claim 8 , wherein the SSD controller is further configured to:
determine, according to the mapping relationship, an identifier of a fourth target zone corresponding to an identifier of a to-be-erased zone in response to receiving a data erase command issued by the host drive unit; and
erase data in the fourth target zone, and label the fourth target zone as idle.
13 . The SSD according to claim 12 , wherein the SSD controller is further configured to:
delete a correspondence relationship between the identifier of the to-be-erased zone and the identifier of the fourth target zone from the mapping relationship.
14 . The SSD according to claim 8 , wherein the SSD controller is further configured to:
determine an identifier of a fifth target zone corresponding to an identifier of a to-be-read zone from the mapping relationship in response to receiving a data read command issued by the host drive unit, wherein the data read command carries the identifier of the to-be-read zone; and
read data from the fifth target zone, and send the data to the host drive unit.
15 . A non-transitory computer readable storage medium, storing computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, are configured to implement a wear leveling method, and the wear leveling comprises:
determining, according to a mapping relationship, an identifier of a first target zone corresponding to an identifier of a to-be-written zone in response to receiving a data write command issued by a host drive unit, wherein the data write command carries the identifier of the to-be-written zone determined by the host drive unit and to-be-written data, the mapping relationship comprises one or more entries, wherein each entry includes an identifier of an alternate zone corresponding to an identifier of a target zone, and the alternate zone of each target zone is a zone of the solid-state drive with fewest programmed/erased cycles, wherein each target zone in the mapping relationship has non-fewest programmed/erased cycles; and
writing the to-be-written data to the first target zone.