1. Field of the Invention
The present invention presents a method of collecting a garbage block in a solid state disk, more particularly, a method of collecting a garbage block in a solid state disk wherein the process of collecting the garbage block is interrupted when writing data in the solid state disk.
2. Description of the Prior Art
A solid state disk (SSD) is a memory formed using a plurality of non-volatile flash memory. When a conventional solid state disk receives a command to access memory, a mapping table is used to convert the logical page address (LPA) of the accessed data to a corresponding physical page address (PPA) and transmits the accessed data to the flash memory. A flash memory has a data area and a spare area. Each area comprises a plurality of blocks. Each block comprises a plurality of physical pages. A physical page is taken as units when performing erase cycle. The flash memory reads the data in the physical address according to a data block of the data area. After the solid state disk transmits the update data to the host, the solid state disk selects a spare block in the spare area and writes the update data into the spare block to form a new data block in the data area and update the mapping table. Afterwards, the logical page address of the data in the original data block is registered to be discarded and used again during the collecting of a garbage block in solid state disk.
Step P1: the solid state disk of the prior art receiving a write command;
Step P2: determining if a program for collecting a garbage block is being executed; if yes, go to step P3, if no, go to step P6;
Step P3: selecting a block in the spare area to be a target block;
Step P4: copying effective data in the garbage block, moving the effective data to a physical page in the target block, and labeling the effective data as ineffective data;
Step P5: erasing all data in the garbage block; and
Step P6: executing the write data command.
Therefore, the solid state disk of the prior art is able to rearrange the effective data in the garbage block in the target block. In this way, the block in the data area may be emptied and may await its turn to be used as a spare block.
However, when the solid state disk of the prior art is executing the method of collecting a garbage block, one garbage block is used as a unit during recycling. After the effective data are copied to the target block, all of the data in the garbage block are erased to complete the recycling of a garbage block. When writing data, the solid state disk must wait for collecting a garbage block to be completed before writing of the data may begin. Thus, the efficiency of writing of data is affected. The more effective data there is in the garbage block, the longer time it would take for the process of collecting the garbage block to finish. Thus, the writing of the data in the solid state disk is delayed due to the collecting of the garbage block and effectively decreases the efficiency of accessing operation of the solid state disk. Therefore, there are problems that may occur during the collecting of a garbage block that needs to be addressed.
An objective of the present invention is to present a method of collecting a garbage block of a solid state disk. After a write command is received, a portion of effective pages in the garbage block is moved to a target block. The process of collecting the garbage block is terminated before writing data. Thus, the efficiency of writing data is increased.
Another objective of the present invention is to present a method of collecting a garbage block of a solid state disk. A predetermined threshold corresponding to the number of spare blocks is set. When the number of the spare blocks in the spare area is less than the predetermined threshold, a process of collecting the garbage block is completed before writing data to avoid affecting the operation the solid state disk.
To achieve the abovementioned objectives, a method of collecting a garbage block of a solid state disk may comprise writing data according to a write command if a process of collecting of a garbage block is not being performed when the write command is received. If the process of collecting of the garbage block is being performed when the write command is received, performing partial collecting of the garbage block by copying a portion of effective pages of the garbage block to a target block in a spare area, terminating the program for collecting the garbage block, and writing data according to the write command. In this way, the efficiency of writing data is increased.
The garbage block is divided in groups. Each of the groups has a portion of effective pages of the garbage block. The effective pages are grouped according to relation of data stored in the effective pages. After writing the data according to the write command, it is determined if the garbage block still has effective pages and writing of the data is ended. When the garbage block still has the effective pages, the program for collecting of the garbage block is reinitialized and collecting of the garbage block is completed.
Another method of collecting a garbage block of a solid state disk may comprise writing data according to a write command if a process of collecting of a garbage block is not being performed when the write command is received. If the process of collecting of the garbage block is being performed when the write command is received, determining if the number of spare blocks in a spare area is greater than a predetermined threshold, performing partial collecting of the garbage block by copying a portion of effective pages of the garbage block to a spare block in a spare area, terminating the program for collecting the garbage block, writing data according to the write command, and ending writing of the data. In this way, the efficiency of writing data is increased.
The predetermined threshold is the minimum number of spare blocks in the spare area for the solid state disk to effectively operate. When the number of the spare blocks in the spare area is less than a predetermined threshold, collecting of the garbage block is completed. The effective pages of the garbage block are copied to a spare block of the spare area. The effective pages are then registered as ineffective pages. And, the garbage block is recycled to be a spare block in the spare area.
These and other objectives of the present invention will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiment that is illustrated in the various figures and drawings.
To achieve the objective of the present invention, preferred embodiments of the present invention are described in the following paragraphs together with some illustrations.
When the solid state disk receives a write command from the host during the collecting of a garbage block, the garbage block collected may, for example, be the block 20A in
Step S1: the solid state disk of the prior art receiving a write command;
Step S2: determining if a program for collecting a garbage block is being executed; if yes, go to step S3, if no, go to step S5;
Step S3: performing partial collecting of garbage block by copying a portion of the effective pages of the garbage block to a target block in the spare area;
Step S4: terminating the collecting of the garbage block;
Step S5: executing the write command; and
Step S6: ending writing of the data.
Therefore, according to above mention process, when a write command is received during the collecting of the garbage block of the solid state disk, partial collecting of garbage block may be used to terminate the collecting of garbage block as quickly as possible without damaging the data in the garbage block. Thus, the speed of executing the write command is increased to improve the efficiency of the solid state disk.
Step R1: the solid state disk of the prior art receiving a write command;
Step R2: determining if a program for collecting a garbage block is being executed; if yes, go to step R3, if no, go to step R5;
Step R3: performing partial collecting of the garbage block by copying a portion of the effective pages of the garbage block to a target block in the spare area;
Step R4: terminating the collecting of the garbage block;
Step R5: executing the write command;
Step R6: determining if there are effective pages still in the garbage block; if yes, go to step R7; if no, go to step R8;
Step R7: if there are still effective pages in the garbage block, completing the collecting of garbage block; and
Step R8: ending writing of the data.
Therefore, according to above mention process, when a write command is received during the collecting of the garbage block of the solid state disk, the process of collecting the garbage block may be temporarily terminated to increase the speed of writing data. After the writing of data is finished, the process of collecting garbage block may be resumed to complete the collecting of the garbage block. In this way, the efficiency of writing data is increased. At the same time, the completion of the process of collecting garbage block may not be affected.
Step T1: the solid state disk of the prior art receiving a write command;
Step T2: determining if a program for collecting a garbage block is being executed; if yes, go to step T3, if no, go to step T7;
Step T3: determining if the number of spare blocks in the spare area is less than a predetermined threshold; if yes, go to step T4; if no, go to step T5;
Step T4: performing a complete collecting of the garbage block; proceed to step T7;
Step T5: performing partial collecting of garbage block by copying a portion of the effective pages of the garbage block to a target block in the spare area;
Step T6: terminating the collecting of the garbage block;
Step T7: executing the write command; and
Step T8: ending writing of the data.
Therefore, according to above mentioned process, in the method of collecting the garbage block in the third embodiment of the present invention, a predetermined threshold for the number of spare blocks available during the operation of the solid state disk may be set. When a write command is received during the collecting of the garbage block of the solid state disk, the collecting of the garbage block may be completed first if the number of spare blocks is less than the predetermined threshold. After the collecting of the garbage block is completed, the write command may then be executed. In this way, the operation of the solid state disk may not be affected.
Those skilled in the art will readily observe that numerous modifications and alterations of the device and method may be made while retaining the teachings of the invention. Accordingly, the above disclosure should be construed as limited only by the metes and bounds of the appended claims.
Number | Date | Country | Kind |
---|---|---|---|
201510379564.5 | Jul 2015 | CN | national |